summaryrefslogtreecommitdiffstats
path: root/tags/java/tsss-demo
diff options
context:
space:
mode:
Diffstat (limited to 'tags/java/tsss-demo')
-rw-r--r--tags/java/tsss-demo/console/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/console/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/console/pom.xml54
-rw-r--r--tags/java/tsss-demo/console/src/main/java/org/apache/tuscany/sca/console/handler/scdl/ScdlContributionForm.java49
-rw-r--r--tags/java/tsss-demo/console/src/main/java/org/apache/tuscany/sca/console/handler/scdl/ScdlContributionHandler.java64
-rw-r--r--tags/java/tsss-demo/console/src/main/java/org/apache/tuscany/sca/console/handler/scdl/TuscanyServlet.java77
-rw-r--r--tags/java/tsss-demo/console/src/main/resources/org/apache/tuscany/console/console.scdl45
-rw-r--r--tags/java/tsss-demo/core-samples/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/core-samples/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/core-samples/common/calculator/LICENSE.txt416
-rw-r--r--tags/java/tsss-demo/core-samples/common/calculator/NOTICE.txt32
-rw-r--r--tags/java/tsss-demo/core-samples/common/calculator/pom.xml61
-rw-r--r--tags/java/tsss-demo/core-samples/common/calculator/readme.html36
-rw-r--r--tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/AddService.java25
-rw-r--r--tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/AddServiceImpl.java30
-rw-r--r--tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/CalculatorService.java35
-rw-r--r--tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/CalculatorServiceImpl.java70
-rw-r--r--tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/DivideService.java25
-rw-r--r--tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/DivideServiceImpl.java30
-rw-r--r--tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/MultiplyService.java25
-rw-r--r--tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/MultiplyServiceImpl.java30
-rw-r--r--tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/SubtractService.java25
-rw-r--r--tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/SubtractServiceImpl.java30
-rw-r--r--tags/java/tsss-demo/core-samples/common/calculator/src/main/resources/META-INF/sca/autowire.default.scdl44
-rw-r--r--tags/java/tsss-demo/core-samples/common/calculator/src/main/resources/META-INF/sca/default.scdl47
-rw-r--r--tags/java/tsss-demo/core-samples/common/calculator/src/test/java/calculator/CalculatorTestComponent.java39
-rw-r--r--tags/java/tsss-demo/core-samples/common/calculator/src/test/resources/itest.scdl32
-rw-r--r--tags/java/tsss-demo/core-samples/common/pom.xml36
-rw-r--r--tags/java/tsss-demo/core-samples/common/readme.html40
-rw-r--r--tags/java/tsss-demo/core-samples/css/samples.css30
-rw-r--r--tags/java/tsss-demo/core-samples/faq.html30
-rw-r--r--tags/java/tsss-demo/core-samples/pom.xml83
-rw-r--r--tags/java/tsss-demo/core-samples/readme.html93
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/calculator/LICENSE.txt416
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/calculator/NOTICE.txt32
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/calculator/pom.xml52
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/calculator/readme.html69
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/calculator/src/main/java/calculator/CalculatorClient.java59
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/calculator/src/main/java/calculator/CalculatorService.java35
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/calculator/src/main/resources/META-INF/sca/autowire.default.scdl56
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/calculator/src/main/resources/META-INF/sca/default.scdl59
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/calculator/src/test/java/calculator/CalculatorClientTestCase.java46
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/loanapplication/LICENSE.txt416
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/loanapplication/NOTICE.txt32
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/loanapplication/pom.xml47
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/loanapplication/readme.html86
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/client/ClientService.java28
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/client/impl/ClientServiceImpl.java85
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/message/Application.java47
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/message/LoanPackage.java45
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/message/impl/ApplicationImpl.java75
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/message/impl/LoanPackageImpl.java75
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/CreditService.java34
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/LoanService.java55
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/LoanServiceCallback.java51
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/RateService.java28
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/impl/CreditServiceImpl.java32
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/impl/LoanServiceImpl.java101
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/impl/RateServiceImpl.java38
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/resources/META-INF/sca/default.scdl68
-rw-r--r--tags/java/tsss-demo/core-samples/standalone/pom.xml33
-rw-r--r--tags/java/tsss-demo/core-samples/webapp/pom.xml63
-rw-r--r--tags/java/tsss-demo/core-samples/webapp/webcalc/LICENSE.txt416
-rw-r--r--tags/java/tsss-demo/core-samples/webapp/webcalc/NOTICE.txt32
-rw-r--r--tags/java/tsss-demo/core-samples/webapp/webcalc/pom.xml54
-rw-r--r--tags/java/tsss-demo/core-samples/webapp/webcalc/readme.html118
-rw-r--r--tags/java/tsss-demo/core-samples/webapp/webcalc/src/main/webapp/WEB-INF/default.scdl33
-rw-r--r--tags/java/tsss-demo/core-samples/webapp/webcalc/src/main/webapp/WEB-INF/web.xml40
-rw-r--r--tags/java/tsss-demo/core-samples/webapp/webcalc/src/main/webapp/calc.jsp40
-rw-r--r--tags/java/tsss-demo/demo.app/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/demo.app/NOTICE.txt163
-rw-r--r--tags/java/tsss-demo/demo.app/pom.xml82
-rw-r--r--tags/java/tsss-demo/demo.app/src/main/java/org/apache/tuscany/demo/app/CalculatorForm.java92
-rw-r--r--tags/java/tsss-demo/demo.app/src/main/java/org/apache/tuscany/demo/app/CalculatorHandler.java130
-rw-r--r--tags/java/tsss-demo/demo/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/demo/NOTICE.txt163
-rw-r--r--tags/java/tsss-demo/demo/demo.xml139
-rw-r--r--tags/java/tsss-demo/demo/pom.xml110
-rw-r--r--tags/java/tsss-demo/demo/src/main/profiles/master/etc/runtime.properties1
-rw-r--r--tags/java/tsss-demo/demo/src/main/profiles/master/system.scdl368
-rw-r--r--tags/java/tsss-demo/demo/src/main/profiles/slave1/etc/runtime.properties1
-rw-r--r--tags/java/tsss-demo/demo/src/main/profiles/slave1/system.scdl337
-rw-r--r--tags/java/tsss-demo/demo/src/main/profiles/slave2/etc/runtime.properties1
-rw-r--r--tags/java/tsss-demo/demo/src/main/profiles/slave2/system.scdl340
-rw-r--r--tags/java/tsss-demo/http.jetty/.ruleset190
-rw-r--r--tags/java/tsss-demo/http.jetty/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/http.jetty/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/http.jetty/pom.xml76
-rw-r--r--tags/java/tsss-demo/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyLogger.java106
-rw-r--r--tags/java/tsss-demo/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyService.java38
-rw-r--r--tags/java/tsss-demo/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyServiceImpl.java326
-rw-r--r--tags/java/tsss-demo/http.jetty/src/main/java/org/apache/tuscany/service/jetty/TransportMonitor.java42
-rw-r--r--tags/java/tsss-demo/http.jetty/src/test/java/org/apache/tuscany/service/jetty/JettyServiceImplTestCase.java194
-rw-r--r--tags/java/tsss-demo/jms/.classpath26
-rw-r--r--tags/java/tsss-demo/jms/.project14
-rw-r--r--tags/java/tsss-demo/jms/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/jms/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/jms/pom.xml81
-rw-r--r--tags/java/tsss-demo/jms/src/main/java/org/apache/tuscany/service/discovery/jms/JmsDiscoveryService.java175
-rw-r--r--tags/java/tsss-demo/jms/src/main/java/org/apache/tuscany/service/discovery/jms/TuscanyJmsException.java37
-rw-r--r--tags/java/tsss-demo/jms/src/main/java/org/apache/tuscany/service/discovery/jms/TuscanyMessageListener.java86
-rw-r--r--tags/java/tsss-demo/kernel/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/kernel/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/kernel/README.txt44
-rw-r--r--tags/java/tsss-demo/kernel/api/.checkstyle24
-rw-r--r--tags/java/tsss-demo/kernel/api/.pmd20
-rw-r--r--tags/java/tsss-demo/kernel/api/.ruleset190
-rw-r--r--tags/java/tsss-demo/kernel/api/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/kernel/api/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/kernel/api/pom.xml42
-rw-r--r--tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyException.java124
-rw-r--r--tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyRuntimeException.java127
-rw-r--r--tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/DataContext.java42
-rw-r--r--tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/DataType.java60
-rw-r--r--tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/LogLevel.java40
-rw-r--r--tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/Monitor.java34
-rw-r--r--tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/Resource.java49
-rw-r--r--tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/package-info.java24
-rw-r--r--tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/package-info.java80
-rw-r--r--tags/java/tsss-demo/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyExceptionTestCase.java110
-rw-r--r--tags/java/tsss-demo/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyRuntimeExceptionTestCase.java105
-rw-r--r--tags/java/tsss-demo/kernel/core/.checkstyle24
-rw-r--r--tags/java/tsss-demo/kernel/core/.pmd20
-rw-r--r--tags/java/tsss-demo/kernel/core/.ruleset190
-rw-r--r--tags/java/tsss-demo/kernel/core/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/kernel/core/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/kernel/core/pom.xml98
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvoker.java78
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalBindingBuilder.java52
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalBindingDefinition.java39
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalBindingLoader.java70
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvoker.java69
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalReferenceBinding.java62
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalServiceBinding.java60
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalTargetInvoker.java79
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/bootstrap/Bootstrapper.java86
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/bootstrap/DefaultBootstrapper.java257
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/BuilderRegistryImpl.java185
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/ComponentNotFoundException.java36
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java384
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/IllegalCallbackException.java36
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/IncompatibleInterfacesException.java40
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/InvalidSourceTypeException.java35
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/InvalidTargetTypeException.java35
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/NoBindingException.java35
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/NoCompatibleBindingsException.java34
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/NoConversationalContractException.java37
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/NoRegisteredBuilderException.java38
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/SourceServiceNotFoundException.java36
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/TargetServiceNotFoundException.java36
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/WireCreationException.java39
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImpl.java50
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/WiringExceptionFormatter.java67
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/interceptor/InterceptorBuilderNotFoundException.java35
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/interceptor/InterceptorBuilderRegistryImpl.java55
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/DefaultPhysicalComponentBuilderRegistry.java75
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/WireAttacherNotFound.java34
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/WireAttacherRegistryImpl.java80
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/CallableReferenceImpl.java60
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/CallbackReferenceImpl.java33
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ComponentContextImpl.java92
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ComponentContextProvider.java44
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ComponentManagerImpl.java109
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ComponentObjectFactory.java51
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/InstanceFactory.java43
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/InstanceFactoryProvider.java60
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ReflectiveInstanceFactory.java85
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ReflectiveInstanceFactoryProvider.java127
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ScopeIdentifier.java35
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ServiceReferenceImpl.java52
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/SimpleWorkContext.java112
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/SystemSingletonAtomicComponent.java138
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/WorkContextImpl.java214
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/AbstractEvent.java39
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/AbstractRequestEvent.java38
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ComponentEvent.java34
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ComponentStart.java47
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ComponentStop.java46
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ConversationEnd.java31
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ConversationStart.java31
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ConversationalEvent.java39
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpRequestEnded.java38
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpRequestStart.java38
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpSessionEnd.java38
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpSessionEvent.java45
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpSessionStart.java38
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/RequestEnd.java38
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/RequestEvent.java28
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/RequestStart.java37
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/IFProviderBuilder.java40
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/IFProviderBuilderException.java48
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/IFProviderBuilderRegistry.java51
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/impl/AbstractIFProviderBuilder.java50
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/impl/DefaultIFProviderBuilderRegistry.java67
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/impl/ObjectFactoryUtil.java62
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/impl/ReflectiveIFProviderBuilder.java151
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/AbstractScopeContainer.java265
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/CompositeScopeContainer.java114
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainer.java190
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/HttpSessionScopeContainer.java141
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/InstanceWrapperBase.java53
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/ReflectiveInstanceWrapper.java52
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/RequestScopeContainer.java130
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/ScopeRegistryImpl.java49
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/StatelessScopeContainer.java62
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingInteceptor.java125
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingJavaInterfaceProcessor.java121
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingRegistryImpl.java90
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessor.java121
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataTypeLoader.java66
-rwxr-xr-xtags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DirectedGraph.java357
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/Input2InputTransformer.java216
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/MediatorImpl.java168
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/Output2OutputTransformer.java201
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/PassByValueInterceptor.java244
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessor.java182
-rwxr-xr-xtags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/PipedTransformer.java66
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/SimpleDataBinding.java61
-rwxr-xr-xtags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/TransformationContextImpl.java83
-rwxr-xr-xtags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/TransformerRegistryImpl.java73
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformer.java68
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/Java2XMLMapperException.java69
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformer.java70
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2XMLTransformer.java221
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/JavaBeansDataBinding.java37
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/XML2JavaBeanTransformer.java299
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/XML2JavaMapperException.java70
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/DOMDataBinding.java56
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/DOMWrapperHandler.java80
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/DOMXMLStreamReader.java1415
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/InputSource2Node.java65
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/InputSource2SAX.java63
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/InputStream2Node.java67
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/InputStream2SAX.java62
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Node2OutputStream.java66
-rwxr-xr-xtags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Node2String.java59
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Node2Writer.java65
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Node2XMLStreamReader.java60
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Reader2Node.java65
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Reader2SAX.java58
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/SAX2DOM.java244
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/SAX2DOMPipe.java67
-rwxr-xr-xtags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Source2ResultTransformer.java60
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/StAX2SAXAdapter.java256
-rwxr-xr-xtags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/StAXHelper.java806
-rwxr-xr-xtags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/StreamDataPipe.java57
-rwxr-xr-xtags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/String2Node.java60
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/String2SAX.java59
-rwxr-xr-xtags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/String2XMLStreamReader.java55
-rwxr-xr-xtags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Writer2ReaderDataPipe.java56
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/XMLStreamReader2Node.java62
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/XMLStreamReader2SAX.java73
-rwxr-xr-xtags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/XMLStreamReader2String.java55
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/XMLStringDataBinding.java33
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/deployer/AbstractDeploymentContext.java80
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/deployer/ChildDeploymentContext.java71
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/deployer/DeployerImpl.java186
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/deployer/RootDeploymentContext.java74
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/deployer/federation/FederatedDeployer.java181
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/generator/DefaultGeneratorContext.java42
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/generator/GeneratorNotFoundException.java31
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/generator/GeneratorRegistryImpl.java275
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/idl/java/IllegalCallbackException.java34
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/idl/java/InterfaceJavaLoader.java114
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/idl/java/JavaInterfaceProcessorRegistryImpl.java156
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/IntrospectionRegistryImpl.java133
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/POJOPhysicalComponentBuilder.java60
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PhysicalComponent.java50
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PojoAtomicComponent.java397
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PojoComponent.java218
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PojoComponentContextFactory.java41
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PojoConfiguration.java223
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PojoWorkContextTunnel.java63
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeBuilder.java69
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ComponentTimeoutException.java33
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeBuilder.java51
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImpl.java121
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeComponentTypeLoader.java65
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeLoader.java251
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/Dependency.java39
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ImplementationCompositeLoader.java125
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ManagedRequestContext.java58
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ReferenceImpl.java71
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ServiceImpl.java81
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/SystemCompositeBuilder.java61
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponent.java72
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaComponent.java42
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilder.java196
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaComponentTypeLoader.java86
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaImplementation.java62
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaImplementationLoader.java64
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaInvokerInterceptor.java141
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaPhysicalComponentBuilder.java184
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaPhysicalComponentGenerator.java134
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaTargetInvoker.java119
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/TargetMethodNotFoundException.java49
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/TypeNotFoundException.java38
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessor.java50
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/AmbiguousConstructorException.java41
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessor.java112
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ContextProcessor.java103
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ConversationProcessor.java141
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DestroyProcessor.java61
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateConstructorException.java38
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateDestructorException.java37
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateInitException.java37
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateReferenceException.java38
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateResourceException.java37
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessor.java58
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessor.java548
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalCallbackReferenceException.java37
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalContextException.java37
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalDestructorException.java37
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalInitException.java36
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalReferenceException.java37
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalResourceException.java37
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalServiceDefinitionException.java37
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceImpl.java384
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InitProcessor.java61
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidConstructorException.java39
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidConversationalImplementation.java45
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidPropertyException.java34
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidReferenceException.java41
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidResourceException.java33
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidServiceType.java34
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/MonitorProcessor.java56
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/NoConstructorException.java36
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/PropertyProcessor.java69
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessor.java164
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ResourceProcessor.java122
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ScopeProcessor.java63
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ServiceProcessor.java155
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ServiceTypeNotFoundException.java34
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/UnknownContextTypeException.java32
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/builder/SystemComponentBuilder.java161
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/builder/SystemPhysicalComponentBuilder.java114
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentImpl.java57
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/component/SystemComponent.java42
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/generator/SystemPhysicalComponentGenerator.java134
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/loader/SystemComponentTypeLoader.java99
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/loader/SystemCompositeComponentTypeLoader.java73
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/loader/SystemImplementationLoader.java75
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/model/SystemCompositeImplementation.java57
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/model/SystemImplementation.java51
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/model/SystemPhysicalComponentDefinition.java30
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/model/SystemPhysicalWireSourceDefinition.java30
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/model/SystemPhysicalWireTargetDefinition.java31
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ArrayMultiplicityObjectFactory.java54
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory.java48
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory2.java44
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ContextInjector.java32
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ConversationIDObjectFactory.java36
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/EventInvoker.java34
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/FieldInjector.java57
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/InjectionRuntimeException.java55
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/Injector.java35
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/InvalidAccessorException.java34
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/InvalidResourceTypeException.java33
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/JNDIObjectFactory.java50
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ListMultiplicityObjectFactory.java50
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/MethodEventInvoker.java55
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/MethodInjector.java55
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/NoAccessorException.java39
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/NoMultiplicityTypeException.java29
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ObjectCallbackException.java48
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/PojoObjectFactory.java120
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/RequestContextObjectFactory.java46
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ResourceNotFoundException.java34
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ResourceObjectFactory.java89
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/SingletonObjectFactory.java39
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/ComponentLoader.java361
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/ComponentTypeElementLoader.java86
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/DependencyLoader.java88
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/IncludeLoader.java105
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/JNDIPropertyFactory.java52
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/LoaderExceptionFormatter.java67
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/LoaderRegistryImpl.java179
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/PolicySetLoader.java195
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/PropertyLoader.java98
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/PropertyUtils.java119
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/ReferenceLoader.java107
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/ServiceLoader.java99
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/StringParserPropertyFactory.java191
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/WireLoader.java122
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/AbstractMarshallerExtension.java74
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/DefaultModelMarshallerRegistry.java97
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/PhysicalChangeSetMarshaller.java119
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/PhysicalOperationDefinitionMarshaller.java130
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/PhysicalWireDefinitionMarshaller.java119
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/AbstractExtensibleMarshallerExtension.java61
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/AbstractIFProviderDefinitionMarshaller.java86
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/AbstractPhysicalComponentDefinitionMarshaller.java123
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/AbstractPhysicalWireSourceDefinitionMarshaller.java106
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/AbstractPhysicalWireTargetDefinitionMarshaller.java81
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/instancefactory/ByteCodeIFProviderDefinitionMarshaller.java101
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/instancefactory/ReflectiveIFProviderDefinitionMarshaller.java234
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/java/JavaPhysicalComponentDefinitionMarshaller.java104
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/java/JavaPhysicalWireSourceDefinitionMarshaller.java96
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/java/JavaPhysicalWireTargetDefinitionMarshaller.java96
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/java/PojoPhysicalComponentDefinitionMarshaller.java107
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/NonBlockingIntentDefinition.java29
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/instancefactory/ByteCodeIFProviderDefinition.java49
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/instancefactory/InjectionSiteMapping.java63
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/instancefactory/InjectionSource.java96
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/instancefactory/MemberSite.java59
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/instancefactory/ReflectiveIFProviderDefinition.java172
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/java/JavaPhysicalComponentDefinition.java30
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/java/JavaPhysicalWireSourceDefinition.java31
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/java/JavaPhysicalWireTargetDefinition.java31
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/DefaultExceptionFormatter.java54
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/InvalidLevelException.java64
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/JavaLoggingMonitorFactory.java120
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/MonitorFactoryUtil.java78
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/NullMonitorFactory.java68
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/ProxyMonitorFactory.java234
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/policy/IntentRegistryImpl.java167
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyBuilderRegistryImpl.java59
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyEngineImpl.java297
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyHelper.java65
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/property/PropertyHelper.java194
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/property/PropertyObjectFactoryImpl.java109
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/property/SimplePropertyObjectFactory.java65
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/resolver/AutowireResolver.java64
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/resolver/AutowireTargetNotFoundException.java30
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/resolver/DefaultAutowireResolver.java181
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/runtime/AbstractRuntime.java374
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/artifact/LocalMavenRepository.java100
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/classloading/ClassLoaderRegistryImpl.java50
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/AssemblyServiceImpl.java308
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContentTypeDescriberImpl.java100
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionDirectoryWatcher.java70
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionLoader.java124
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionProcessorRegistryImpl.java95
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryImpl.java275
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionServiceImpl.java137
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/DocumentParseException.java31
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/InvalidContributionMetadataException.java52
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/InvalidDocumentException.java32
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/XMLChangeSetHandler.java116
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/CompositeContributionProcessor.java111
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessor.java139
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/InvalidComponentDefinitionlException.java36
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/InvalidFolderContributionURIException.java41
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/InvalidPojoComponentDefinitionlException.java36
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessor.java146
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessor.java109
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/resolver/ComponentDefinitionArtifactResolver.java69
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/extension/AbstractExtensionDeployer.java115
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistry.java142
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/store/memory/MemoryStore.java198
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/work/jca/JcaWorkScheduler.java206
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkScheduler.java217
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/work/jsr237/workmanager/DefaultWorkEvent.java73
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/work/jsr237/workmanager/DefaultWorkItem.java166
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/work/jsr237/workmanager/ThreadPoolWorkManager.java220
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/util/FileHelper.java704
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/util/IOHelper.java182
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/util/JavaIntrospectionHelper.java439
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptor.java60
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatter.java94
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/InvocationChainImpl.java105
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/InvokerInterceptor.java60
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/NoMethodForOperationException.java42
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptor.java193
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptorBuilder.java55
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptorGenerator.java51
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactory.java49
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/ProxyServiceExtension.java115
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireImpl.java159
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory.java85
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory2.java65
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java116
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java149
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler2.java133
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.java266
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler2.java187
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKProxyService.java107
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/composite.scdl48
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/databinding.scdl165
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/deployment.scdl62
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/formatters.scdl44
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/implementation.scdl79
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/interfaceJava.scdl36
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/javaImplementation.scdl40
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/loader.scdl53
-rw-r--r--tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/systemImplementation.scdl51
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvokerTestCase.java72
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingBuilderTestCase.java40
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java70
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerInvocationExceptionTestCase.java84
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerTestCase.java83
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerThrowableTestCase.java89
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java115
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java201
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryNoBindingsTestCase.java89
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java190
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplCreateWireTestCase.java110
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplTestCase.java320
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplWireTestCase.java89
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/IllegalCallbackExceptionTestCase.java40
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/IncompatibleInterfacesExceptionTestCase.java38
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/InvalidSourceTypeExceptionTestCase.java39
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/InvalidTargetTypeExceptionTestCase.java39
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.java156
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/ServiceConnectorTestCase.java152
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/TargetServiceNotFoundExceptionTestCase.java38
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImplTestCase.java48
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/WiringExceptionFormatterTestCase.java70
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/interceptor/InterceptorBuilderRegistryImplTestCase.java65
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/physical/WireAttacherRegistryTestCase.java76
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/ComponentContextImplTestCase.java91
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/ComponentManagerImplTestCase.java90
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/JavaObjectRegistrationTestCase.java77
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/ReflectiveInstanceFactoryProviderTestCase.java173
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/SystemSingletonAtomicComponentTestCase.java82
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/WorkContextImplTestCase.java65
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java69
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/instancefactory/impl/Bar.java28
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/instancefactory/impl/Foo.java42
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/instancefactory/impl/ReflectiveIFProviderBuilderTest.java89
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java61
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicCompositeScopeTestCase.java143
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicConversationalScopeTestCase.java95
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicHttpSessionScopeTestCase.java220
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicRequestScopeTestCase.java167
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicStatelessScopeTestCase.java89
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInitDestroyErrorTestCase.java93
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerDestroyOnExpirationTestCase.java72
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxAgeTestCase.java76
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxIdleTimeTestCase.java78
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerPersistenceTestCase.java189
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeRestartTestCase.java113
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperBaseTestCase.java64
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ReflectiveInstanceWrapperTestCase.java83
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeRestartTestCase.java100
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java166
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingInterceptorTestCase.java126
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingJavaInterfaceProcessorTestCase.java79
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingLoaderTestCase.java79
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingRegistryImplTestCase.java87
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingTestCase.java49
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorOptimizationTestCase.java89
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorTestCase.java94
-rwxr-xr-xtags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DirectedGraphTestCase.java89
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/IDLTransformerTestCase.java220
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/MediatorImplTestCase.java118
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueInterceptorTestCase.java69
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessorTestCase.java186
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/TransformerRegistryImplTestCase.java106
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformerTestCase.java178
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformerTestCase.java126
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/DOM2StAXTestCase.java76
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/DataPipeTestCase.java89
-rwxr-xr-xtags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/Node2StringTestCase.java35
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/PushTransformationTestCase.java81
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/StAXHelperTestCase.java47
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/TraxTransformerTestCase.java99
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/deployer/BootstrapDeployerTestCase.java181
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/idl/java/ConversationalIntrospectionTestCase.java80
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/idl/java/JavaInterfaceProcessorRegistryImplTestCase.java100
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/IntrospectionRegistryTestCase.java123
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PhysicalComponentTestCase.java80
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PojoAtomicComponentTestCase.java179
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PojoComponentTestCase.java138
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeBuilderTestCase.java199
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplTestCase.java79
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLoaderTestCase.java201
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLoaderWireResolutionTestCase.java230
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/DuplicateRegistrationTestCase.java120
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ImplementationCompositeLoaderTestCase.java194
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ManagedRequestContextTestCase.java42
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ReferenceImplTestCase.java55
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ServiceImplTestCase.java56
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentMetadataInjectionTestCase.java37
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentNegativeMetadataTestCase.java49
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaBuilderPropertyTestCase.java140
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderConversationIDTestCase.java85
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderMetadataTestCase.java133
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderResourceTestCase.java85
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentTypeLoaderTestCase.java75
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaInvokerInterceptorBasicTestCase.java247
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaReferenceWireTestCase.java157
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerBasicInvocationTestCase.java173
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerSequenceTestCase.java147
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerStatelessDestroyTestCase.java72
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/MultiplicityTestCase.java34
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/ResourceInjectionTestCase.java113
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/CallbackInvocationTestCase.java363
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/WireToScopedJavaTestCase.java220
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessorTestCase.java59
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorExtensibilityTestCase.java82
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java167
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java169
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java176
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java166
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java196
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConversationProcessorTestCase.java152
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConvertTimeMillisTestCase.java110
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/DestroyProcessorTestCase.java100
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessorTestCase.java60
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicAndPropertyTestCase.java70
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java297
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java396
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java129
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceTestCase.java113
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceUniqueTestCase.java67
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/InitProcessorTestCase.java98
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/MonitorProcessorTestCase.java180
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java208
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessorTestCase.java232
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ResourceProcessorTestCase.java117
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ScopeProcessorTestCase.java128
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceCallbackTestCase.java166
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceProcessorTestCase.java151
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/builder/SystemComponentBuilderResourceTestCase.java97
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/builder/SystemPhysicalComponentBuilderTestCase.java92
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentTestCase.java119
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentWireInvocationTestCase.java67
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemComponentTypeLoaderTestCase.java82
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemImplementationLoaderTestCase.java106
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory2TestCase.java46
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactoryTestCase.java52
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/FieldInjectorTestCase.java48
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/JNDIObjectFactoryTestCase.java61
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/MethodEventInvokerTestCase.java72
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/MethodInjectorTestCase.java79
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/PojoObjectFactoryTestCase.java76
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/RequestContextObjectFactoryTestCase.java37
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/ResourceObjectFactoryTestCase.java91
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java33
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/AbstractConversationTestCase.java52
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationIdleExpireTestCase.java150
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationMaxAgeExpireTestCase.java158
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationStartStopEndTestCase.java149
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/IntrospectionRegistryIntegrationTestCase.java131
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/java/PhysicalBuilderTestCase.java186
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/system/builder/PhysicalBuilderTestCase.java184
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/system/builder/SystemBuilderPropertyTestCase.java92
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/mock/MockFactory.java212
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/scope/ScopeReferenceTestCase.java796
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/ReferenceInjectionTestCase.java79
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderNoBindingTestCase.java104
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderNoReferenceTestCase.java114
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderPropertyTestCase.java81
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderRefTestCase.java159
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderTestCase.java249
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderValidationTestCase.java169
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentTypeElementLoaderTestCase.java88
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/DependencyLoaderTestCase.java124
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/IncludeLoaderTestCase.java176
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/JNDIPropertyFactoryTestCase.java81
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/LoaderExceptionFormatterTestCase.java47
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/PolicySetLoaderTestCase.java71
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/PropertyParsingTestCase.java77
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ReferenceLoaderTestCase.java137
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderPromoteTestCase.java86
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderTestCase.java161
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryImplTestCase.java131
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/StringParserPropertyFactoryTestCase.java128
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/WireLoaderTestCase.java181
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/marshaller/JavaPhysicalChangeSetMarshallerTest.java159
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/binding/MockServiceBinding.java69
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/AsyncTarget.java31
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BadContextPojo.java28
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BadNamePojo.java26
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterface.java30
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterfaceImpl.java66
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponent.java31
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponentImpl.java40
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeDestroyOnlyComponent.java36
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitDestroyComponent.java39
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitOnlyComponent.java42
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponent.java29
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponentImpl.java29
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeDestroyOnlyComponent.java37
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitDestroyComponent.java38
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitOnlyComponent.java38
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderException.java40
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojo.java29
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojoImpl.java36
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedEagerInitPojo.java60
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojo.java28
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojoImpl.java61
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTarget.java31
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTargetImpl.java39
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeComponent.java30
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeDestroyOnlyComponent.java38
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitDestroyComponent.java38
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitOnlyComponent.java39
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponent.java30
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponentImpl.java30
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitDestroyComponent.java36
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitOnlyComponent.java37
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTarget.java30
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTargetImpl.java41
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/Source.java37
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SourceImpl.java63
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponent.java30
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponentImpl.java27
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/Target.java32
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/TargetImpl.java38
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockStaticInvoker.java98
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockSyncInterceptor.java55
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockTargetInvoker.java33
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/monitor/DefaultExceptionFormatterTestCase.java59
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/monitor/JavaLoggingTestCase.java153
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/policy/IntentRegistryImplTestCase.java152
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/policy/PolicyEngineImplTestCase.java140
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/property/PropertyHelperTestCase.java107
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/property/SimplePropertyObjectFactoryTestCase.java107
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/resolver/DefaultAutowireResolverTestCase.java177
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/artifact/LocalMavenRepositoryTestCase.java82
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/AssemblyServiceImplTestCase.java125
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContentTypeDescriberImplTestCase.java49
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryTestCase.java76
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionServiceImplTestCase.java67
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessorTestCase.java50
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessorTestCase.java46
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessorTestCase.java86
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistryTestCase.java147
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/store/memory/MemoryStoreTestCase.java166
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTest.java81
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTestCase.java100
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/workmanager/ThreadPoolWorkManagerTestCase.java132
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/util/Bean1.java45
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/util/Bean2.java47
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/util/JavaIntrospectionHelperTestCase.java180
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/util/SuperBean.java48
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/BasicReferenceInvocationHandlerTestCase.java84
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptorTestCase.java60
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java390
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatterTestCase.java82
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationChainImplTestCase.java84
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationErrorTestCase.java92
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationTestCase.java92
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationHandlerTestCase.java142
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/NonBlockingInterceptorBuilderTestCase.java38
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/NonBlockingInterceptorTestCase.java75
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactoryTestCase.java44
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireImplTestCase.java50
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireObjectFactoryTestCase.java138
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireOptimizationTestCase.java113
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java69
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerSerializationTestCase.java81
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerTestCase.java65
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerProxyTestCase.java82
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerSerializationTestCase.java136
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.java158
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCase.java57
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/resources/deployables/sample-calculator.jarbin0 -> 26901 bytes
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/resources/marshall/javaChangeSet.xml72
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/databinding/impl/ipo.xsd136
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/databinding/impl/order.wsdl76
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/databinding/xml/foo.xml22
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/deployer/boot1-include.scdl32
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/deployer/boot1.scdl34
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/deployer/boot2.scdl160
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/loader/TestPolicy.scdl51
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/loader/test-include.scdl22
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/policy/PolicySet.scdl66
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/property/ipo.xml51
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/services/deployment/test.ext18
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/services/deployment/test.scdl22
-rw-r--r--tags/java/tsss-demo/kernel/core/src/test/resources/repository/sample-calculator.jarbin0 -> 26901 bytes
-rw-r--r--tags/java/tsss-demo/kernel/databinding/.checkstyle6
-rw-r--r--tags/java/tsss-demo/kernel/databinding/.pmd2
-rw-r--r--tags/java/tsss-demo/kernel/databinding/.ruleset190
-rw-r--r--tags/java/tsss-demo/kernel/databinding/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/kernel/databinding/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/kernel/databinding/pom.xml63
-rw-r--r--tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/loader/DataTypeLoader.java64
-rw-r--r--tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessor.java125
-rw-r--r--tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/processor/JavaInterfaceIntrospector.java152
-rw-r--r--tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Exception2ExceptionTransformer.java126
-rw-r--r--tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Input2InputTransformer.java199
-rw-r--r--tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Output2OutputTransformer.java186
-rw-r--r--tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataBindingInteceptor.java254
-rw-r--r--tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataBindingWirePostProcessor.java111
-rw-r--r--tags/java/tsss-demo/kernel/databinding/src/main/resources/org/apache/tuscany/core/databinding.scdl185
-rw-r--r--tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/loader/DataBindingLoaderTestCase.java80
-rw-r--r--tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java82
-rw-r--r--tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/transformers/IDLTransformerTestCase.java223
-rw-r--r--tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/wire/DataBindingInterceptorTestCase.java129
-rw-r--r--tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/wire/DataBindingWirePostProcessorOptimizationTestCase.java102
-rw-r--r--tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/wire/DataBindingWirePostProcessorTestCase.java223
-rw-r--r--tags/java/tsss-demo/kernel/host-api/.checkstyle24
-rw-r--r--tags/java/tsss-demo/kernel/host-api/.pmd20
-rw-r--r--tags/java/tsss-demo/kernel/host-api/.ruleset190
-rw-r--r--tags/java/tsss-demo/kernel/host-api/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/kernel/host-api/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/kernel/host-api/pom.xml49
-rw-r--r--tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/AbstractRuntimeInfo.java125
-rw-r--r--tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/MonitorFactory.java52
-rw-r--r--tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/RuntimeInfo.java68
-rw-r--r--tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/AssemblyService.java60
-rw-r--r--tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/ContentTypes.java35
-rw-r--r--tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/ContributionService.java96
-rw-r--r--tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/DeploymentException.java51
-rw-r--r--tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/UnsupportedContentTypeException.java49
-rw-r--r--tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/management/ManagementService.java35
-rw-r--r--tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/monitor/ExceptionFormatter.java34
-rw-r--r--tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/monitor/FormatterRegistry.java42
-rw-r--r--tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/package-info.java23
-rw-r--r--tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/rmi/RMIHost.java49
-rw-r--r--tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/rmi/RMIHostAdmin.java39
-rw-r--r--tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/rmi/RMIHostException.java45
-rw-r--r--tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/rmi/RMIHostRuntimeException.java45
-rw-r--r--tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/runtime/InitializationException.java37
-rw-r--r--tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/runtime/ShutdownException.java33
-rw-r--r--tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/runtime/TuscanyRuntime.java125
-rw-r--r--tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/servlet/ServletRequestInjector.java41
-rw-r--r--tags/java/tsss-demo/kernel/host-api/src/test/java/org/apache/tuscany/host/rmi/RMIHostExceptionTestCase.java54
-rw-r--r--tags/java/tsss-demo/kernel/host-api/src/test/java/org/apache/tuscany/host/rmi/RMIHostRuntimeExceptionTestCase.java54
-rw-r--r--tags/java/tsss-demo/kernel/overview.html29
-rw-r--r--tags/java/tsss-demo/kernel/pom.xml209
-rw-r--r--tags/java/tsss-demo/kernel/spi/.checkstyle24
-rw-r--r--tags/java/tsss-demo/kernel/spi/.pmd20
-rw-r--r--tags/java/tsss-demo/kernel/spi/.ruleset190
-rw-r--r--tags/java/tsss-demo/kernel/spi/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/kernel/spi/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/kernel/spi/pom.xml66
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/doc/Context Model.emx673
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/AbstractLifecycle.java77
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/CoreRuntimeException.java55
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/InvalidNameException.java45
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/Lifecycle.java69
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/ObjectCreationException.java56
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/ObjectFactory.java35
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/QualifiedName.java105
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/bootstrap/ComponentNames.java62
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BindingBuilder.java60
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/Builder.java67
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderConfigException.java48
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderException.java55
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderInstantiationException.java39
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderRegistry.java55
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/ComponentBuilder.java42
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/Connector.java50
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/InvalidServiceInterfaceException.java35
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/MissingWireTargetException.java37
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/ScopeNotFoundException.java29
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/WiringException.java82
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/interceptor/InterceptorBuilder.java33
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/interceptor/InterceptorBuilderRegistry.java58
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/PhysicalComponentBuilder.java42
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/PhysicalComponentBuilderRegistry.java51
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/WireAttachException.java34
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/WireAttacher.java70
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/WireAttacherRegistry.java73
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/AbstractSCAObject.java104
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/AtomicComponent.java104
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Component.java158
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ComponentException.java52
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ComponentManager.java84
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ComponentRuntimeException.java54
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/DuplicateNameException.java36
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/GroupInitializationException.java48
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/IllegalTargetException.java33
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/InstanceWrapper.java41
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/InvalidAutowireInterface.java31
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/InvalidConversationSequenceException.java31
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Invocable.java57
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/MalformedNameException.java32
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/PersistenceException.java41
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ReactivationException.java45
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Reference.java53
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ReferenceBinding.java66
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/RegistrationException.java45
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAExternalizable.java43
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObject.java40
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObjectInputStream.java57
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObjectStartException.java33
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObjectStopException.java33
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ScopeContainer.java119
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ScopeContainerMonitor.java36
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ScopeRegistry.java39
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Service.java53
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ServiceBinding.java52
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetDestructionException.java40
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetException.java50
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetInitializationException.java39
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetInvocationException.java43
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetInvokerCreationException.java51
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetNotFoundException.java36
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetResolutionException.java43
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/WorkContext.java141
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/DataBinding.java72
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/DataBindingRegistry.java67
-rwxr-xr-xtags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/DataPipe.java44
-rwxr-xr-xtags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/Mediator.java58
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/PullTransformer.java36
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/PushTransformer.java34
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/SimpleTypeMapper.java44
-rwxr-xr-xtags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/TransformationContext.java71
-rwxr-xr-xtags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/TransformationException.java46
-rwxr-xr-xtags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/Transformer.java49
-rwxr-xr-xtags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/TransformerRegistry.java73
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/WrapperHandler.java56
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/DOMHelper.java69
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/DataBindingExtension.java179
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/Java2SimpleTypeTransformer.java61
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/SimpleType2JavaTransformer.java72
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtension.java415
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/TransformerExtension.java73
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/XSDDataTypeConverter.java940
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ArtifactResolver.java84
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ArtifactResolverRegistry.java45
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ChangeSetHandler.java48
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ChangeSetHandlerRegistry.java28
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/CompositeClassLoader.java181
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContentType.java37
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContentTypeDescriber.java36
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessor.java66
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessorRegistry.java36
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionRepository.java77
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/Deployer.java50
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/DeploymentContext.java101
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/DeploymentMonitor.java38
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/AbstractEventPublisher.java83
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/Event.java33
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/EventFilter.java33
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/EventPublisher.java50
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/RuntimeEventListener.java31
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/TrueFilter.java31
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/AbstractComponentExtension.java138
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ArtifactResolverExtension.java75
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/AtomicComponentExtension.java115
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/BindingBuilderExtension.java67
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ComponentBuilderExtension.java78
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ComponentTypeLoaderExtension.java63
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeComponentExtension.java104
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ContributionProcessorExtension.java76
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ExecutionMonitor.java33
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/InterceptorBuilderExtension.java50
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/LoaderExtension.java79
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ReferenceBindingExtension.java60
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ServiceBindingExtension.java62
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/TargetInvokerExtension.java78
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/BindingGenerator.java36
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/ComponentGenerator.java80
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/GenerationException.java52
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/GeneratorContext.java37
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/GeneratorRegistry.java92
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/InterceptorGenerator.java42
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/ResourceGenerator.java42
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceHost.java46
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceHostRegistry.java72
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceResolutionException.java32
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ServletHost.java58
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/ElementInfo.java54
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/InvalidConversationalOperationException.java40
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/InvalidServiceContractException.java50
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/OverloadedOperationException.java41
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/ServiceFaultException.java84
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/TypeInfo.java66
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/XMLType.java124
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/InterfaceJavaIntrospector.java46
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaIDLUtils.java151
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaInterfaceProcessor.java34
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaInterfaceProcessorExtension.java46
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaInterfaceProcessorRegistry.java39
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaServiceContract.java39
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessor.java188
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ConstructorDefinition.java51
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/DuplicatePropertyException.java35
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/IllegalPropertyException.java36
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ImplementationProcessor.java120
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ImplementationProcessorExtension.java117
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ImplementationProcessorService.java92
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/IntrospectionRegistry.java38
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/Introspector.java43
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedComponentType.java61
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedProperty.java64
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedReference.java61
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedService.java87
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/PojoComponentType.java148
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ProcessingException.java65
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/Resource.java145
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/ComponentTypeLoader.java42
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/IllegalSCDLNameException.java28
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidConfigurationException.java36
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidReferenceException.java43
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidServiceException.java30
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidValueException.java40
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidWireException.java45
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/Loader.java80
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderException.java92
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderRegistry.java69
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderUtil.java78
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingImplementationException.java35
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingIncludeException.java32
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingPromoteException.java31
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingReferenceException.java32
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingRequiredPropertyException.java30
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingResourceException.java67
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/PropertyObjectFactory.java44
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/ReferenceMultiplicityViolationException.java75
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/StAXElementLoader.java46
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UndefinedPropertyException.java28
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UndefinedReferenceException.java30
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UnrecognizedComponentTypeException.java42
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UnrecognizedElementException.java46
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/MarshalException.java49
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/ModelMarshaller.java52
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/ModelMarshallerRegistry.java60
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/AtomicImplementation.java33
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/BindingDefinition.java45
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ComponentDefinition.java189
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ComponentType.java178
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/CompositeComponentType.java236
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/CompositeImplementation.java56
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Contribution.java113
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ContributionImport.java50
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/DataType.java249
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/DeployedArtifact.java112
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ElementInfo.java60
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Implementation.java43
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Include.java80
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Intent.java92
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentDefinition.java27
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentMap.java64
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentName.java140
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ModelObject.java38
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Multiplicity.java47
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Operation.java406
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachable.java39
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachableModel.java49
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyContentModel.java45
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyModel.java29
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicySet.java99
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicySetReference.java38
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Property.java105
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PropertyValue.java128
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Qualifier.java51
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ReferenceDefinition.java96
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ReferenceTarget.java69
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ResourceDefinition.java27
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Scope.java64
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ServiceContract.java283
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ServiceDefinition.java163
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/TypeInfo.java72
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/WSPolicyAttachment.java35
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/WireDefinition.java47
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/WrapperInfo.java139
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/XMLType.java124
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/InstanceFactoryProviderDefinition.java32
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/POJOComponentDefinition.java69
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalChangeSet.java73
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalComponentDefinition.java99
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalInterceptorDefinition.java59
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalOperationDefinition.java153
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireDefinition.java150
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireSourceDefinition.java101
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireTargetDefinition.java52
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/package-info.java23
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/IntentRegistry.java83
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/PolicyBuilderRegistry.java49
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/PolicyEngine.java42
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/PolicySetContainer.java46
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/SCATypeManager.java29
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/SourcePolicyBuilder.java42
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/SourcePolicyBuilderExtension.java52
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/TargetPolicyBuilder.java42
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/TargetPolicyBuilderExtension.java52
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/resolver/ResolutionException.java52
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/resolver/Resolver.java38
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/resolver/ResolverRegistry.java52
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/VoidService.java33
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/artifact/Artifact.java197
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/artifact/ArtifactRepository.java45
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/classloading/ClassLoaderRegistry.java53
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/classloading/DuplicateClassLoaderException.java36
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/AbstractDiscoveryService.java152
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/DiscoveryException.java49
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/DiscoveryService.java75
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/RequestListener.java39
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/ResponseListener.java39
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/management/TuscanyManagementService.java40
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/DuplicateRecordException.java31
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/RecoveryListener.java46
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/Store.java96
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreException.java54
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreExpirationEvent.java71
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreMonitor.java74
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreReadException.java41
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreWriteException.java43
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/NotificationListener.java66
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/NotificationListenerAdaptor.java71
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/WorkScheduler.java52
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/WorkSchedulerException.java41
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/util/UriHelper.java57
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/util/stax/StaxUtil.java204
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/AbstractInvocationHandler.java140
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ChainHolder.java56
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/IncompatibleServiceContractException.java74
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Interceptor.java50
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/InvocationChain.java99
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/InvocationRuntimeException.java46
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Message.java163
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/MessageId.java56
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/MessageImpl.java146
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ProxyCreationException.java51
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ProxyService.java122
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/TargetInvoker.java85
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Wire.java188
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WirePostProcessor.java31
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WirePostProcessorExtension.java43
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WirePostProcessorRegistry.java44
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/AssertionTestCase.java38
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/QualifiedNameTestCase.java65
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/TuscanyRuntimeExceptionTestCase.java49
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/AbstractSCAObjectTestCase.java106
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/MockSCAExternalizable.java48
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/MockSerializable.java42
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/SCAObjectInputStreamTestCase.java49
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DOMHelperTestCase.java55
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DataBindingExtensionTestCase.java80
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtensionTestCase.java127
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/TransformerExtensionTestCase.java74
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/XSDDataTypeConverterTestCase.java60
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/event/AbstractEventPublisherTestCase.java92
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/AbstractComponentExtensionTestCase.java110
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/AtomicComponentExtensionTestCase.java110
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/ComponentTypeLoaderExtensionTestCase.java58
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java82
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/InterceptorBuilderExtensionTestCase.java56
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/LoaderExtensionTestCase.java70
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionSequenceTestCase.java171
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionTestCase.java82
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/idl/java/JavaIDLUtilsTestCase.java105
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessorTestCase.java174
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/loader/LoaderExceptionTestCase.java33
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ComponentTypeTestCase.java54
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/CompositeComponentTypeTestCase.java43
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/IntentNameTestCase.java34
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/OperationTestCase.java52
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ScopeTestCase.java59
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ServiceContractTestCase.java76
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/policy/SourcePolicyBuilderExtensionTestCase.java51
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/policy/TargetPolicyBuilderExtensionTestCase.java50
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/util/URIHelperTestCase.java70
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/util/stax/StaxUtilTestCase.java58
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/AbstractInvocationHandlerTestCase.java132
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/ChainHolderTestCase.java35
-rw-r--r--tags/java/tsss-demo/kernel/spi/src/test/resources/test.scdl34
-rw-r--r--tags/java/tsss-demo/pom.xml59
-rw-r--r--tags/java/tsss-demo/runtime/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/runtime/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/runtime/README.txt28
-rw-r--r--tags/java/tsss-demo/runtime/itest/plugin/LICENSE.txt1407
-rw-r--r--tags/java/tsss-demo/runtime/itest/plugin/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/runtime/itest/plugin/pom.xml90
-rw-r--r--tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/Dependency.java81
-rw-r--r--tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedArtifactRepository.java159
-rw-r--r--tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java88
-rw-r--r--tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenMonitorFactory.java136
-rw-r--r--tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenRuntimeInfo.java56
-rw-r--r--tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSet.java81
-rw-r--r--tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSuite.java79
-rw-r--r--tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyITestMojo.java429
-rw-r--r--tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/ImplementationJUnit.java56
-rw-r--r--tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/ImplementationJUnitLoader.java54
-rw-r--r--tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitComponentBuilder.java194
-rw-r--r--tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitComponentTypeLoader.java146
-rw-r--r--tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitServiceContract.java35
-rw-r--r--tags/java/tsss-demo/runtime/itest/plugin/src/main/resources/META-INF/tuscany/embeddedMaven.scdl174
-rw-r--r--tags/java/tsss-demo/runtime/itest/plugin/src/site/apt/usage.apt158
-rw-r--r--tags/java/tsss-demo/runtime/itest/plugin/src/site/fml/faq.fml65
-rw-r--r--tags/java/tsss-demo/runtime/itest/plugin/src/site/site.xml33
-rw-r--r--tags/java/tsss-demo/runtime/itest/pom.xml53
-rw-r--r--tags/java/tsss-demo/runtime/itest/smoketest/LICENSE.txt1407
-rw-r--r--tags/java/tsss-demo/runtime/itest/smoketest/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/runtime/itest/smoketest/pom.xml58
-rw-r--r--tags/java/tsss-demo/runtime/itest/smoketest/src/main/java/org/apache/tuscany/sca/runtime/itest/smoketest/HelloService.java26
-rw-r--r--tags/java/tsss-demo/runtime/itest/smoketest/src/main/java/org/apache/tuscany/sca/runtime/itest/smoketest/HelloServiceImpl.java37
-rw-r--r--tags/java/tsss-demo/runtime/itest/smoketest/src/main/resources/META-INF/sca/default.scdl27
-rw-r--r--tags/java/tsss-demo/runtime/itest/smoketest/src/test/java/org/apache/tuscany/sca/runtime/itest/smoketest/BasicTestComponent.java35
-rw-r--r--tags/java/tsss-demo/runtime/itest/smoketest/src/test/resources/itest.scdl30
-rw-r--r--tags/java/tsss-demo/runtime/pom.xml166
-rw-r--r--tags/java/tsss-demo/runtime/services/contribution/.checkstyle24
-rw-r--r--tags/java/tsss-demo/runtime/services/contribution/.pmd20
-rw-r--r--tags/java/tsss-demo/runtime/services/contribution/.ruleset190
-rw-r--r--tags/java/tsss-demo/runtime/services/contribution/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/runtime/services/contribution/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/runtime/services/contribution/pom.xml42
-rw-r--r--tags/java/tsss-demo/runtime/services/management/jmx/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/runtime/services/management/jmx/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/runtime/services/management/jmx/pom.xml44
-rw-r--r--tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/JmxException.java48
-rw-r--r--tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/JmxManagementService.java75
-rw-r--r--tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/AbstractAgent.java154
-rw-r--r--tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/Agent.java56
-rw-r--r--tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/ManagementException.java37
-rw-r--r--tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/RmiAgent.java120
-rw-r--r--tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/AnnotationDrivenDynamicMBean.java82
-rw-r--r--tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/InstrumentationException.java48
-rw-r--r--tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/InstrumentedComponent.java138
-rw-r--r--tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/ReflectedDynamicMBean.java353
-rw-r--r--tags/java/tsss-demo/runtime/services/management/pom.xml35
-rw-r--r--tags/java/tsss-demo/runtime/services/maven/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/runtime/services/maven/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/runtime/services/maven/pom.xml52
-rw-r--r--tags/java/tsss-demo/runtime/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenArtifactRepository.java101
-rw-r--r--tags/java/tsss-demo/runtime/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenHelper.java296
-rw-r--r--tags/java/tsss-demo/runtime/services/maven/src/main/java/org/apache/tuscany/services/maven/TuscanyDependencyException.java58
-rw-r--r--tags/java/tsss-demo/runtime/services/maven/src/main/java/org/apache/tuscany/services/maven/WarRepositoryHelper.java116
-rw-r--r--tags/java/tsss-demo/runtime/services/maven/src/test/java/org/apache/tuscany/services/maven/MavenArtifactRepositoryTestCase.java96
-rw-r--r--tags/java/tsss-demo/runtime/services/maven/src/test/java/org/apache/tuscany/services/maven/WarRepositoryHelperTestCase.java78
-rw-r--r--tags/java/tsss-demo/runtime/services/maven/src/test/resources/webapp.warbin0 -> 443672 bytes
-rw-r--r--tags/java/tsss-demo/runtime/services/pom.xml39
-rw-r--r--tags/java/tsss-demo/runtime/standalone/assembly/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/runtime/standalone/assembly/NOTICE.txt163
-rw-r--r--tags/java/tsss-demo/runtime/standalone/assembly/pom.xml68
-rw-r--r--tags/java/tsss-demo/runtime/standalone/assembly/src/main/assembly/README.txt18
-rw-r--r--tags/java/tsss-demo/runtime/standalone/assembly/src/main/assembly/profiles/admin/system.scdl168
-rw-r--r--tags/java/tsss-demo/runtime/standalone/assembly/src/main/assembly/profiles/launcher/system.scdl189
-rw-r--r--tags/java/tsss-demo/runtime/standalone/assembly/standalone.xml87
-rw-r--r--tags/java/tsss-demo/runtime/standalone/launcher/.ruleset190
-rw-r--r--tags/java/tsss-demo/runtime/standalone/launcher/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/runtime/standalone/launcher/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/runtime/standalone/launcher/pom.xml67
-rw-r--r--tags/java/tsss-demo/runtime/standalone/launcher/src/main/java/org/apache/tuscany/launcher/Main.java98
-rw-r--r--tags/java/tsss-demo/runtime/standalone/launcher/src/main/resources/org/apache/tuscany/launcher/Main.properties23
-rw-r--r--tags/java/tsss-demo/runtime/standalone/pom.xml64
-rw-r--r--tags/java/tsss-demo/runtime/standalone/server.shutdown/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/runtime/standalone/server.shutdown/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/runtime/standalone/server.shutdown/pom.xml63
-rw-r--r--tags/java/tsss-demo/runtime/standalone/server.shutdown/src/main/java/org/apache/tuscany/standalone/server/ShutdownServer.java108
-rw-r--r--tags/java/tsss-demo/runtime/standalone/server.start/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/runtime/standalone/server.start/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/runtime/standalone/server.start/pom.xml79
-rw-r--r--tags/java/tsss-demo/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/TuscanyServer.java264
-rw-r--r--tags/java/tsss-demo/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/TuscanyServerException.java49
-rw-r--r--tags/java/tsss-demo/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/TuscanyServerMBean.java49
-rw-r--r--tags/java/tsss-demo/runtime/standalone/smoketest/pom.xml100
-rw-r--r--tags/java/tsss-demo/runtime/standalone/smoketest/src/main/java/org/apache/tuscany/sca/runtime/standalone/smoketest/HelloService.java26
-rw-r--r--tags/java/tsss-demo/runtime/standalone/smoketest/src/main/java/org/apache/tuscany/sca/runtime/standalone/smoketest/HelloServiceImpl.java37
-rw-r--r--tags/java/tsss-demo/runtime/standalone/smoketest/src/main/java/org/apache/tuscany/sca/runtime/standalone/smoketest/Launched.java50
-rw-r--r--tags/java/tsss-demo/runtime/standalone/smoketest/src/main/resources/META-INF/sca/default.scdl33
-rw-r--r--tags/java/tsss-demo/runtime/standalone/smoketest/src/test/java/org/apache/tuscany/sca/runtime/standalone/smoketest/CommandTestCase.java63
-rw-r--r--tags/java/tsss-demo/runtime/standalone/smoketest/src/test/java/org/apache/tuscany/sca/runtime/standalone/smoketest/ProcessDrainer.java131
-rw-r--r--tags/java/tsss-demo/runtime/standalone/smoketest/src/test/java/org/apache/tuscany/sca/runtime/standalone/smoketest/SmokeTestAssemblyContent.java33
-rw-r--r--tags/java/tsss-demo/runtime/standalone/smoketest/src/test/java/org/apache/tuscany/sca/runtime/standalone/smoketest/SmokeTestLauncher.java88
-rw-r--r--tags/java/tsss-demo/runtime/standalone/smoketest/src/test/resources/org/apache/tuscany/sca/runtime/standalone/smoketest/LauncherNoComponent.txt1
-rw-r--r--tags/java/tsss-demo/runtime/standalone/smoketest/src/test/resources/org/apache/tuscany/sca/runtime/standalone/smoketest/LauncherUsage.txt1
-rw-r--r--tags/java/tsss-demo/runtime/standalone/standalone-api/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/runtime/standalone/standalone-api/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/runtime/standalone/standalone-api/pom.xml39
-rw-r--r--tags/java/tsss-demo/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/DirectoryHelper.java303
-rw-r--r--tags/java/tsss-demo/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/StandaloneRuntime.java44
-rw-r--r--tags/java/tsss-demo/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/StandaloneRuntimeInfo.java62
-rw-r--r--tags/java/tsss-demo/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/StandaloneRuntimeInfoImpl.java78
-rw-r--r--tags/java/tsss-demo/runtime/standalone/standalone-host/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/runtime/standalone/standalone-host/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/runtime/standalone/standalone-host/pom.xml50
-rw-r--r--tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/DirectoryScanExtender.java64
-rw-r--r--tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/StandaloneRuntimeImpl.java143
-rw-r--r--tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/Launched.java51
-rw-r--r--tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedComponentBuilder.java195
-rw-r--r--tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedComponentTypeLoader.java113
-rw-r--r--tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedLoader.java55
-rw-r--r--tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedServiceContract.java37
-rw-r--r--tags/java/tsss-demo/runtime/webapp/plugin.war/LICENSE.txt1407
-rw-r--r--tags/java/tsss-demo/runtime/webapp/plugin.war/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/runtime/webapp/plugin.war/pom.xml80
-rw-r--r--tags/java/tsss-demo/runtime/webapp/plugin.war/src/main/java/org/apache/tuscany/plugin/war/Dependency.java90
-rw-r--r--tags/java/tsss-demo/runtime/webapp/plugin.war/src/main/java/org/apache/tuscany/plugin/war/TuscanyWarMojo.java508
-rw-r--r--tags/java/tsss-demo/runtime/webapp/plugin.war/src/site/apt/usage.apt46
-rw-r--r--tags/java/tsss-demo/runtime/webapp/plugin.war/src/site/site.xml37
-rw-r--r--tags/java/tsss-demo/runtime/webapp/pom.xml68
-rw-r--r--tags/java/tsss-demo/runtime/webapp/smoketest/LICENSE.txt1407
-rw-r--r--tags/java/tsss-demo/runtime/webapp/smoketest/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/runtime/webapp/smoketest/pom.xml118
-rw-r--r--tags/java/tsss-demo/runtime/webapp/smoketest/src/main/java/org/apache/tuscany/sca/runtime/webapp/smoketest/HelloService.java26
-rw-r--r--tags/java/tsss-demo/runtime/webapp/smoketest/src/main/java/org/apache/tuscany/sca/runtime/webapp/smoketest/HelloServiceImpl.java37
-rw-r--r--tags/java/tsss-demo/runtime/webapp/smoketest/src/main/java/org/apache/tuscany/sca/runtime/webapp/smoketest/TestServlet.java52
-rw-r--r--tags/java/tsss-demo/runtime/webapp/smoketest/src/main/webapp/WEB-INF/default.scdl35
-rw-r--r--tags/java/tsss-demo/runtime/webapp/smoketest/src/main/webapp/WEB-INF/web.xml46
-rw-r--r--tags/java/tsss-demo/runtime/webapp/smoketest/src/test/java/org/apache/tuscany/sca/runtime/webapp/smoketest/SmokeTestContext.java58
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-api/.ruleset190
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-api/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-api/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-api/pom.xml53
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/Constants.java116
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/InvalidResourcePath.java31
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherMonitor.java33
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java114
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyFilter.java63
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyInitException.java48
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyRequestListener.java76
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyServlet.java58
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanySessionListener.java53
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java93
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeInfo.java35
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeInfoImpl.java67
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappUtil.java56
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappUtilImpl.java124
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java113
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyFilterTestCase.java112
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyServletTestCase.java80
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanySessionListenerTestCase.java78
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/WebappUtilTestCase.java131
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-host/.ruleset190
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-host/LICENSE.txt202
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-host/NOTICE.txt14
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-host/pom.xml66
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionId.java58
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletHostImpl.java142
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherInitException.java48
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/UnSupportedRuntimeException.java44
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebResourceScanExtender.java83
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java209
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappBuilder.java65
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappComponent.java165
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappComponentType.java34
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappComponentTypeLoader.java46
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappImplementation.java27
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappLoader.java123
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/resources/META-INF/tuscany/webapp.scdl193
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/Foo.java25
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/FooImpl.java25
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionIdTestCase.java44
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/ServletHostTestCase.java86
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImplTestCase.java98
-rw-r--r--tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/resources/testapp.scdl26
1325 files changed, 126174 insertions, 0 deletions
diff --git a/tags/java/tsss-demo/console/LICENSE.txt b/tags/java/tsss-demo/console/LICENSE.txt
new file mode 100644
index 0000000000..0084319535
--- /dev/null
+++ b/tags/java/tsss-demo/console/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, serviceDefinition marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/console/NOTICE.txt b/tags/java/tsss-demo/console/NOTICE.txt
new file mode 100644
index 0000000000..d83ebbe236
--- /dev/null
+++ b/tags/java/tsss-demo/console/NOTICE.txt
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/console/pom.xml b/tags/java/tsss-demo/console/pom.xml
new file mode 100644
index 0000000000..9999541ce6
--- /dev/null
+++ b/tags/java/tsss-demo/console/pom.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany</groupId>
+ <artifactId>sca</artifactId>
+ <version>1.0-incubating</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>tuscany-sca-console</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ <!-- TODO Change this later to WAR, one we have war deployment on servlet host -->
+ <packaging>jar</packaging>
+ <name>Apache Tuscany SCA Console</name>
+ <description>An Apache Maven plugin for packaging SCA composite archives.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-spi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/tags/java/tsss-demo/console/src/main/java/org/apache/tuscany/sca/console/handler/scdl/ScdlContributionForm.java b/tags/java/tsss-demo/console/src/main/java/org/apache/tuscany/sca/console/handler/scdl/ScdlContributionForm.java
new file mode 100644
index 0000000000..5a96f7267c
--- /dev/null
+++ b/tags/java/tsss-demo/console/src/main/java/org/apache/tuscany/sca/console/handler/scdl/ScdlContributionForm.java
@@ -0,0 +1,49 @@
+package org.apache.tuscany.sca.console.handler.scdl;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tuscany.spi.host.ServletHost;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+
+@SuppressWarnings("serial")
+public class ScdlContributionForm extends TuscanyServlet {
+
+ /**
+ * Injects the servlet host and path mapping.
+ *
+ * @param servletHost Servlet host to use.
+ * @param path Path mapping for the servlet.
+ */
+ public ScdlContributionForm(@Reference(name = "servletHost") ServletHost servletHost,
+ @Property(name = "path") String path) {
+ super(servletHost, path);
+ }
+
+ /**
+ * Processes the request.
+ *
+ * @param req Servlet request.
+ * @param res Servlet response.
+ * @throws ServletException Servlet exception.
+ * @throws IOException IO Exception.
+ */
+ protected void process(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+
+ PrintWriter writer = res.getWriter();
+ writer.println("<form name='' method='post' action='scdlSubmit'>");
+ writer.println("<textarea name='scdl' cols='60' rows='40'></textarea>");
+ writer.println("<br/>");
+ writer.println("<input type='submit' value='Contribute SCDL'/>");
+ writer.println("</form>");
+ writer.flush();
+ writer.close();
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/console/src/main/java/org/apache/tuscany/sca/console/handler/scdl/ScdlContributionHandler.java b/tags/java/tsss-demo/console/src/main/java/org/apache/tuscany/sca/console/handler/scdl/ScdlContributionHandler.java
new file mode 100644
index 0000000000..609187d668
--- /dev/null
+++ b/tags/java/tsss-demo/console/src/main/java/org/apache/tuscany/sca/console/handler/scdl/ScdlContributionHandler.java
@@ -0,0 +1,64 @@
+package org.apache.tuscany.sca.console.handler.scdl;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tuscany.host.deployment.AssemblyService;
+import org.apache.tuscany.host.deployment.DeploymentException;
+import org.apache.tuscany.spi.host.ServletHost;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+
+@SuppressWarnings("serial")
+public class ScdlContributionHandler extends TuscanyServlet {
+
+ // SCDL query parameter
+ private static final String SCDL_PARAM = "scdl";
+
+ // Assembly service to use
+ private AssemblyService assemblyService;
+
+ /**
+ * Injects the servlet host and path mapping.
+ *
+ * @param servletHost Servlet host to use.
+ * @param path Path mapping for the servlet.
+ */
+ public ScdlContributionHandler(@Reference(name = "servletHost") ServletHost servletHost,
+ @Property(name = "path") String path,
+ @Reference(name = "assemblyService") AssemblyService assemblyService) {
+ super(servletHost, path);
+ this.assemblyService = assemblyService;
+ }
+
+ /**
+ * Processes the request.
+ *
+ * @param req Servlet request.
+ * @param res Servlet response.
+ * @throws ServletException Servlet exception.
+ * @throws IOException IO Exception.
+ */
+ protected void process(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+
+ try {
+ String scdl = req.getParameter(SCDL_PARAM);
+ InputStream in = new ByteArrayInputStream(scdl.getBytes());
+ assemblyService.include(in);
+ PrintWriter writer = res.getWriter();
+ writer.println("Processed SCDL ");
+ writer.flush();
+ writer.close();
+ } catch(DeploymentException ex) {
+ throw new ServletException(ex);
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/console/src/main/java/org/apache/tuscany/sca/console/handler/scdl/TuscanyServlet.java b/tags/java/tsss-demo/console/src/main/java/org/apache/tuscany/sca/console/handler/scdl/TuscanyServlet.java
new file mode 100644
index 0000000000..f614a2b33d
--- /dev/null
+++ b/tags/java/tsss-demo/console/src/main/java/org/apache/tuscany/sca/console/handler/scdl/TuscanyServlet.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.console.handler.scdl;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tuscany.spi.host.ServletHost;
+import org.osoa.sca.annotations.EagerInit;
+
+/**
+ * Super class for all the Tuscany servlets.
+ *
+ * @version $Revision$ $Date$
+ *
+ */
+@SuppressWarnings("serial")
+@EagerInit
+public abstract class TuscanyServlet extends HttpServlet {
+
+ /**
+ * Injects the servlet host and path mapping.
+ *
+ * @param servletHost Servlet host to use.
+ * @param path Path mapping for the servlet.
+ */
+ public TuscanyServlet(ServletHost servletHost, String path) {
+ servletHost.registerMapping(path, this);
+ }
+
+ /**
+ * Processes the request.
+ *
+ * @param req Servlet request.
+ * @param res Servlet response.
+ * @throws ServletException Servlet exception.
+ * @throws IOException IO Exception.
+ */
+ protected abstract void process(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException;
+
+ /**
+ * Handles get requests.
+ */
+ @Override
+ protected final void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+ process(req, res);
+ }
+
+ /**
+ * Handles post request.
+ */
+ @Override
+ protected final void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+ process(req, res);
+ }
+
+}
diff --git a/tags/java/tsss-demo/console/src/main/resources/org/apache/tuscany/console/console.scdl b/tags/java/tsss-demo/console/src/main/resources/org/apache/tuscany/console/console.scdl
new file mode 100644
index 0000000000..0d021f905c
--- /dev/null
+++ b/tags/java/tsss-demo/console/src/main/resources/org/apache/tuscany/console/console.scdl
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<!--
+ Servlets for the SCA console.
+
+ $Rev$ $Date$
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ name="org.apache.tuscany.sca.console"
+ autowire="true">
+
+ <!-- Servlet that serves the SCDL contribution form -->
+ <component name="console.scdlRequestForm">
+ <system:implementation.system class="org.apache.tuscany.sca.console.handler.scdl.ScdlContributionForm"/>
+ <property name="path">/scdlForm</property>
+ <reference name="servletHost" target="httpService"/>
+ </component>
+
+ <!-- Servlet that handles the scdl submission -->
+ <component name="console.scdlHandler">
+ <system:implementation.system class="org.apache.tuscany.sca.console.handler.scdl.ScdlContributionHandler"/>
+ <property name="path">/scdlSubmit</property>
+ <reference name="servletHost" target="httpService"/>
+ <reference name="assemblyService" target="assemblyService"/>
+ </component>
+
+</composite> \ No newline at end of file
diff --git a/tags/java/tsss-demo/core-samples/LICENSE.txt b/tags/java/tsss-demo/core-samples/LICENSE.txt
new file mode 100644
index 0000000000..0084319535
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, serviceDefinition marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/core-samples/NOTICE.txt b/tags/java/tsss-demo/core-samples/NOTICE.txt
new file mode 100644
index 0000000000..2d290a2ed5
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/NOTICE.txt
@@ -0,0 +1,14 @@
+Apache Tuscany Core Samples
+Copyright (c) 2005 - 2007 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/core-samples/common/calculator/LICENSE.txt b/tags/java/tsss-demo/core-samples/common/calculator/LICENSE.txt
new file mode 100644
index 0000000000..bdec70a4fa
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/common/calculator/LICENSE.txt
@@ -0,0 +1,416 @@
+
+ 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.
+
+===============================================================================================================
+
+
+License for the Service Data Objects JavaDoc and Interface Definition files.
+
+Permission to copy, make derivative works of, and distribute the Service Data Objects
+JavaDoc and Interface Definition Files files in any medium without fee or royalty as part
+of a compliant implementation of the Service Data Objects Specification is hereby granted.
+The Service Data Objects Specification may be found at any of the following locations:
+
+http://dev2dev.bea.com/technologies/commonj/index.jsp
+http://www.ibm.com/developerworks/library/specification/ws-sdo/
+http://oracle.com/technology/webservices/sca
+https://www.sdn.sap.com/
+http://www.xcalia/xdn/specs/sdo
+
+THE SERVICE DATA OBJECTS SPECIFICATION AND THE JAVADOC AND INTERFACE DEFINITION FILES
+ARE PROVIDED "AS IS," AND THE AUTHORS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS
+SPECIFICATION OR THE JAVADOC AND INTERFACE DEFINITION FILES AND THE IMPLEMENTATION OF THEIR CONTENTS,
+INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+NON-INFRINGEMENT OR TITLE. THE AUTHORS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL,
+INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR RELATING TO ANY USE OR DISTRIBUTION OF THE
+SERVICE DATA OBJECTS SPECIFICATION OR THE JAVADOC OR INTERFACE DEFINTION FILES.
+
+The name and trademarks of the Authors may NOT be used in any manner, including advertising or
+publicity pertaining to the Service Component Architecture Specification or its contents without specific,
+written prior permission. Title to copyright in the Service Data Objects Specification and the
+JavaDoc and Interface Definition Files will at all times remain with the Authors.
+
+No other rights are granted by implication, estoppel or otherwise.
+
+=================================================================================================================
+Eclipse Public License - v 1.0
+
+THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
+
+1. DEFINITIONS
+
+"Contribution" means:
+
+a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and
+b) in the case of each subsequent Contributor:
+
+i) changes to the Program, and
+
+ii) additions to the Program;
+
+where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program.
+
+"Contributor" means any person or entity that distributes the Program.
+
+"Licensed Patents " mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program.
+
+"Program" means the Contributions distributed in accordance with this Agreement.
+
+"Recipient" means anyone who receives the Program under this Agreement, including all Contributors.
+
+2. GRANT OF RIGHTS
+
+a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.
+
+b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder.
+
+c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.
+
+d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement.
+
+3. REQUIREMENTS
+
+A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:
+
+a) it complies with the terms and conditions of this Agreement; and
+
+b) its license agreement:
+
+i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;
+
+ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;
+
+iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and
+
+iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.
+
+When the Program is made available in source code form:
+
+a) it must be made available under this Agreement; and
+
+b) a copy of this Agreement must be included with each copy of the Program.
+
+Contributors may not remove or alter any copyright notices contained within the Program.
+
+Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution.
+
+4. COMMERCIAL DISTRIBUTION
+
+Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.
+
+For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.
+
+5. NO WARRANTY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED 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. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations.
+
+6. DISCLAIMER OF LIABILITY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+7. GENERAL
+
+If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
+
+If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed.
+
+All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive.
+
+Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved.
+
+This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.
+
+===================================================================================================
+
+Common Public License - v 1.0
+
+THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
+
+1. DEFINITIONS
+
+"Contribution" means:
+
+ a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and
+ b) in the case of each subsequent Contributor:
+
+ i) changes to the Program, and
+
+ ii) additions to the Program;
+
+ where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program.
+
+"Contributor" means any person or entity that distributes the Program.
+
+"Licensed Patents " mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program.
+
+"Program" means the Contributions distributed in accordance with this Agreement.
+
+"Recipient" means anyone who receives the Program under this Agreement, including all Contributors.
+
+2. GRANT OF RIGHTS
+
+ a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.
+
+ b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder.
+
+ c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.
+
+ d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement.
+
+3. REQUIREMENTS
+
+A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:
+
+ a) it complies with the terms and conditions of this Agreement; and
+
+ b) its license agreement:
+
+ i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;
+
+ ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;
+
+ iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and
+
+ iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.
+
+When the Program is made available in source code form:
+
+ a) it must be made available under this Agreement; and
+
+ b) a copy of this Agreement must be included with each copy of the Program.
+
+Contributors may not remove or alter any copyright notices contained within the Program.
+
+Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution.
+
+4. COMMERCIAL DISTRIBUTION
+
+Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.
+
+For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.
+
+5. NO WARRANTY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED 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. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement, including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations.
+
+6. DISCLAIMER OF LIABILITY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+7. GENERAL
+
+If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
+
+If Recipient institutes patent litigation against a Contributor with respect to a patent applicable to software (including a cross-claim or counterclaim in a lawsuit), then any patent licenses granted by that Contributor to such Recipient under this Agreement shall terminate as of the date such litigation is filed. In addition, if Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed.
+
+All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive.
+
+Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. IBM is the initial Agreement Steward. IBM may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved.
+
+This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.
+
+
+
+
+
+
diff --git a/tags/java/tsss-demo/core-samples/common/calculator/NOTICE.txt b/tags/java/tsss-demo/core-samples/common/calculator/NOTICE.txt
new file mode 100644
index 0000000000..4dbc3a8099
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/common/calculator/NOTICE.txt
@@ -0,0 +1,32 @@
+Apache Tuscany SCA for Java
+Copyright 2006 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+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.
+
+Unless otherwise indicated, all distribution made available by the Apache Software Foundation
+is provided to you under the terms and conditions of the Apache License Version 2.0 ("AL").
+A copy of the AL is provided with this distribution as the LICENSE.txt file present in the
+root directory, and is also available at http://www.apache.org/licenses/.
+
+The terms and conditions governing the distribution may refer to the AL or other license
+agreements, notices or terms and conditions. Some of these other license agreements may
+include (but are not limited to):
+
+ . Eclipse Public License Version 1.0 (available at http://www.eclipse.org/legal/epl-v10.html)
+ . Common Public License Version 1.0 (available at http://www.eclipse.org/legal/cpl-v10.html)
+
+This product also includes software developed by:
+- the Eclipse Modeling Framework project (http://www.eclipse.org/emf/)
+
+It is your obligation to read and accept all such terms and conditions prior to use of the
+distribution. If term or condition is provided, please contact the Apache Software Foundation
+to determine what terms and conditions govern that particular distribution.
diff --git a/tags/java/tsss-demo/core-samples/common/calculator/pom.xml b/tags/java/tsss-demo/core-samples/common/calculator/pom.xml
new file mode 100644
index 0000000000..77c327fee7
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/common/calculator/pom.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca.core-samples</groupId>
+ <artifactId>common</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.core-samples.common</groupId>
+ <artifactId>calculator</artifactId>
+ <packaging>jar</packaging>
+ <name>Apache Tuscany Calculator Common Composite</name>
+ <description>A sample Calculator made of several SCA components wired together.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osoa</groupId>
+ <artifactId>sca-api-r1.0</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <defaultGoal>install</defaultGoal>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.tuscany</groupId>
+ <artifactId>tuscany-itest-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tags/java/tsss-demo/core-samples/common/calculator/readme.html b/tags/java/tsss-demo/core-samples/common/calculator/readme.html
new file mode 100644
index 0000000000..b42e31f089
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/common/calculator/readme.html
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <title>Tuscany Simple Calculator Sample</title>
+ <link rel="stylesheet" href="../../css/samples.css" type="text/css">
+</head>
+
+<body>
+<h1>Common Calculator Composite</h1>
+
+<h2>Overview</h2>
+<p>
+ This sample illustrates the use of SCA to wire components together inside a composite.
+ All connections between the components are local and are defined using Java interfaces.
+</p>
+</body>
+</html>
diff --git a/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/AddService.java b/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/AddService.java
new file mode 100644
index 0000000000..4eeb30a9c2
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/AddService.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+public interface AddService {
+
+ double add(double n1, double n2);
+
+}
diff --git a/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/AddServiceImpl.java b/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/AddServiceImpl.java
new file mode 100644
index 0000000000..8b6fe066a6
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/AddServiceImpl.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+/**
+ * An implementation of the Add service
+ */
+public class AddServiceImpl implements AddService {
+
+ public double add(double n1, double n2) {
+ return n1 + n2;
+ }
+
+}
diff --git a/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/CalculatorService.java b/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/CalculatorService.java
new file mode 100644
index 0000000000..031fa8b912
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/CalculatorService.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;
+
+
+/**
+ * The Calculator service interface.
+ */
+public interface CalculatorService {
+
+ double add(double n1, double n2);
+
+ double subtract(double n1, double n2);
+
+ double multiply(double n1, double n2);
+
+ double divide(double n1, double n2);
+
+}
diff --git a/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/CalculatorServiceImpl.java b/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/CalculatorServiceImpl.java
new file mode 100644
index 0000000000..3d861f2018
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/CalculatorServiceImpl.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 calculator;
+
+import org.osoa.sca.annotations.Reference;
+
+
+/**
+ * An implementation of the Calculator service.
+ */
+public class CalculatorServiceImpl implements CalculatorService {
+
+ private AddService addService;
+ private SubtractService subtractService;
+ private MultiplyService multiplyService;
+ private DivideService divideService;
+
+ @Reference
+ public void setAddService(AddService addService) {
+ this.addService = addService;
+ }
+
+ @Reference
+ public void setSubtractService(SubtractService subtractService) {
+ this.subtractService = subtractService;
+ }
+
+ @Reference
+ public void setDivideService(DivideService divideService) {
+ this.divideService = divideService;
+ }
+
+ @Reference
+ public void setMultiplyService(MultiplyService multiplyService) {
+ this.multiplyService = multiplyService;
+ }
+
+ public double add(double n1, double n2) {
+ return addService.add(n1, n2);
+ }
+
+ public double subtract(double n1, double n2) {
+ return subtractService.subtract(n1, n2);
+ }
+
+ public double multiply(double n1, double n2) {
+ return multiplyService.multiply(n1, n2);
+ }
+
+ public double divide(double n1, double n2) {
+ return divideService.divide(n1, n2);
+ }
+
+}
diff --git a/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/DivideService.java b/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/DivideService.java
new file mode 100644
index 0000000000..131c5a8014
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/DivideService.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+public interface DivideService {
+
+ double divide(double n1, double n2);
+
+}
diff --git a/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/DivideServiceImpl.java b/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/DivideServiceImpl.java
new file mode 100644
index 0000000000..f7ac0b7287
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/DivideServiceImpl.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+/**
+ * An implementation of the Divide service.
+ */
+public class DivideServiceImpl implements DivideService {
+
+ public double divide(double n1, double n2) {
+ return n1 / n2;
+ }
+
+}
diff --git a/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/MultiplyService.java b/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/MultiplyService.java
new file mode 100644
index 0000000000..a917896aeb
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/MultiplyService.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+public interface MultiplyService {
+
+ double multiply(double n1, double n2);
+
+}
diff --git a/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/MultiplyServiceImpl.java b/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/MultiplyServiceImpl.java
new file mode 100644
index 0000000000..b7dca792b2
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/MultiplyServiceImpl.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+/**
+ * An implementation of the Multiply service.
+ */
+public class MultiplyServiceImpl implements MultiplyService {
+
+ public double multiply(double n1, double n2) {
+ return n1 * n2;
+ }
+
+}
diff --git a/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/SubtractService.java b/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/SubtractService.java
new file mode 100644
index 0000000000..e328f024ea
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/SubtractService.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+public interface SubtractService {
+
+ double subtract(double n1, double n2);
+
+}
diff --git a/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/SubtractServiceImpl.java b/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/SubtractServiceImpl.java
new file mode 100644
index 0000000000..77b128ab8d
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/common/calculator/src/main/java/calculator/SubtractServiceImpl.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+/**
+ * An implementation of the subtract service.
+ */
+public class SubtractServiceImpl implements SubtractService {
+
+ public double subtract(double n1, double n2) {
+ return n1 - n2;
+ }
+
+}
diff --git a/tags/java/tsss-demo/core-samples/common/calculator/src/main/resources/META-INF/sca/autowire.default.scdl b/tags/java/tsss-demo/core-samples/common/calculator/src/main/resources/META-INF/sca/autowire.default.scdl
new file mode 100644
index 0000000000..1c5f9b1ed0
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/common/calculator/src/main/resources/META-INF/sca/autowire.default.scdl
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ name="CalculatorComposite"
+ autowire="true">
+
+ <component name="CalculatorServiceComponent">
+ <implementation.java class="calculator.CalculatorServiceImpl"/>
+ </component>
+
+ <component name="AddServiceComponent">
+ <implementation.java class="calculator.AddServiceImpl"/>
+ </component>
+
+ <component name="SubtractServiceComponent">
+ <implementation.java class="calculator.SubtractServiceImpl"/>
+ </component>
+
+ <component name="MultiplyServiceComponent">
+ <implementation.java class="calculator.MultiplyServiceImpl"/>
+ </component>
+
+ <component name="DivideServiceComponent">
+ <implementation.java class="calculator.DivideServiceImpl"/>
+ </component>
+
+</composite>
diff --git a/tags/java/tsss-demo/core-samples/common/calculator/src/main/resources/META-INF/sca/default.scdl b/tags/java/tsss-demo/core-samples/common/calculator/src/main/resources/META-INF/sca/default.scdl
new file mode 100644
index 0000000000..d78713e869
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/common/calculator/src/main/resources/META-INF/sca/default.scdl
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ name="CalculatorComposite">
+
+ <component name="CalculatorServiceComponent">
+ <implementation.java class="calculator.CalculatorServiceImpl"/>
+ <reference name="addService" target="AddServiceComponent"/>
+ <reference name="subtractService" target="SubtractServiceComponent"/>
+ <reference name="multiplyService" target="MultiplyServiceComponent"/>
+ <reference name="divideService" target="DivideServiceComponent"/>
+ </component>
+
+ <component name="AddServiceComponent">
+ <implementation.java class="calculator.AddServiceImpl"/>
+ </component>
+
+ <component name="SubtractServiceComponent">
+ <implementation.java class="calculator.SubtractServiceImpl"/>
+ </component>
+
+ <component name="MultiplyServiceComponent">
+ <implementation.java class="calculator.MultiplyServiceImpl"/>
+ </component>
+
+ <component name="DivideServiceComponent">
+ <implementation.java class="calculator.DivideServiceImpl"/>
+ </component>
+
+</composite>
diff --git a/tags/java/tsss-demo/core-samples/common/calculator/src/test/java/calculator/CalculatorTestComponent.java b/tags/java/tsss-demo/core-samples/common/calculator/src/test/java/calculator/CalculatorTestComponent.java
new file mode 100644
index 0000000000..1f75ebcd4c
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/common/calculator/src/test/java/calculator/CalculatorTestComponent.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 calculator;
+
+import junit.framework.TestCase;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * This shows how to test the Calculator service component.
+ */
+public class CalculatorTestComponent extends TestCase {
+
+ @Reference
+ public CalculatorService calculatorService;
+
+ public void testCalculator() throws Exception {
+ // Calculate
+ assertEquals(calculatorService.add(3, 2), 5.0);
+ assertEquals(calculatorService.subtract(3, 2), 1.0);
+ assertEquals(calculatorService.multiply(3, 2), 6.0);
+ assertEquals(calculatorService.divide(3, 2), 1.5);
+ }
+}
diff --git a/tags/java/tsss-demo/core-samples/common/calculator/src/test/resources/itest.scdl b/tags/java/tsss-demo/core-samples/common/calculator/src/test/resources/itest.scdl
new file mode 100644
index 0000000000..b3fcfc531d
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/common/calculator/src/test/resources/itest.scdl
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/2.0-alpha"
+ name="CalculatorTestHarnessComposite">
+
+ <!-- To use autowire instead of manually specifying reference targets, comment out the default.scdl include and uncomment the autowre.default.scdl include -->
+ <include name="CalculatorComposite" scdlResource="META-INF/sca/default.scdl"/>
+ <!-- <include name="CalculatorComposite" scdlResource="META-INF/sca/autowire.default.scdl"/> -->
+
+ <component name="testComponent">
+ <tuscany:junit class="calculator.CalculatorTestComponent"/>
+ <reference name="calculatorService" target="CalculatorServiceComponent"/>
+ </component>
+</composite>
diff --git a/tags/java/tsss-demo/core-samples/common/pom.xml b/tags/java/tsss-demo/core-samples/common/pom.xml
new file mode 100644
index 0000000000..bc7b262b76
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/common/pom.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>core-samples</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.core-samples</groupId>
+ <artifactId>common</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache Tuscany Core Samples Common Composites</name>
+ <description>Common composites used by other Core Samples.</description>
+
+ <modules>
+ <module>calculator</module>
+ </modules>
+</project>
diff --git a/tags/java/tsss-demo/core-samples/common/readme.html b/tags/java/tsss-demo/core-samples/common/readme.html
new file mode 100644
index 0000000000..ace822fbd7
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/common/readme.html
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <title>Apache Tuscany Sample Common Composites</title>
+ <link rel="stylesheet" href="../css/samples.css" type="text/css">
+</head>
+<body>
+<p>
+ This module contains common composites that are shared by other sample applications.
+ The Maven build packages each one, runs its integration tests to confirm that it runs
+ in the local environment, and then installs the composite in the local repository.
+</p>
+<p>
+ The common composites are:
+</p>
+<table width="100%">
+ <tr><th align="left" width="10%">Module</th><th align="left">Description</th></tr>
+ <tr><td><a href="calculator/">calculator</a></td><td>A simple four-function calculator.</tr>
+</table>
+</body>
+</html>
diff --git a/tags/java/tsss-demo/core-samples/css/samples.css b/tags/java/tsss-demo/core-samples/css/samples.css
new file mode 100644
index 0000000000..410a505fce
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/css/samples.css
@@ -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.
+ */
+pre.command {
+ border-style: solid;
+ border-width: 1px;
+ font-family: monospace;
+ margin-left: 5%;
+ margin-right: 5%;
+ padding-top: 10px;
+ padding-left: 3%;
+ padding-right: 3%;
+ padding-bottom: 10px;
+ background-color: rgb(230,230,230);
+} \ No newline at end of file
diff --git a/tags/java/tsss-demo/core-samples/faq.html b/tags/java/tsss-demo/core-samples/faq.html
new file mode 100644
index 0000000000..37f3c6ac7a
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/faq.html
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <title>Sample FAQs for Apache Tuscany</title>
+ <link rel="stylesheet" href="css/samples.css" type="text/css">
+</head>
+<body>
+<h1>Apache Tuscany Sample FAQ</h1>
+Freqently Asked Questions about building and running sample applications.
+</body>
+</html> \ No newline at end of file
diff --git a/tags/java/tsss-demo/core-samples/pom.xml b/tags/java/tsss-demo/core-samples/pom.xml
new file mode 100644
index 0000000000..8e7bbb070b
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/pom.xml
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany</groupId>
+ <artifactId>sca</artifactId>
+ <version>1.0-incubating</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>core-samples</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ <packaging>pom</packaging>
+ <name>Apache Tuscany Core Samples</name>
+ <description>Sample projects that illustrate core concepts for SCA and Tuscany.</description>
+
+ <properties>
+ <!-- version the SCA API that we implement -->
+ <scaSpecVersion>1.0</scaSpecVersion>
+
+ <!-- version the Apache Tuscany kernel that the runtimes work with -->
+ <kernelVersion>2.0-alpha-incubating</kernelVersion>
+ </properties>
+
+ <!-- definition of repositories where the parent pom can be found -->
+ <repositories>
+ <repository>
+ <id>apache.incubator</id>
+ <name>Apache Incubator Repository</name>
+ <url>http://people.apache.org/repo/m2-incubating-repository/</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.osoa</groupId>
+ <artifactId>sca-api-r${scaSpecVersion}</artifactId>
+ <version>1.0-incubating</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>2.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <modules>
+ <module>common</module>
+ </modules>
+</project>
diff --git a/tags/java/tsss-demo/core-samples/readme.html b/tags/java/tsss-demo/core-samples/readme.html
new file mode 100644
index 0000000000..cea10e77b5
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/readme.html
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <title>Apache Tuscany Sample Applications</title>
+ <link rel="stylesheet" href="css/samples.css" type="text/css">
+</head>
+<body>
+<h1>Apache Tuscany Sample Applications</h1>
+<p>
+ Thank you for your interest in Apache Tuscany in using the Service Component Architecture (SCA)
+ for building applications. This package contains a number of samples that illustrate some of
+ the core concepts in SCA and shows how to build and run them using Apache Tuscany.
+</p>
+
+<h2>Pre-requisites</h2>
+
+<p>
+ The samples assume that you have certain tools in your local environment, specifically:
+</p>
+<ul>
+ <li>a Java5 development kit</li>
+ <li><a href="http://maven.apache.org/download.html">Apache Maven v2.0.4</a> or later</li>
+</ul>
+<p>To run the web application samples you will also require a J2EE 1.4 web container such as
+ <a href="http://tomcat.apache.org/download-55.cgi">Apache Tomcat 5.5</a>
+</p>
+
+<h2 id="GettingStarted">Getting Started</h2>
+
+<p>
+ Many of the samples use pre-built SCA composites that implement the services they are using.
+ These need to be built before any of the individual samples. To do this run:
+</p>
+<pre class="command">
+$ mvn install
+</pre>
+<p>
+ from this directory.
+</p>
+<p>
+ Please see the <a href="common/readme.html">common</a> module for information on these composites.
+</p>
+<h3>Standalone Samples</h3>
+<p>
+ These sample applications are intended to be run in a standalone environment in conjunction
+ with an installed version of Apache Tuscany. You can download a distribution from
+ <a href="http://people.apache.org/dist/incubator/tuscany/java/sca/">http://people.apache.org/dist/incubator/tuscany/java/sca/</a>
+</p>
+<p>
+ Please see the <a href="standalone/readme.html">standalone</a> module for specific details on running these samples.
+</p>
+<h3>Web Application Samples</h3>
+<p>
+ These sample applications are intended to be run in a standard web container such as Apache Tomcat
+ or Jetty. The projects for these use a Maven plugin to package a standard WAR file that can then be deployed
+ to the web container using its standard deployment tools. An Apache Tuscany distribution does not need
+ to be included on your local machine as the Tuscany runtime is automatically downloaded by the
+ Maven plugin.
+</p>
+<p>
+ Please see the <a href="webapp/readme.html">webapp</a> module for specific details on running these samples.
+</p>
+<h2>Frequently Asked Questions</h2>
+<p>Help! Something is not working right ...</p>
+<p>
+ Please see the <a href="faq.html">faq</a> page in this directory for more information.
+ Additional help may also be found on the <a href="http://cwiki.apache.org/TUSCANY/tuscany-sca-faq.html">project wiki</a>
+</p>
+<p>
+ You can also contact the project members directly on the mailing list
+ <a href="mailto:tuscany-user@ws.apache.org">tuscany-user@ws.apache.org</a>
+</p>
+</body>
+</html>
diff --git a/tags/java/tsss-demo/core-samples/standalone/calculator/LICENSE.txt b/tags/java/tsss-demo/core-samples/standalone/calculator/LICENSE.txt
new file mode 100644
index 0000000000..bdec70a4fa
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/calculator/LICENSE.txt
@@ -0,0 +1,416 @@
+
+ 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.
+
+===============================================================================================================
+
+
+License for the Service Data Objects JavaDoc and Interface Definition files.
+
+Permission to copy, make derivative works of, and distribute the Service Data Objects
+JavaDoc and Interface Definition Files files in any medium without fee or royalty as part
+of a compliant implementation of the Service Data Objects Specification is hereby granted.
+The Service Data Objects Specification may be found at any of the following locations:
+
+http://dev2dev.bea.com/technologies/commonj/index.jsp
+http://www.ibm.com/developerworks/library/specification/ws-sdo/
+http://oracle.com/technology/webservices/sca
+https://www.sdn.sap.com/
+http://www.xcalia/xdn/specs/sdo
+
+THE SERVICE DATA OBJECTS SPECIFICATION AND THE JAVADOC AND INTERFACE DEFINITION FILES
+ARE PROVIDED "AS IS," AND THE AUTHORS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS
+SPECIFICATION OR THE JAVADOC AND INTERFACE DEFINITION FILES AND THE IMPLEMENTATION OF THEIR CONTENTS,
+INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+NON-INFRINGEMENT OR TITLE. THE AUTHORS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL,
+INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR RELATING TO ANY USE OR DISTRIBUTION OF THE
+SERVICE DATA OBJECTS SPECIFICATION OR THE JAVADOC OR INTERFACE DEFINTION FILES.
+
+The name and trademarks of the Authors may NOT be used in any manner, including advertising or
+publicity pertaining to the Service Component Architecture Specification or its contents without specific,
+written prior permission. Title to copyright in the Service Data Objects Specification and the
+JavaDoc and Interface Definition Files will at all times remain with the Authors.
+
+No other rights are granted by implication, estoppel or otherwise.
+
+=================================================================================================================
+Eclipse Public License - v 1.0
+
+THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
+
+1. DEFINITIONS
+
+"Contribution" means:
+
+a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and
+b) in the case of each subsequent Contributor:
+
+i) changes to the Program, and
+
+ii) additions to the Program;
+
+where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program.
+
+"Contributor" means any person or entity that distributes the Program.
+
+"Licensed Patents " mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program.
+
+"Program" means the Contributions distributed in accordance with this Agreement.
+
+"Recipient" means anyone who receives the Program under this Agreement, including all Contributors.
+
+2. GRANT OF RIGHTS
+
+a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.
+
+b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder.
+
+c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.
+
+d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement.
+
+3. REQUIREMENTS
+
+A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:
+
+a) it complies with the terms and conditions of this Agreement; and
+
+b) its license agreement:
+
+i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;
+
+ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;
+
+iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and
+
+iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.
+
+When the Program is made available in source code form:
+
+a) it must be made available under this Agreement; and
+
+b) a copy of this Agreement must be included with each copy of the Program.
+
+Contributors may not remove or alter any copyright notices contained within the Program.
+
+Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution.
+
+4. COMMERCIAL DISTRIBUTION
+
+Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.
+
+For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.
+
+5. NO WARRANTY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED 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. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations.
+
+6. DISCLAIMER OF LIABILITY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+7. GENERAL
+
+If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
+
+If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed.
+
+All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive.
+
+Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved.
+
+This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.
+
+===================================================================================================
+
+Common Public License - v 1.0
+
+THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
+
+1. DEFINITIONS
+
+"Contribution" means:
+
+ a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and
+ b) in the case of each subsequent Contributor:
+
+ i) changes to the Program, and
+
+ ii) additions to the Program;
+
+ where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program.
+
+"Contributor" means any person or entity that distributes the Program.
+
+"Licensed Patents " mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program.
+
+"Program" means the Contributions distributed in accordance with this Agreement.
+
+"Recipient" means anyone who receives the Program under this Agreement, including all Contributors.
+
+2. GRANT OF RIGHTS
+
+ a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.
+
+ b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder.
+
+ c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.
+
+ d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement.
+
+3. REQUIREMENTS
+
+A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:
+
+ a) it complies with the terms and conditions of this Agreement; and
+
+ b) its license agreement:
+
+ i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;
+
+ ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;
+
+ iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and
+
+ iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.
+
+When the Program is made available in source code form:
+
+ a) it must be made available under this Agreement; and
+
+ b) a copy of this Agreement must be included with each copy of the Program.
+
+Contributors may not remove or alter any copyright notices contained within the Program.
+
+Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution.
+
+4. COMMERCIAL DISTRIBUTION
+
+Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.
+
+For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.
+
+5. NO WARRANTY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED 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. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement, including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations.
+
+6. DISCLAIMER OF LIABILITY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+7. GENERAL
+
+If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
+
+If Recipient institutes patent litigation against a Contributor with respect to a patent applicable to software (including a cross-claim or counterclaim in a lawsuit), then any patent licenses granted by that Contributor to such Recipient under this Agreement shall terminate as of the date such litigation is filed. In addition, if Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed.
+
+All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive.
+
+Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. IBM is the initial Agreement Steward. IBM may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved.
+
+This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.
+
+
+
+
+
+
diff --git a/tags/java/tsss-demo/core-samples/standalone/calculator/NOTICE.txt b/tags/java/tsss-demo/core-samples/standalone/calculator/NOTICE.txt
new file mode 100644
index 0000000000..4dbc3a8099
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/calculator/NOTICE.txt
@@ -0,0 +1,32 @@
+Apache Tuscany SCA for Java
+Copyright 2006 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+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.
+
+Unless otherwise indicated, all distribution made available by the Apache Software Foundation
+is provided to you under the terms and conditions of the Apache License Version 2.0 ("AL").
+A copy of the AL is provided with this distribution as the LICENSE.txt file present in the
+root directory, and is also available at http://www.apache.org/licenses/.
+
+The terms and conditions governing the distribution may refer to the AL or other license
+agreements, notices or terms and conditions. Some of these other license agreements may
+include (but are not limited to):
+
+ . Eclipse Public License Version 1.0 (available at http://www.eclipse.org/legal/epl-v10.html)
+ . Common Public License Version 1.0 (available at http://www.eclipse.org/legal/cpl-v10.html)
+
+This product also includes software developed by:
+- the Eclipse Modeling Framework project (http://www.eclipse.org/emf/)
+
+It is your obligation to read and accept all such terms and conditions prior to use of the
+distribution. If term or condition is provided, please contact the Apache Software Foundation
+to determine what terms and conditions govern that particular distribution.
diff --git a/tags/java/tsss-demo/core-samples/standalone/calculator/pom.xml b/tags/java/tsss-demo/core-samples/standalone/calculator/pom.xml
new file mode 100644
index 0000000000..c206388234
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/calculator/pom.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca.core-samples</groupId>
+ <artifactId>standalone</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.core-samples.standalone</groupId>
+ <artifactId>calc</artifactId>
+ <packaging>jar</packaging>
+ <name>Apache Tuscany Calculator Client Sample</name>
+ <description>A sample Calculator that runs from the command line.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.core-samples.common</groupId>
+ <artifactId>calculator</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${artifactId}</finalName>
+ </build>
+</project>
diff --git a/tags/java/tsss-demo/core-samples/standalone/calculator/readme.html b/tags/java/tsss-demo/core-samples/standalone/calculator/readme.html
new file mode 100644
index 0000000000..5fac063c10
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/calculator/readme.html
@@ -0,0 +1,69 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <title>Apache Tuscany Calculator Sample Application</title>
+ <link rel="stylesheet" href="../../css/samples.css" type="text/css">
+</head>
+<body>
+<h1>Apache Tuscany Calculator Sample Application</h1>
+
+<p>
+ This sample illustrates the use of SCA to wire components together inside a composite.
+ All connections between the components are local and are defined using Java interfaces.
+</p>
+
+<h2>Setup</h2>
+<p>
+ Please install Apache Maven and build the library composites as described in the
+ <a href="../../readme.html#GettingStarted">Getting Started</a> section of the root readme.
+</p>
+
+<h2>Building</h2>
+
+<p>To build the sample run:</p>
+ <pre class="command">
+$ mvn package
+</pre>
+<p>
+ This will build and package the code that calls the calculator composite from a
+ command line client environment.
+</p>
+
+<h2>Running</h2>
+<p>
+ To run the client, use the <code>launcher</code> command from the standalone distribution:
+</p>
+<pre class="command">
+$ java -jar {tuscany.installDir}/bin/launcher.jar target/calc.jar {add|subtract|multiply|divide} {param} {param}
+</pre>
+
+<p>where <code>tuscany.installDir</code> is the path where you installed the standalone distribution.</p>
+
+<p>
+ The sample when run will display to the standard output:
+</p>
+<pre class="command">
+$ java -jar {tuscany.installDir}/bin/launcher.jar target/calc.jar add 2 5
+result = 7.0
+</pre>
+</body>
+</html>
diff --git a/tags/java/tsss-demo/core-samples/standalone/calculator/src/main/java/calculator/CalculatorClient.java b/tags/java/tsss-demo/core-samples/standalone/calculator/src/main/java/calculator/CalculatorClient.java
new file mode 100644
index 0000000000..74c24b9a2c
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/calculator/src/main/java/calculator/CalculatorClient.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 calculator;
+
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * This client program shows how to create an SCA runtime, start it,
+ * locate the Calculator service and invoke it.
+ */
+public class CalculatorClient {
+
+ private CalculatorService calculatorService;
+
+ @Reference
+ public void setCalculatorService(CalculatorService calculatorService) {
+ this.calculatorService = calculatorService;
+ }
+
+ public int main(String[] args) throws Exception {
+
+ if(args.length != 3) {
+ System.err.println("usage: <add|substract|multiply|divide> <operand1> <operand2>");
+ return 1;
+ }
+
+ double result;
+ if("add".equals(args[0])) {
+ result = calculatorService.add(Double.parseDouble(args[1]), Double.parseDouble(args[2]));
+ } else if("subtract".equals(args[0])) {
+ result = calculatorService.subtract(Double.parseDouble(args[1]), Double.parseDouble(args[2]));
+ } else if("multiply".equals(args[0])) {
+ result = calculatorService.multiply(Double.parseDouble(args[1]), Double.parseDouble(args[2]));
+ } else if("divide".equals(args[0])) {
+ result = calculatorService.divide(Double.parseDouble(args[1]), Double.parseDouble(args[2]));
+ } else {
+ throw new IllegalArgumentException("Usage <add|substract|multiply|divide> <operand1> <operand2>");
+ }
+ System.out.println("result = " + result);
+ return 0;
+ }
+
+}
diff --git a/tags/java/tsss-demo/core-samples/standalone/calculator/src/main/java/calculator/CalculatorService.java b/tags/java/tsss-demo/core-samples/standalone/calculator/src/main/java/calculator/CalculatorService.java
new file mode 100644
index 0000000000..031fa8b912
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/calculator/src/main/java/calculator/CalculatorService.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;
+
+
+/**
+ * The Calculator service interface.
+ */
+public interface CalculatorService {
+
+ double add(double n1, double n2);
+
+ double subtract(double n1, double n2);
+
+ double multiply(double n1, double n2);
+
+ double divide(double n1, double n2);
+
+}
diff --git a/tags/java/tsss-demo/core-samples/standalone/calculator/src/main/resources/META-INF/sca/autowire.default.scdl b/tags/java/tsss-demo/core-samples/standalone/calculator/src/main/resources/META-INF/sca/autowire.default.scdl
new file mode 100644
index 0000000000..16a4a377dd
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/calculator/src/main/resources/META-INF/sca/autowire.default.scdl
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/2.0-alpha"
+ name="CalculatorComposite"
+ autowire="true">
+
+ <dependency xmlns="http://tuscany.apache.org/xmlns/sca/2.0-alpha">
+ <group>org.apache.tuscany.sca.core-samples.common</group>
+ <name>calculator</name>
+ <version>2.0-alpha-incubating-SNAPSHOT</version>
+ </dependency>
+
+ <component name="CalculatorClient">
+ <tuscany:launched class="calculator.CalculatorClient"/>
+ <reference name="calculatorService" target="CalculatorServiceComponent"/>
+ </component>
+
+ <component name="CalculatorServiceComponent">
+ <implementation.java class="calculator.CalculatorServiceImpl"/>
+ </component>
+
+ <component name="AddServiceComponent">
+ <implementation.java class="calculator.AddServiceImpl"/>
+ </component>
+
+ <component name="SubtractServiceComponent">
+ <implementation.java class="calculator.SubtractServiceImpl"/>
+ </component>
+
+ <component name="MultiplyServiceComponent">
+ <implementation.java class="calculator.MultiplyServiceImpl"/>
+ </component>
+
+ <component name="DivideServiceComponent">
+ <implementation.java class="calculator.DivideServiceImpl"/>
+ </component>
+
+</composite>
diff --git a/tags/java/tsss-demo/core-samples/standalone/calculator/src/main/resources/META-INF/sca/default.scdl b/tags/java/tsss-demo/core-samples/standalone/calculator/src/main/resources/META-INF/sca/default.scdl
new file mode 100644
index 0000000000..1a4476bec8
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/calculator/src/main/resources/META-INF/sca/default.scdl
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/2.0-alpha"
+ name="CalculatorComposite">
+
+ <dependency xmlns="http://tuscany.apache.org/xmlns/sca/2.0-alpha">
+ <group>org.apache.tuscany.sca.core-samples.common</group>
+ <name>calculator</name>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </dependency>
+
+ <component name="CalculatorClient">
+ <tuscany:launched class="calculator.CalculatorClient"/>
+ <reference name="calculatorService" target="CalculatorServiceComponent"/>
+ </component>
+
+ <component name="CalculatorServiceComponent">
+ <implementation.java class="calculator.CalculatorServiceImpl"/>
+ <reference name="addService" target="AddServiceComponent"/>
+ <reference name="subtractService" target="SubtractServiceComponent"/>
+ <reference name="multiplyService" target="MultiplyServiceComponent"/>
+ <reference name="divideService" target="DivideServiceComponent"/>
+ </component>
+
+ <component name="AddServiceComponent">
+ <implementation.java class="calculator.AddServiceImpl"/>
+ </component>
+
+ <component name="SubtractServiceComponent">
+ <implementation.java class="calculator.SubtractServiceImpl"/>
+ </component>
+
+ <component name="MultiplyServiceComponent">
+ <implementation.java class="calculator.MultiplyServiceImpl"/>
+ </component>
+
+ <component name="DivideServiceComponent">
+ <implementation.java class="calculator.DivideServiceImpl"/>
+ </component>
+
+</composite>
diff --git a/tags/java/tsss-demo/core-samples/standalone/calculator/src/test/java/calculator/CalculatorClientTestCase.java b/tags/java/tsss-demo/core-samples/standalone/calculator/src/test/java/calculator/CalculatorClientTestCase.java
new file mode 100644
index 0000000000..d4580f954e
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/calculator/src/test/java/calculator/CalculatorClientTestCase.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CalculatorClientTestCase extends TestCase {
+ private CalculatorClient client;
+ private CalculatorService mockService;
+
+ public void testAdd() throws Exception {
+ double result = 5;
+ EasyMock.expect(mockService.add(2.0, 3.0)).andReturn(result);
+ EasyMock.replay(mockService);
+ // The main returns 0 (status) instead of the result
+ assertEquals(0, client.main(new String[] {"add", "2", "3"}));
+ EasyMock.verify(mockService);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ client = new CalculatorClient();
+ mockService = EasyMock.createMock(CalculatorService.class);
+ client.setCalculatorService(mockService);
+ }
+}
diff --git a/tags/java/tsss-demo/core-samples/standalone/loanapplication/LICENSE.txt b/tags/java/tsss-demo/core-samples/standalone/loanapplication/LICENSE.txt
new file mode 100644
index 0000000000..bdec70a4fa
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/loanapplication/LICENSE.txt
@@ -0,0 +1,416 @@
+
+ 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.
+
+===============================================================================================================
+
+
+License for the Service Data Objects JavaDoc and Interface Definition files.
+
+Permission to copy, make derivative works of, and distribute the Service Data Objects
+JavaDoc and Interface Definition Files files in any medium without fee or royalty as part
+of a compliant implementation of the Service Data Objects Specification is hereby granted.
+The Service Data Objects Specification may be found at any of the following locations:
+
+http://dev2dev.bea.com/technologies/commonj/index.jsp
+http://www.ibm.com/developerworks/library/specification/ws-sdo/
+http://oracle.com/technology/webservices/sca
+https://www.sdn.sap.com/
+http://www.xcalia/xdn/specs/sdo
+
+THE SERVICE DATA OBJECTS SPECIFICATION AND THE JAVADOC AND INTERFACE DEFINITION FILES
+ARE PROVIDED "AS IS," AND THE AUTHORS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS
+SPECIFICATION OR THE JAVADOC AND INTERFACE DEFINITION FILES AND THE IMPLEMENTATION OF THEIR CONTENTS,
+INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+NON-INFRINGEMENT OR TITLE. THE AUTHORS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL,
+INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR RELATING TO ANY USE OR DISTRIBUTION OF THE
+SERVICE DATA OBJECTS SPECIFICATION OR THE JAVADOC OR INTERFACE DEFINTION FILES.
+
+The name and trademarks of the Authors may NOT be used in any manner, including advertising or
+publicity pertaining to the Service Component Architecture Specification or its contents without specific,
+written prior permission. Title to copyright in the Service Data Objects Specification and the
+JavaDoc and Interface Definition Files will at all times remain with the Authors.
+
+No other rights are granted by implication, estoppel or otherwise.
+
+=================================================================================================================
+Eclipse Public License - v 1.0
+
+THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
+
+1. DEFINITIONS
+
+"Contribution" means:
+
+a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and
+b) in the case of each subsequent Contributor:
+
+i) changes to the Program, and
+
+ii) additions to the Program;
+
+where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program.
+
+"Contributor" means any person or entity that distributes the Program.
+
+"Licensed Patents " mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program.
+
+"Program" means the Contributions distributed in accordance with this Agreement.
+
+"Recipient" means anyone who receives the Program under this Agreement, including all Contributors.
+
+2. GRANT OF RIGHTS
+
+a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.
+
+b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder.
+
+c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.
+
+d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement.
+
+3. REQUIREMENTS
+
+A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:
+
+a) it complies with the terms and conditions of this Agreement; and
+
+b) its license agreement:
+
+i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;
+
+ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;
+
+iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and
+
+iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.
+
+When the Program is made available in source code form:
+
+a) it must be made available under this Agreement; and
+
+b) a copy of this Agreement must be included with each copy of the Program.
+
+Contributors may not remove or alter any copyright notices contained within the Program.
+
+Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution.
+
+4. COMMERCIAL DISTRIBUTION
+
+Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.
+
+For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.
+
+5. NO WARRANTY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED 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. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations.
+
+6. DISCLAIMER OF LIABILITY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+7. GENERAL
+
+If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
+
+If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed.
+
+All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive.
+
+Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved.
+
+This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.
+
+===================================================================================================
+
+Common Public License - v 1.0
+
+THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
+
+1. DEFINITIONS
+
+"Contribution" means:
+
+ a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and
+ b) in the case of each subsequent Contributor:
+
+ i) changes to the Program, and
+
+ ii) additions to the Program;
+
+ where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program.
+
+"Contributor" means any person or entity that distributes the Program.
+
+"Licensed Patents " mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program.
+
+"Program" means the Contributions distributed in accordance with this Agreement.
+
+"Recipient" means anyone who receives the Program under this Agreement, including all Contributors.
+
+2. GRANT OF RIGHTS
+
+ a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.
+
+ b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder.
+
+ c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.
+
+ d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement.
+
+3. REQUIREMENTS
+
+A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:
+
+ a) it complies with the terms and conditions of this Agreement; and
+
+ b) its license agreement:
+
+ i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;
+
+ ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;
+
+ iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and
+
+ iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.
+
+When the Program is made available in source code form:
+
+ a) it must be made available under this Agreement; and
+
+ b) a copy of this Agreement must be included with each copy of the Program.
+
+Contributors may not remove or alter any copyright notices contained within the Program.
+
+Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution.
+
+4. COMMERCIAL DISTRIBUTION
+
+Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.
+
+For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.
+
+5. NO WARRANTY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED 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. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement, including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations.
+
+6. DISCLAIMER OF LIABILITY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+7. GENERAL
+
+If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
+
+If Recipient institutes patent litigation against a Contributor with respect to a patent applicable to software (including a cross-claim or counterclaim in a lawsuit), then any patent licenses granted by that Contributor to such Recipient under this Agreement shall terminate as of the date such litigation is filed. In addition, if Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed.
+
+All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive.
+
+Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. IBM is the initial Agreement Steward. IBM may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved.
+
+This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.
+
+
+
+
+
+
diff --git a/tags/java/tsss-demo/core-samples/standalone/loanapplication/NOTICE.txt b/tags/java/tsss-demo/core-samples/standalone/loanapplication/NOTICE.txt
new file mode 100644
index 0000000000..4dbc3a8099
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/loanapplication/NOTICE.txt
@@ -0,0 +1,32 @@
+Apache Tuscany SCA for Java
+Copyright 2006 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+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.
+
+Unless otherwise indicated, all distribution made available by the Apache Software Foundation
+is provided to you under the terms and conditions of the Apache License Version 2.0 ("AL").
+A copy of the AL is provided with this distribution as the LICENSE.txt file present in the
+root directory, and is also available at http://www.apache.org/licenses/.
+
+The terms and conditions governing the distribution may refer to the AL or other license
+agreements, notices or terms and conditions. Some of these other license agreements may
+include (but are not limited to):
+
+ . Eclipse Public License Version 1.0 (available at http://www.eclipse.org/legal/epl-v10.html)
+ . Common Public License Version 1.0 (available at http://www.eclipse.org/legal/cpl-v10.html)
+
+This product also includes software developed by:
+- the Eclipse Modeling Framework project (http://www.eclipse.org/emf/)
+
+It is your obligation to read and accept all such terms and conditions prior to use of the
+distribution. If term or condition is provided, please contact the Apache Software Foundation
+to determine what terms and conditions govern that particular distribution.
diff --git a/tags/java/tsss-demo/core-samples/standalone/loanapplication/pom.xml b/tags/java/tsss-demo/core-samples/standalone/loanapplication/pom.xml
new file mode 100644
index 0000000000..3aa6937d7c
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/loanapplication/pom.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca.core-samples</groupId>
+ <artifactId>standalone</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.core-samples.standalone</groupId>
+ <artifactId>loan-application</artifactId>
+ <packaging>jar</packaging>
+ <name>Apache Tuscany Loan Application Client Sample</name>
+ <description>A sample demonstrating the use of asynchronous and conversational services.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osoa</groupId>
+ <artifactId>sca-api-r1.0</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${artifactId}</finalName>
+ </build>
+</project>
diff --git a/tags/java/tsss-demo/core-samples/standalone/loanapplication/readme.html b/tags/java/tsss-demo/core-samples/standalone/loanapplication/readme.html
new file mode 100644
index 0000000000..ec6eff8548
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/loanapplication/readme.html
@@ -0,0 +1,86 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+
+<html>
+<head>
+ <meta http-equiv="Content-Type" content=
+ "text/html; charset=us-ascii">
+ <meta http-equiv="Content-Style-Type" content="text/css">
+
+ <title>Tuscany Loan Application Conversational and Callback Services Sample</title>
+ <!-- LINK rel="stylesheet" href="ait.css" type="text/css" -->
+ <link rel="stylesheet" href="../../css/base.css" type="text/css">
+</head>
+
+<body>
+ <h3>Tuscany Loan Application Conversational and Callback Services Sample</h3>
+
+ <h4>Overview</h4>
+
+ <p>This sample illustrates the use of conversational services and callbacks in Tuscany.</p>
+
+ <h4>Location</h4>
+
+ <p>The sample is located &nbsp;in the
+ samples\standalone\loanapplication directory. All commands should be issued while working in the sample
+ directory.</p>
+
+ <h4>Prerequisites</h4>
+
+ <p>Obtain the following prerequisites and install according to
+ their documentation.</p>
+
+ <ul>
+ <li><a href="http://java.sun.com/javase/downloads/index.jsp"
+ target="_blank">JDK 5.0</a></li>
+
+ <li><a href="http://maven.apache.org/download.html" target=
+ "_blank">Maven 2.0.4</a></li>
+ </ul>
+
+ <h4>Building</h4>
+
+ <p>To build the sample&nbsp; issue :</p>
+ <pre>
+<code>mvn install<br></code>
+</pre>
+
+ <p>The result after executing is in the <span style=
+ "font-weight: bold;">target</span> subdirectory the <span style=
+ "font-weight: bold;">loan-application.jar</span></p>
+
+ <h4>Running</h4>
+
+ <p>Boot the Tuscany standalone runtime environment using the
+ following command:</p>
+ <pre>
+<code>java -jar {path-to-launcher.jar} target/loan-application.jar <br></code>
+</pre>
+
+ <p>where {path-to-launcher.jar} is the path to the Tuscany launcher jar </p>
+
+ <pre>
+<code></code>
+</pre>
+
+ <h4>Results</h4>
+
+ </body>
+</html>
diff --git a/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/client/ClientService.java b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/client/ClientService.java
new file mode 100644
index 0000000000..2c2fcaf1e0
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/client/ClientService.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 loanapplication.client;
+
+/**
+ * Interacts with the {@link loanapplication.provider.LoanService}, initiating a loan application process that
+ * demonstrates the use of conversational services and callbacks
+ */
+public interface ClientService {
+
+
+}
diff --git a/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/client/impl/ClientServiceImpl.java b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/client/impl/ClientServiceImpl.java
new file mode 100644
index 0000000000..cfda4558f6
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/client/impl/ClientServiceImpl.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 loanapplication.client.impl;
+
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Scope;
+import org.osoa.sca.annotations.Service;
+
+import loanapplication.client.ClientService;
+import loanapplication.message.Application;
+import loanapplication.message.LoanPackage;
+import loanapplication.message.impl.ApplicationImpl;
+import loanapplication.provider.LoanService;
+import loanapplication.provider.LoanServiceCallback;
+
+/**
+ * Demonstrates a client to the conversational loan service that receives a set of callbacks. This component
+ * implementation is configured as a Tuscany "launched" component type. The standalone launcher will invoke {@link
+ * #main(String[])} when the application is started.
+ */
+@Service(ClientService.class)
+@Scope("COMPOSITE")
+public class ClientServiceImpl implements ClientService, LoanServiceCallback {
+ private LoanService loanService;
+
+ /**
+ * Instantiates a new client with a reference to the loan service
+ *
+ * @param loanService the loan service
+ */
+ public ClientServiceImpl(@Reference(name = "loanService")LoanService loanService) {
+ this.loanService = loanService;
+ }
+
+ /**
+ * The method invoked to initiate a new application process.
+ *
+ * @param args startup parameters
+ * @return the return code
+ */
+ public int main(String[] args) {
+ System.out.println("Client applying for loan");
+ Application app = new ApplicationImpl();
+ app.setCustomerID("12345");
+ app.setAmount(100000);
+ app.setTerm(30);
+ app.setType(Application.FIXED);
+ loanService.apply(app);
+ return 1;
+ }
+
+ public void creditScoreResult(int code) {
+ System.out.println("Callback: credit score was " + code);
+ }
+
+ public void applicationResult(int code) {
+ if (code == APPROVED) {
+ System.out.println("Callback: the loan has been approved");
+ System.out.println("Client securing loan");
+ loanService.secureLoan();
+ } else {
+ System.out.println("Callback: the loan has been declined");
+ }
+ }
+
+ public void loanPackage(LoanPackage loanPackage) {
+ System.out.println("Callback: loan package received");
+ }
+}
diff --git a/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/message/Application.java b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/message/Application.java
new file mode 100644
index 0000000000..0d689f79b7
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/message/Application.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 loanapplication.message;
+
+/**
+ * A loan application
+ */
+public interface Application {
+ int FIXED = 1;
+ int FIVE_YEAR_VARIABLE = 2;
+
+ String getCustomerID();
+
+ void setCustomerID(String customerID);
+
+ float getAmount();
+
+ void setAmount(float amount);
+
+ float getDownPayment();
+
+ void setDownPayment(float downPayment);
+
+ int getType();
+
+ void setType(int type);
+
+ int getTerm();
+
+ void setTerm(int term);
+}
diff --git a/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/message/LoanPackage.java b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/message/LoanPackage.java
new file mode 100644
index 0000000000..cd8cdcc04d
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/message/LoanPackage.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 loanapplication.message;
+
+/**
+ * Contains information for a completed loan
+ */
+public interface LoanPackage {
+
+ String getLoanNumber();
+
+ void setLoanNumber(String loanNumber);
+
+ int getType();
+
+ void setType(int type);
+
+ float getAmount();
+
+ void setAmount(float amount);
+
+ float getRate();
+
+ void setRate(float rate);
+
+ int getTerm();
+
+ void setTerm(int term);
+}
diff --git a/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/message/impl/ApplicationImpl.java b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/message/impl/ApplicationImpl.java
new file mode 100644
index 0000000000..7b0049b8a5
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/message/impl/ApplicationImpl.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 loanapplication.message.impl;
+
+import java.io.Serializable;
+
+import loanapplication.message.Application;
+
+/**
+ * A simple implementation of an Application
+ */
+public class ApplicationImpl implements Application, Serializable {
+ private static final long serialVersionUID = -4289535647716763141L;
+ private float amount;
+ private float downPayment;
+ private String customerID;
+ private int type;
+ private int term;
+
+ public float getAmount() {
+ return amount;
+ }
+
+ public void setAmount(float amount) {
+ this.amount = amount;
+ }
+
+ public float getDownPayment() {
+ return downPayment;
+ }
+
+ public void setDownPayment(float downPayment) {
+ this.downPayment = downPayment;
+ }
+
+ public String getCustomerID() {
+ return customerID;
+ }
+
+ public void setCustomerID(String customerID) {
+ this.customerID = customerID;
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ public void setType(int type) {
+ this.type = type;
+ }
+
+ public int getTerm() {
+ return term;
+ }
+
+ public void setTerm(int term) {
+ this.term = term;
+ }
+}
diff --git a/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/message/impl/LoanPackageImpl.java b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/message/impl/LoanPackageImpl.java
new file mode 100644
index 0000000000..4beee06b57
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/message/impl/LoanPackageImpl.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 loanapplication.message.impl;
+
+import java.io.Serializable;
+
+import loanapplication.message.LoanPackage;
+
+/**
+ * A simple implementation of a LoanPackage
+ */
+public class LoanPackageImpl implements LoanPackage, Serializable {
+ private static final long serialVersionUID = 51755060138169723L;
+ private int type;
+ private float amount;
+ private float rate;
+ private int term;
+ private String loanNumber;
+
+ public String getLoanNumber() {
+ return loanNumber;
+ }
+
+ public void setLoanNumber(String loanNumber) {
+ this.loanNumber = loanNumber;
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ public void setType(int type) {
+ this.type = type;
+ }
+
+ public float getAmount() {
+ return amount;
+ }
+
+ public void setAmount(float amount) {
+ this.amount = amount;
+ }
+
+ public float getRate() {
+ return rate;
+ }
+
+ public void setRate(float rate) {
+ this.rate = rate;
+ }
+
+ public int getTerm() {
+ return term;
+ }
+
+ public void setTerm(int term) {
+ this.term = term;
+ }
+}
diff --git a/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/CreditService.java b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/CreditService.java
new file mode 100644
index 0000000000..38444abbd4
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/CreditService.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 loanapplication.provider;
+
+/**
+ * Performs a credit check on a customer
+ */
+public interface CreditService {
+
+ /**
+ * Returns the customer credit score
+ *
+ * @param customerID the customer ID
+ * @return the credit score
+ */
+ int getCreditScore(String customerID);
+
+}
diff --git a/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/LoanService.java b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/LoanService.java
new file mode 100644
index 0000000000..c9eb01dbb3
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/LoanService.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 loanapplication.provider;
+
+import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.Conversational;
+import org.osoa.sca.annotations.EndsConversation;
+
+import loanapplication.message.Application;
+
+/**
+ * Defines the loan service contract.
+ */
+@Conversational
+@Callback(LoanServiceCallback.class)
+public interface LoanService {
+
+ /**
+ * Submits a new loan application. Calling this method will start a new conversation if one has not been previously
+ * initiated.
+ *
+ * @param application the loan application
+ */
+ void apply(Application application);
+
+ /**
+ * Called after the loan has been approved and when the client is read to complete the process. Calling this method
+ * will end the conversation.
+ */
+ @EndsConversation
+ void secureLoan();
+
+ /**
+ * Called to cancel a loan application. Calling this method will end the conversation.
+ */
+ @EndsConversation
+ void cancel();
+
+}
diff --git a/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/LoanServiceCallback.java b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/LoanServiceCallback.java
new file mode 100644
index 0000000000..8b67017a55
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/LoanServiceCallback.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 loanapplication.provider;
+
+import loanapplication.message.LoanPackage;
+
+/**
+ * Defines the callback contract for loan service clients
+ */
+public interface LoanServiceCallback {
+ int APPROVED = 1;
+ int DECLINED = -1;
+
+ /**
+ * Called when the customer's credit score is received from the credit check process.
+ *
+ * @param code the customer's credit score.
+ */
+ void creditScoreResult(int code);
+
+ /**
+ * Called to the loan has been {@link LoanServiceCallback#APPROVED} or {@link LoanServiceCallback#DECLINED}.
+ *
+ * @param code if the loan application was approved or declined.
+ */
+ void applicationResult(int code);
+
+ /**
+ * Called after the loan has been secured to provide the completed loan information.
+ *
+ * @param loanPackage the loan information.
+ */
+ void loanPackage(LoanPackage loanPackage);
+
+}
diff --git a/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/RateService.java b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/RateService.java
new file mode 100644
index 0000000000..6d53c7d6b7
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/RateService.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 loanapplication.provider;
+
+/**
+ *
+ */
+public interface RateService {
+
+ float getRate(int type);
+
+}
diff --git a/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/impl/CreditServiceImpl.java b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/impl/CreditServiceImpl.java
new file mode 100644
index 0000000000..86c5f722d1
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/impl/CreditServiceImpl.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 loanapplication.provider.impl;
+
+import loanapplication.provider.CreditService;
+
+/**
+ * The credit service implementation
+ */
+public class CreditServiceImpl implements CreditService {
+
+ public int getCreditScore(String customerID) {
+ System.out.println("Credit Service: Performing credit check");
+ return 700;
+ }
+}
diff --git a/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/impl/LoanServiceImpl.java b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/impl/LoanServiceImpl.java
new file mode 100644
index 0000000000..fc36ec1d53
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/impl/LoanServiceImpl.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 loanapplication.provider.impl;
+
+import java.io.Serializable;
+import java.util.UUID;
+
+import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Scope;
+
+import loanapplication.message.Application;
+import loanapplication.provider.CreditService;
+import loanapplication.provider.LoanService;
+import loanapplication.provider.LoanServiceCallback;
+import loanapplication.provider.RateService;
+
+/**
+ * The loan service implementation
+ */
+@Scope("CONVERSATION")
+public class LoanServiceImpl implements LoanService, Serializable {
+ private static final long serialVersionUID = 7801583139613235069L;
+ // the loan number, demonstrates the use of conversational state
+ private String loanNumber;
+ private CreditService creditService;
+ private RateService rateService;
+ private LoanServiceCallback callback;
+
+ /**
+ * Instantiates a new component instance, passing in references to the credit and rate services
+ *
+ * @param creditService the credit service
+ * @param rateService the rate service
+ */
+ public LoanServiceImpl(@Reference(name = "creditService", required = true)CreditService creditService,
+ @Reference(name = "rateService", required = true)RateService rateService) {
+ this.creditService = creditService;
+ this.rateService = rateService;
+ }
+
+ /**
+ * A setter method for injecting the client callback reference. The reference will be injected by the runtime
+ *
+ * @param callback the client callback reference
+ */
+ @Callback
+ public void setCallback(LoanServiceCallback callback) {
+ this.callback = callback;
+ }
+
+ public void apply(Application application) {
+ String id = application.getCustomerID();
+ loanNumber = UUID.randomUUID().toString();
+ System.out.println("---------------------------------------------------------------------");
+ System.out.println("Application received for customer");
+ System.out.println("Assigned loan number: " + loanNumber);
+ System.out.println("---------------------------------------------------------------------");
+ int rating = creditService.getCreditScore(id);
+ if (rating > 500) {
+ // approve the loan
+ callback.creditScoreResult(rating);
+ rateService.getRate(application.getType());
+ callback.applicationResult(LoanServiceCallback.APPROVED);
+ } else {
+ // reject the loan
+ callback.creditScoreResult(rating);
+ callback.applicationResult(LoanServiceCallback.DECLINED);
+ }
+ }
+
+ public void secureLoan() {
+ System.out.println("---------------------------------------------------------------------");
+ System.out.println("Loan secured");
+ System.out.println("Loan number: " + loanNumber);
+ System.out.println("---------------------------------------------------------------------");
+ }
+
+ public void cancel() {
+ System.out.println("---------------------------------------------------------------------");
+ System.out.println("Loan cancelled");
+ System.out.println("Loan number: " + loanNumber);
+ System.out.println("---------------------------------------------------------------------");
+ }
+}
diff --git a/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/impl/RateServiceImpl.java b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/impl/RateServiceImpl.java
new file mode 100644
index 0000000000..6860b465ea
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/java/loanapplication/provider/impl/RateServiceImpl.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 loanapplication.provider.impl;
+
+import loanapplication.message.Application;
+import loanapplication.provider.RateService;
+
+/**
+ * The rate service implementation
+ */
+public class RateServiceImpl implements RateService {
+
+ public float getRate(int type) {
+ System.out.println("Rate Service: Calculating rate");
+ if (type == Application.FIVE_YEAR_VARIABLE) {
+ return 6.0f;
+ } else {
+ return 6.5f;
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/resources/META-INF/sca/default.scdl b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/resources/META-INF/sca/default.scdl
new file mode 100644
index 0000000000..7b9c840588
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/loanapplication/src/main/resources/META-INF/sca/default.scdl
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/2.0-alpha"
+ name="LoanApplication">
+
+ <component name="LoanClient">
+ <tuscany:launched class="loanapplication.client.impl.ClientServiceImpl"/>
+ <reference name="loanService" target="LoanService"/>
+ </component>
+
+ <component name="LoanService">
+ <implementation.java class="loanapplication.provider.impl.LoanServiceImpl"/>
+ <reference name="creditService" target="CreditService"/>
+ <reference name="rateService" target="RateService"/>
+ </component>
+
+ <component name="CreditService">
+ <implementation.java class="loanapplication.provider.impl.CreditServiceImpl"/>
+ </component>
+
+ <component name="RateService">
+ <implementation.java class="loanapplication.provider.impl.RateServiceImpl"/>
+ </component>
+
+</composite>
+
+<!-- Alternatively, the following demonstrates the same assembly using autowire instead of direct reference targets -->
+<!--
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/2.0-alpha"
+ name="LoanApplication"
+ autowire="true">
+ <component name="LoanClient">
+ <tuscany:launched class="loanapplication.client.impl.ClientServiceImpl"/>
+ </component>
+
+ <component name="LoanService">
+ <implementation.java class="loanapplication.provider.impl.LoanServiceImpl"/>
+ </component>
+
+ <component name="CreditService">
+ <implementation.java class="loanapplication.provider.impl.CreditServiceImpl"/>
+ </component>
+
+ <component name="RateService">
+ <implementation.java class="loanapplication.provider.impl.RateServiceImpl"/>
+ </component>
+
+</composite>
+-->
diff --git a/tags/java/tsss-demo/core-samples/standalone/pom.xml b/tags/java/tsss-demo/core-samples/standalone/pom.xml
new file mode 100644
index 0000000000..22b0d00e02
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/standalone/pom.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>core-samples</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.core-samples</groupId>
+ <artifactId>standalone</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache Tuscany Core Samples Standalone</name>
+ <description>Sample projects that run in the standalone environment.</description>
+
+</project>
diff --git a/tags/java/tsss-demo/core-samples/webapp/pom.xml b/tags/java/tsss-demo/core-samples/webapp/pom.xml
new file mode 100644
index 0000000000..34447362b1
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/webapp/pom.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>core-samples</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.core-samples</groupId>
+ <artifactId>webapp</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache Tuscany Core Samples Webapp</name>
+ <description>Sample projects that run in the webapp environment.</description>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.runtime.webapp</groupId>
+ <artifactId>webapp-api</artifactId>
+ <version>${kernelVersion}</version>
+ <scope>runtime</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.tuscany</groupId>
+ <artifactId>tuscany-war-plugin</artifactId>
+ <version>${kernelVersion}</version>
+ <executions>
+ <execution>
+ <id>tuscany-war</id>
+ <goals>
+ <goal>tuscany-war</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
diff --git a/tags/java/tsss-demo/core-samples/webapp/webcalc/LICENSE.txt b/tags/java/tsss-demo/core-samples/webapp/webcalc/LICENSE.txt
new file mode 100644
index 0000000000..bdec70a4fa
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/webapp/webcalc/LICENSE.txt
@@ -0,0 +1,416 @@
+
+ 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.
+
+===============================================================================================================
+
+
+License for the Service Data Objects JavaDoc and Interface Definition files.
+
+Permission to copy, make derivative works of, and distribute the Service Data Objects
+JavaDoc and Interface Definition Files files in any medium without fee or royalty as part
+of a compliant implementation of the Service Data Objects Specification is hereby granted.
+The Service Data Objects Specification may be found at any of the following locations:
+
+http://dev2dev.bea.com/technologies/commonj/index.jsp
+http://www.ibm.com/developerworks/library/specification/ws-sdo/
+http://oracle.com/technology/webservices/sca
+https://www.sdn.sap.com/
+http://www.xcalia/xdn/specs/sdo
+
+THE SERVICE DATA OBJECTS SPECIFICATION AND THE JAVADOC AND INTERFACE DEFINITION FILES
+ARE PROVIDED "AS IS," AND THE AUTHORS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS
+SPECIFICATION OR THE JAVADOC AND INTERFACE DEFINITION FILES AND THE IMPLEMENTATION OF THEIR CONTENTS,
+INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+NON-INFRINGEMENT OR TITLE. THE AUTHORS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL,
+INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR RELATING TO ANY USE OR DISTRIBUTION OF THE
+SERVICE DATA OBJECTS SPECIFICATION OR THE JAVADOC OR INTERFACE DEFINTION FILES.
+
+The name and trademarks of the Authors may NOT be used in any manner, including advertising or
+publicity pertaining to the Service Component Architecture Specification or its contents without specific,
+written prior permission. Title to copyright in the Service Data Objects Specification and the
+JavaDoc and Interface Definition Files will at all times remain with the Authors.
+
+No other rights are granted by implication, estoppel or otherwise.
+
+=================================================================================================================
+Eclipse Public License - v 1.0
+
+THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
+
+1. DEFINITIONS
+
+"Contribution" means:
+
+a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and
+b) in the case of each subsequent Contributor:
+
+i) changes to the Program, and
+
+ii) additions to the Program;
+
+where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program.
+
+"Contributor" means any person or entity that distributes the Program.
+
+"Licensed Patents " mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program.
+
+"Program" means the Contributions distributed in accordance with this Agreement.
+
+"Recipient" means anyone who receives the Program under this Agreement, including all Contributors.
+
+2. GRANT OF RIGHTS
+
+a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.
+
+b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder.
+
+c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.
+
+d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement.
+
+3. REQUIREMENTS
+
+A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:
+
+a) it complies with the terms and conditions of this Agreement; and
+
+b) its license agreement:
+
+i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;
+
+ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;
+
+iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and
+
+iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.
+
+When the Program is made available in source code form:
+
+a) it must be made available under this Agreement; and
+
+b) a copy of this Agreement must be included with each copy of the Program.
+
+Contributors may not remove or alter any copyright notices contained within the Program.
+
+Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution.
+
+4. COMMERCIAL DISTRIBUTION
+
+Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.
+
+For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.
+
+5. NO WARRANTY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED 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. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations.
+
+6. DISCLAIMER OF LIABILITY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+7. GENERAL
+
+If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
+
+If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed.
+
+All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive.
+
+Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved.
+
+This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.
+
+===================================================================================================
+
+Common Public License - v 1.0
+
+THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
+
+1. DEFINITIONS
+
+"Contribution" means:
+
+ a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and
+ b) in the case of each subsequent Contributor:
+
+ i) changes to the Program, and
+
+ ii) additions to the Program;
+
+ where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program.
+
+"Contributor" means any person or entity that distributes the Program.
+
+"Licensed Patents " mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program.
+
+"Program" means the Contributions distributed in accordance with this Agreement.
+
+"Recipient" means anyone who receives the Program under this Agreement, including all Contributors.
+
+2. GRANT OF RIGHTS
+
+ a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.
+
+ b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder.
+
+ c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.
+
+ d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement.
+
+3. REQUIREMENTS
+
+A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:
+
+ a) it complies with the terms and conditions of this Agreement; and
+
+ b) its license agreement:
+
+ i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;
+
+ ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;
+
+ iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and
+
+ iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.
+
+When the Program is made available in source code form:
+
+ a) it must be made available under this Agreement; and
+
+ b) a copy of this Agreement must be included with each copy of the Program.
+
+Contributors may not remove or alter any copyright notices contained within the Program.
+
+Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution.
+
+4. COMMERCIAL DISTRIBUTION
+
+Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.
+
+For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.
+
+5. NO WARRANTY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED 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. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement, including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations.
+
+6. DISCLAIMER OF LIABILITY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+7. GENERAL
+
+If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
+
+If Recipient institutes patent litigation against a Contributor with respect to a patent applicable to software (including a cross-claim or counterclaim in a lawsuit), then any patent licenses granted by that Contributor to such Recipient under this Agreement shall terminate as of the date such litigation is filed. In addition, if Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed.
+
+All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive.
+
+Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. IBM is the initial Agreement Steward. IBM may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved.
+
+This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.
+
+
+
+
+
+
diff --git a/tags/java/tsss-demo/core-samples/webapp/webcalc/NOTICE.txt b/tags/java/tsss-demo/core-samples/webapp/webcalc/NOTICE.txt
new file mode 100644
index 0000000000..4dbc3a8099
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/webapp/webcalc/NOTICE.txt
@@ -0,0 +1,32 @@
+Apache Tuscany SCA for Java
+Copyright 2006 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+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.
+
+Unless otherwise indicated, all distribution made available by the Apache Software Foundation
+is provided to you under the terms and conditions of the Apache License Version 2.0 ("AL").
+A copy of the AL is provided with this distribution as the LICENSE.txt file present in the
+root directory, and is also available at http://www.apache.org/licenses/.
+
+The terms and conditions governing the distribution may refer to the AL or other license
+agreements, notices or terms and conditions. Some of these other license agreements may
+include (but are not limited to):
+
+ . Eclipse Public License Version 1.0 (available at http://www.eclipse.org/legal/epl-v10.html)
+ . Common Public License Version 1.0 (available at http://www.eclipse.org/legal/cpl-v10.html)
+
+This product also includes software developed by:
+- the Eclipse Modeling Framework project (http://www.eclipse.org/emf/)
+
+It is your obligation to read and accept all such terms and conditions prior to use of the
+distribution. If term or condition is provided, please contact the Apache Software Foundation
+to determine what terms and conditions govern that particular distribution.
diff --git a/tags/java/tsss-demo/core-samples/webapp/webcalc/pom.xml b/tags/java/tsss-demo/core-samples/webapp/webcalc/pom.xml
new file mode 100644
index 0000000000..e7836a033d
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/webapp/webcalc/pom.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca.core-samples</groupId>
+ <artifactId>webapp</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.core-samples.webapp</groupId>
+ <artifactId>webcalc</artifactId>
+ <packaging>war</packaging>
+ <name>Apache Tuscany WebApp Calculator Sample</name>
+ <description>A sample using an SCA composite a web application.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.core-samples.common</groupId>
+ <artifactId>calculator</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca.runtime.webapp</groupId>
+ <artifactId>webapp-api</artifactId>
+ </dependency>
+ </dependencies>
+ <build>
+ <finalName>${artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.tuscany</groupId>
+ <artifactId>tuscany-war-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tags/java/tsss-demo/core-samples/webapp/webcalc/readme.html b/tags/java/tsss-demo/core-samples/webapp/webcalc/readme.html
new file mode 100644
index 0000000000..1f7cde1bbb
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/webapp/webcalc/readme.html
@@ -0,0 +1,118 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+
+<html>
+<head>
+ <meta http-equiv="Content-Type" content=
+ "text/html; charset=us-ascii">
+ <meta http-equiv="Content-Style-Type" content="text/css">
+
+ <title>Tuscany Webapp Sample</title>
+ <link rel="stylesheet" href="../../css/base.css" type="text/css">
+</head>
+
+<body>
+ <!-- LINK rel="stylesheet" href="ait.css" type="text/css" -->
+ <!-- maven --><!-- end maven -->
+
+ <h3>Tuscany Webapp Sample</h3>
+
+ <h4>Overview</h4>
+
+ <p>This sample illustrates how to use Apache Tuscany to run a SCA composite inside a
+web application. It describes how to run it on Apache Tomcat but the application
+should be portable to other containers such as Jetty or commmercial servers.</p>
+
+ <h4>Location</h4>
+
+ <p>This sample is located&nbsp;in the&nbsp; <a href=
+ ".">samples\webapp\webapp</a> directory. &nbsp;All
+ the following commands should be issued while working in the
+ sample directory.&nbsp;</p>
+
+ <h4>Prerequisites</h4>
+
+ <p>Obtain the following prerequisites and install according to
+ their documentation.</p>
+
+ <ul>
+ <li><a href="http://java.sun.com/javase/downloads/index.jsp"
+ target="_blank">JDK 5.0</a></li>
+
+ <li><a href="http://maven.apache.org/download.html" target=
+ "_blank">Maven 2.0.4</a></li>
+
+ <li><a href="http://tomcat.apache.org/download-55.cgi" target=
+ "_blank">Apache Tomcat 5.xx</a> latest version binary core
+ distribution.&nbsp;</li>
+
+ <li>This sample reuses the composite from the &nbsp;<a href= "../../standalone/calculator/readme.html" target="_blank">calculator sample</a>&nbsp;
+ so that sample must have beed built before building this sample.</li>
+ </ul>
+
+ <h4>Building</h4>
+
+ <p>To build the sample issue :</p>
+ <pre>
+<code>mvn</code>
+</pre>
+
+ <p>This should result in the creation of the war file
+ <span style="font-weight: bold;">target\sample-webapp.war</span></p>
+
+ <h4>Setup</h4>
+
+ <p>If you have enabled remote deployment in Tomcat by adding the
+ line:</p>
+
+ <p><code>&lt;user username="admin" password=""
+ roles="manager"/&gt;</code></p>
+
+ <p>into <span style="font-style: italic;">&lt;tomcat
+ dir&gt;</span>\conf\tomcat-users.xml you can deploy the WARs to
+ Tomcat using the tomcat-maven-plugin:</p>
+
+ <p><code>mvn tomcat:deploy</code></p>
+
+ <p>Alternatively you can copy the WAR files to Tomcat's webapps
+ directory. Copy <span style=
+ "font-weight: bold;">target\sample-webapp.war</span>
+ <span style="font-style: italic;">&lt;tomcat
+ dir&gt;</span>/webapps/.</p>
+
+ <h4>Running</h4>
+
+ <p>Start the tomcat server by issuing the following command ind
+ the <span style="font-style: italic;">&lt;tomcat
+ dir&gt;</span>\bin directory:</p>
+
+ <p><code>startup</code></p>
+
+ <p>Once you've started your web server, open a browser and go to sample-webapp page at
+&nbsp;<a href=
+ "http://localhost:8080/sample-webapp/" target=
+ "_blank">http://localhost:8080/sample-webapp/</a>&nbsp; and you should see a web page displaying:</p>
+<samp>
+<br><B>Expression Result</B>
+<br>2 + 3 5.0
+<br>3 - 2 1.0
+</samp>
+</body>
+</html>
diff --git a/tags/java/tsss-demo/core-samples/webapp/webcalc/src/main/webapp/WEB-INF/default.scdl b/tags/java/tsss-demo/core-samples/webapp/webcalc/src/main/webapp/WEB-INF/default.scdl
new file mode 100644
index 0000000000..d159fd7a38
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/webapp/webcalc/src/main/webapp/WEB-INF/default.scdl
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/2.0-alpha"
+ name="CalculatorComposite">
+
+ <!-- config that includes the calculator composite -->
+ <include name="CalculatorComposite" scdlResource="META-INF/sca/default.scdl"/>
+
+ <component name="webcalc">
+ <tuscany:webapp>
+ <reference name="calculatorService" interface="calculator.CalculatorService"/>
+ </tuscany:webapp>
+ <reference name="calculatorService" target="CalculatorServiceComponent"/>
+ </component>
+</composite>
diff --git a/tags/java/tsss-demo/core-samples/webapp/webcalc/src/main/webapp/WEB-INF/web.xml b/tags/java/tsss-demo/core-samples/webapp/webcalc/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000000..2232ddc3ef
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/webapp/webcalc/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+
+<web-app version="2.4"
+ xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
+
+ <display-name>Apache Tuscany Simple Webapp Sample</display-name>
+
+ <welcome-file-list id="WelcomeFileList">
+ <welcome-file>calc.jsp</welcome-file>
+ </welcome-file-list>
+
+ <listener>
+ <listener-class>org.apache.tuscany.runtime.webapp.TuscanyContextListener</listener-class>
+ </listener>
+
+ <context-param>
+ <param-name>tuscany.component</param-name>
+ <param-value>webcalc</param-value>
+ </context-param>
+</web-app>
diff --git a/tags/java/tsss-demo/core-samples/webapp/webcalc/src/main/webapp/calc.jsp b/tags/java/tsss-demo/core-samples/webapp/webcalc/src/main/webapp/calc.jsp
new file mode 100644
index 0000000000..f561f82ea4
--- /dev/null
+++ b/tags/java/tsss-demo/core-samples/webapp/webcalc/src/main/webapp/calc.jsp
@@ -0,0 +1,40 @@
+<%@ page import="calculator.CalculatorService" %>
+<%--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%
+ CalculatorService calc = (CalculatorService) application.getAttribute("calculatorService");
+%>
+<html>
+<head><title>Calculator Sample</title></head>
+
+<body>
+<table>
+ <tr>
+ <th>Expression</th><th>Result</th>
+ </tr>
+ <tr>
+ <td>2 + 3</td><td><%= calc.add(2, 3) %></td>
+ </tr>
+ <tr>
+ <td>3 - 2</td><td><%= calc.subtract(3, 2) %></td>
+ </tr>
+</table>
+</body>
+</html> \ No newline at end of file
diff --git a/tags/java/tsss-demo/demo.app/LICENSE.txt b/tags/java/tsss-demo/demo.app/LICENSE.txt
new file mode 100644
index 0000000000..0084319535
--- /dev/null
+++ b/tags/java/tsss-demo/demo.app/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, serviceDefinition marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/demo.app/NOTICE.txt b/tags/java/tsss-demo/demo.app/NOTICE.txt
new file mode 100644
index 0000000000..b18217bd7a
--- /dev/null
+++ b/tags/java/tsss-demo/demo.app/NOTICE.txt
@@ -0,0 +1,163 @@
+${project.name}
+Copyright (c) 2005 - 2007 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
+----- NOTICE from LICENSE.txt file for classworlds project --------------------
+* profiles/launcher/boot/classworlds-1.1.jar
+-------------------------------------------------------------------------------
+
+/*
+ $Id$
+
+ Copyright 2002 (C) The Codehaus. All Rights Reserved.
+
+ Redistribution and use of this software and associated documentation
+ ("Software"), with or without modification, are permitted provided
+ that the following conditions are met:
+
+ 1. Redistributions of source code must retain copyright
+ statements and notices. Redistributions must also contain a
+ copy of this document.
+
+ 2. Redistributions in binary form must reproduce the
+ above copyright notice, this list of conditions and the
+ following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+ 3. The name "classworlds" must not be used to endorse or promote
+ products derived from this Software without prior written
+ permission of The Codehaus. For written permission, please
+ contact bob@codehaus.org.
+
+ 4. Products derived from this Software may not be called "classworlds"
+ nor may "classworlds" appear in their names without prior written
+ permission of The Codehaus. "classworlds" is a registered
+ trademark of The Codehaus.
+
+ 5. Due credit should be given to The Codehaus.
+ (http://classworlds.codehaus.org/).
+
+ THIS SOFTWARE IS PROVIDED BY THE CODEHAUS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ THE CODEHAUS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ */
+
+
+----- NOTICE from LICENSE.txt file in jsch-0.1.24 distribution ----------------
+* profiles/launcher/boot/jsch-0.1.24.jar
+-------------------------------------------------------------------------------
+
+JSch 0.0.* was released under the GNU LGPL license. Later, we have switched
+over to a BSD-style license.
+
+------------------------------------------------------------------------------
+Copyright (c) 2002,2003,2004,2005 Atsuhiko Yamanaka, JCraft,Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the distribution.
+
+ 3. The names of the authors may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
+INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+----- NOTICE from Codehaus for Plexus Project ---------------------------------
+* profiles/launcher/boot/plexus-container-default-1.0-alpha-9.jar
+* profiles/launcher/boot/plexus-interactivity-api-1.0-alpha-4.jar
+* profiles/launcher/boot/plexus-utils-1.1.jar
+-------------------------------------------------------------------------------
+
+ The MIT License
+
+ Copyright (c) 2004, The Codehaus
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
+ this software and associated documentation files (the "Software"), to deal in
+ the Software without restriction, including without limitation the rights to
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ of the Software, and to permit persons to whom the Software is furnished to do
+ so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+
+-----
+
+Some portions of Plexus are also distributed under other BSD-style licenses
+including the Apache License Version 2.0
+
+----- NOTICE from StAX project at http://svn.codehaus.org/stax/trunk/dev/README-API.txt
+* profiles/launcher/boot/stax-api-1.0.1.jar
+-------------------------------------------------------------------------------
+
+These files together comprise the API for JSR 173 (Streaming API for XML Specification), including its API classes and interfaces.
+
+
+The following lists the files in this distribution:
+
+README-API.txt [README file for JSR 173 api bundle.]
+ASF2.0.txt [Apache Software Foundation License 2.0.]
+jsr173_1.0_api.jar [The API classes and interfaces in binary format.]
+jsr173_1.0_src.jar [The API classes and interfaces in source format.]
+
+Your right to use the listed files, whether together or individually, is governed by the Apache Software Foundation License 2.0 included in this bundle.
+
+Please see the javadoc for information on how to get started.
+
+----- NOTICE from wstx-asl-3.2.0.jar ------------------------------------------
+* profiles/launcher/boot/wstx-asl-3.2.0.jar
+-------------------------------------------------------------------------------
+
+This product currently only contains code developed by authors
+of specific components, as identified by the source code files.
+
+Since product implements StAX API, it has dependencies to StAX API
+classes.
+
+For additional credits (generally to people who reported problems)
+see CREDITS file.
diff --git a/tags/java/tsss-demo/demo.app/pom.xml b/tags/java/tsss-demo/demo.app/pom.xml
new file mode 100644
index 0000000000..9b79c61ee5
--- /dev/null
+++ b/tags/java/tsss-demo/demo.app/pom.xml
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany</groupId>
+ <artifactId>sca</artifactId>
+ <version>1.0-incubating</version>
+ </parent>
+ <groupId>org.apache.tuscany.distribution.sca</groupId>
+ <artifactId>demo-app</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>Tuscany Demo Application</name>
+ <description>Tuscany Demo Application.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-spi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.core-samples.common</groupId>
+ <artifactId>calculator</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <!-- compiler plugin configuration -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+</project>
diff --git a/tags/java/tsss-demo/demo.app/src/main/java/org/apache/tuscany/demo/app/CalculatorForm.java b/tags/java/tsss-demo/demo.app/src/main/java/org/apache/tuscany/demo/app/CalculatorForm.java
new file mode 100644
index 0000000000..e997032217
--- /dev/null
+++ b/tags/java/tsss-demo/demo.app/src/main/java/org/apache/tuscany/demo/app/CalculatorForm.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.demo.app;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tuscany.spi.host.ServletHost;
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * @version $Revision$ $Date$
+ */
+@SuppressWarnings("serial")
+@EagerInit
+@Service(Servlet.class)
+public class CalculatorForm extends HttpServlet {
+
+ /**
+ * Injects the servlet host.
+ *
+ * @param servletHost Servlet host to use.
+ */
+ @Reference
+ public void setServletHost(ServletHost servletHost) {
+ servletHost.registerMapping("/calculatorForm", this);
+ }
+
+ /**
+ * Processes the request.
+ *
+ * @param req Servlet request.
+ * @param res Servlet response.
+ * @throws ServletException Servlet exception.
+ * @throws IOException IO Exception.
+ */
+ protected void process(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+
+ PrintWriter writer = res.getWriter();
+ writer.println("<form name='' method='post' action='calculate'>");
+ writer.println("<input name='op1' type='text' size='10'>");
+ writer.println("<br/>");
+ writer.println("<input name='op2' type='text' size='10'>");
+ writer.println("<br/>");
+ writer.println("<input type='submit' value='Add'/>");
+ writer.println("</form>");
+ writer.flush();
+ writer.close();
+
+ }
+
+ /**
+ * Handles get requests.
+ */
+ @Override
+ protected final void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+ process(req, res);
+ }
+
+ /**
+ * Handles post request.
+ */
+ @Override
+ protected final void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+ process(req, res);
+ }
+
+}
diff --git a/tags/java/tsss-demo/demo.app/src/main/java/org/apache/tuscany/demo/app/CalculatorHandler.java b/tags/java/tsss-demo/demo.app/src/main/java/org/apache/tuscany/demo/app/CalculatorHandler.java
new file mode 100644
index 0000000000..771f0828ca
--- /dev/null
+++ b/tags/java/tsss-demo/demo.app/src/main/java/org/apache/tuscany/demo/app/CalculatorHandler.java
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.demo.app;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tuscany.core.component.SimpleWorkContext;
+import org.apache.tuscany.core.implementation.PojoWorkContextTunnel;
+import org.apache.tuscany.core.implementation.java.JavaComponent;
+import org.apache.tuscany.spi.component.ComponentManager;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.host.ServletHost;
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Service;
+
+import calculator.CalculatorService;
+
+/**
+ * @version $Revision$ $Date$
+ */
+@SuppressWarnings("serial")
+@EagerInit
+@Service(Servlet.class)
+public class CalculatorHandler extends HttpServlet {
+
+ // Calculator service
+ private ComponentManager componentManager;
+
+ /**
+ * Injects the servlet host.
+ *
+ * @param servletHost Servlet host to use.
+ */
+ @Reference
+ public void setServletHost(ServletHost servletHost) {
+ servletHost.registerMapping("/calculate", this);
+ }
+
+ /**
+ * Injects the calculator.
+ *
+ * @param componentManager Component manager.
+ */
+ @Reference
+ public void setComponentManager(ComponentManager componentManager) {
+ this.componentManager = componentManager;
+ }
+
+ /**
+ * Processes the request.
+ *
+ * @param req Servlet request.
+ * @param res Servlet response.
+ * @throws ServletException Servlet exception.
+ * @throws IOException IO Exception.
+ */
+ protected void process(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+
+
+ try {
+
+ PojoWorkContextTunnel.setThreadWorkContext(new SimpleWorkContext());
+
+ URI calculatorServiceUri = new URI("tuscany://./domain/CalculatorServiceComponent");
+
+ JavaComponent javaComponent = (JavaComponent) componentManager.getComponent(calculatorServiceUri);
+
+ ScopeContainer scopeContainer = javaComponent.getScopeContainer();
+ InstanceWrapper wrapper = scopeContainer.getWrapper(javaComponent, new URI("tuscany://./domain"));
+ CalculatorService calculatorService = (CalculatorService) wrapper.getInstance();
+ double op1 = Double.parseDouble(req.getParameter("op1"));
+ double op2 = Double.parseDouble(req.getParameter("op2"));
+ double result = calculatorService.add(op1, op2);
+
+ PrintWriter writer = res.getWriter();
+ writer.println("Result: " + result);
+ writer.flush();
+ writer.close();
+ } catch (URISyntaxException ex) {
+ throw new ServletException(ex);
+ } catch (TargetResolutionException ex) {
+ throw new ServletException(ex);
+ }
+ }
+
+ /**
+ * Handles get requests.
+ */
+ @Override
+ protected final void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+ process(req, res);
+ }
+
+ /**
+ * Handles post request.
+ */
+ @Override
+ protected final void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+ process(req, res);
+ }
+
+}
diff --git a/tags/java/tsss-demo/demo/LICENSE.txt b/tags/java/tsss-demo/demo/LICENSE.txt
new file mode 100644
index 0000000000..0084319535
--- /dev/null
+++ b/tags/java/tsss-demo/demo/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, serviceDefinition marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/demo/NOTICE.txt b/tags/java/tsss-demo/demo/NOTICE.txt
new file mode 100644
index 0000000000..b18217bd7a
--- /dev/null
+++ b/tags/java/tsss-demo/demo/NOTICE.txt
@@ -0,0 +1,163 @@
+${project.name}
+Copyright (c) 2005 - 2007 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
+----- NOTICE from LICENSE.txt file for classworlds project --------------------
+* profiles/launcher/boot/classworlds-1.1.jar
+-------------------------------------------------------------------------------
+
+/*
+ $Id$
+
+ Copyright 2002 (C) The Codehaus. All Rights Reserved.
+
+ Redistribution and use of this software and associated documentation
+ ("Software"), with or without modification, are permitted provided
+ that the following conditions are met:
+
+ 1. Redistributions of source code must retain copyright
+ statements and notices. Redistributions must also contain a
+ copy of this document.
+
+ 2. Redistributions in binary form must reproduce the
+ above copyright notice, this list of conditions and the
+ following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+ 3. The name "classworlds" must not be used to endorse or promote
+ products derived from this Software without prior written
+ permission of The Codehaus. For written permission, please
+ contact bob@codehaus.org.
+
+ 4. Products derived from this Software may not be called "classworlds"
+ nor may "classworlds" appear in their names without prior written
+ permission of The Codehaus. "classworlds" is a registered
+ trademark of The Codehaus.
+
+ 5. Due credit should be given to The Codehaus.
+ (http://classworlds.codehaus.org/).
+
+ THIS SOFTWARE IS PROVIDED BY THE CODEHAUS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ THE CODEHAUS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ */
+
+
+----- NOTICE from LICENSE.txt file in jsch-0.1.24 distribution ----------------
+* profiles/launcher/boot/jsch-0.1.24.jar
+-------------------------------------------------------------------------------
+
+JSch 0.0.* was released under the GNU LGPL license. Later, we have switched
+over to a BSD-style license.
+
+------------------------------------------------------------------------------
+Copyright (c) 2002,2003,2004,2005 Atsuhiko Yamanaka, JCraft,Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the distribution.
+
+ 3. The names of the authors may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
+INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+----- NOTICE from Codehaus for Plexus Project ---------------------------------
+* profiles/launcher/boot/plexus-container-default-1.0-alpha-9.jar
+* profiles/launcher/boot/plexus-interactivity-api-1.0-alpha-4.jar
+* profiles/launcher/boot/plexus-utils-1.1.jar
+-------------------------------------------------------------------------------
+
+ The MIT License
+
+ Copyright (c) 2004, The Codehaus
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
+ this software and associated documentation files (the "Software"), to deal in
+ the Software without restriction, including without limitation the rights to
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ of the Software, and to permit persons to whom the Software is furnished to do
+ so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+
+-----
+
+Some portions of Plexus are also distributed under other BSD-style licenses
+including the Apache License Version 2.0
+
+----- NOTICE from StAX project at http://svn.codehaus.org/stax/trunk/dev/README-API.txt
+* profiles/launcher/boot/stax-api-1.0.1.jar
+-------------------------------------------------------------------------------
+
+These files together comprise the API for JSR 173 (Streaming API for XML Specification), including its API classes and interfaces.
+
+
+The following lists the files in this distribution:
+
+README-API.txt [README file for JSR 173 api bundle.]
+ASF2.0.txt [Apache Software Foundation License 2.0.]
+jsr173_1.0_api.jar [The API classes and interfaces in binary format.]
+jsr173_1.0_src.jar [The API classes and interfaces in source format.]
+
+Your right to use the listed files, whether together or individually, is governed by the Apache Software Foundation License 2.0 included in this bundle.
+
+Please see the javadoc for information on how to get started.
+
+----- NOTICE from wstx-asl-3.2.0.jar ------------------------------------------
+* profiles/launcher/boot/wstx-asl-3.2.0.jar
+-------------------------------------------------------------------------------
+
+This product currently only contains code developed by authors
+of specific components, as identified by the source code files.
+
+Since product implements StAX API, it has dependencies to StAX API
+classes.
+
+For additional credits (generally to people who reported problems)
+see CREDITS file.
diff --git a/tags/java/tsss-demo/demo/demo.xml b/tags/java/tsss-demo/demo/demo.xml
new file mode 100644
index 0000000000..d3b7992566
--- /dev/null
+++ b/tags/java/tsss-demo/demo/demo.xml
@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<assembly>
+ <id>bin</id>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <formats>
+ <format>zip</format>
+ <format>tar.gz</format>
+ </formats>
+
+ <files>
+ <!-- include legal and other files -->
+ <file>
+ <source>LICENSE.txt</source>
+ <outputDirectory>/</outputDirectory>
+ </file>
+ <file>
+ <source>NOTICE.txt</source>
+ <outputDirectory>/</outputDirectory>
+ <filtered>true</filtered>
+ </file>
+ </files>
+
+ <fileSets>
+ <!-- include assembly files -->
+ <fileSet>
+ <directory>src/main</directory>
+ <outputDirectory>/</outputDirectory>
+ </fileSet>
+ </fileSets>
+
+ <dependencySets>
+ <!-- copy executable commands to the bin directory without version info -->
+ <dependencySet>
+ <includes>
+ <include>org.apache.tuscany.sca.runtime.standalone:server.start</include>
+ </includes>
+ <excludes>
+ <exclude>org.apache.tuscany.sca.runtime.standalone:standalone-api</exclude>
+ <exclude>org.apache.tuscany.sca.runtime.services.management:management-jmx</exclude>
+ <exclude>javax.servlet:servlet-api</exclude>
+ </excludes>
+ <outputDirectory>bin</outputDirectory>
+ <outputFileNameMapping>${artifactId}.${extension}</outputFileNameMapping>
+ <fileMode>755</fileMode>
+ </dependencySet>
+
+ <!-- copy dependencies used by the executable commands to the lib directory -->
+ <dependencySet>
+ <includes>
+ <include>org.apache.tuscany.sca.runtime.standalone:standalone-api</include>
+ <include>org.osoa:sca-api-r1.0</include>
+ <include>org.apache.tuscany.sca.kernel:tuscany-api</include>
+ <include>org.apache.tuscany.sca.kernel:tuscany-host-api</include>
+ <include>org.apache.tuscany.sca.runtime.services.management:management-jmx</include>
+ <include>org.apache.tuscany.sca.kernel:tuscany-spi</include>
+ <include>javax.servlet:servlet-api</include>
+ <include>org.codehaus.woodstox:wstx-asl</include>
+ </includes>
+ <excludes>
+ <exclude>junit:junit</exclude>
+ <exclude>org.easymock:easymock</exclude>
+ </excludes>
+ <outputDirectory>lib</outputDirectory>
+ <outputFileNameMapping>${artifactId}-${baseVersion}.${extension}</outputFileNameMapping>
+ </dependencySet>
+
+ <!-- copy boot dependencies to master profile -->
+ <dependencySet>
+ <includes>
+ <include>org.apache.tuscany.sca.runtime.standalone:standalone-host</include>
+ <include>org.apache.tuscany.sca.services:http-jetty</include>
+ <include>org.apache.tuscany:tuscany-sca-console</include>
+ <include>org.apache.tuscany.sca.runtime.services.discovery:discovery-jms</include>
+ <include>org.apache.tuscany.sca.core-samples.common:calculator</include>
+ <include>org.apache.tuscany.distribution.sca:demo-app</include>
+ </includes>
+ <excludes>
+ <exclude>junit:junit</exclude>
+ <exclude>org.easymock:easymock</exclude>
+ <exclude>javax.servlet:servlet-api</exclude>
+ </excludes>
+ <outputDirectory>profiles/master/boot</outputDirectory>
+ </dependencySet>
+
+ <!-- copy boot dependencies to slave1 profile -->
+ <dependencySet>
+ <includes>
+ <include>org.apache.tuscany.sca.runtime.standalone:standalone-host</include>
+ <include>org.apache.tuscany.sca.services:http-jetty</include>
+ <include>org.apache.tuscany.sca.runtime.services.discovery:discovery-jms</include>
+ <include>org.apache.tuscany.sca.core-samples.common:calculator</include>
+ <include>org.apache.tuscany.distribution.sca:demo-app</include>
+ </includes>
+ <excludes>
+ <exclude>junit:junit</exclude>
+ <exclude>org.easymock:easymock</exclude>
+ <exclude>javax.servlet:servlet-api</exclude>
+ </excludes>
+ <outputDirectory>profiles/slave1/boot</outputDirectory>
+ </dependencySet>
+
+ <!-- copy boot dependencies to slave2 profile -->
+ <dependencySet>
+ <includes>
+ <include>org.apache.tuscany.sca.runtime.standalone:standalone-host</include>
+ <include>org.apache.tuscany.sca.services:http-jetty</include>
+ <include>org.apache.tuscany.sca.runtime.services.discovery:discovery-jms</include>
+ <include>org.apache.tuscany.sca.core-samples.common:calculator</include>
+ <include>org.apache.tuscany.distribution.sca:demo-app</include>
+ </includes>
+ <excludes>
+ <exclude>junit:junit</exclude>
+ <exclude>org.easymock:easymock</exclude>
+ <exclude>javax.servlet:servlet-api</exclude>
+ </excludes>
+ <outputDirectory>profiles/slave2/boot</outputDirectory>
+ </dependencySet>
+ </dependencySets>
+
+</assembly>
+
diff --git a/tags/java/tsss-demo/demo/pom.xml b/tags/java/tsss-demo/demo/pom.xml
new file mode 100644
index 0000000000..489438b559
--- /dev/null
+++ b/tags/java/tsss-demo/demo/pom.xml
@@ -0,0 +1,110 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany</groupId>
+ <artifactId>sca</artifactId>
+ <version>1.0-incubating</version>
+ </parent>
+ <artifactId>demo</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ <packaging>pom</packaging>
+ <name>Tuscany Standalone Distribution</name>
+ <description>Tuscany Distribution for a standalone runtime environment.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.runtime.standalone</groupId>
+ <artifactId>server.start</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.runtime.services.discovery</groupId>
+ <artifactId>discovery-jms</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.runtime.standalone</groupId>
+ <artifactId>standalone-host</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.services</groupId>
+ <artifactId>http-jetty</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-spi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany</groupId>
+ <artifactId>tuscany-sca-console</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ <version>3.2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.core-samples.common</groupId>
+ <artifactId>calculator</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.distribution.sca</groupId>
+ <artifactId>demo-app</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.2-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <descriptors>
+ <descriptor>demo.xml</descriptor>
+ </descriptors>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tags/java/tsss-demo/demo/src/main/profiles/master/etc/runtime.properties b/tags/java/tsss-demo/demo/src/main/profiles/master/etc/runtime.properties
new file mode 100644
index 0000000000..cd1e824731
--- /dev/null
+++ b/tags/java/tsss-demo/demo/src/main/profiles/master/etc/runtime.properties
@@ -0,0 +1 @@
+domain=federation-demo \ No newline at end of file
diff --git a/tags/java/tsss-demo/demo/src/main/profiles/master/system.scdl b/tags/java/tsss-demo/demo/src/main/profiles/master/system.scdl
new file mode 100644
index 0000000000..88d3d0a6b2
--- /dev/null
+++ b/tags/java/tsss-demo/demo/src/main/profiles/master/system.scdl
@@ -0,0 +1,368 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+-->
+<!--
+Default system configuration for the launcher environment.
+
+$Rev$ $Date$
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ name="org.apache.tuscany.launcher.System" autowire="true">
+
+ <!-- Work manager -->
+ <component name="workManager">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.work.jsr237.workmanager.ThreadPoolWorkManager"/>
+ <property name="poolSize">10</property>
+ </component>
+
+ <component name="workScheduler">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler"/>
+ </component>
+ <!-- Generator Registry -->
+ <component name="generatorRegistry">
+ <system:implementation.system
+ class="org.apache.tuscany.core.generator.GeneratorRegistryImpl"/>
+ </component>
+
+ <component name="javaGenerator">
+ <system:implementation.system
+ class="org.apache.tuscany.core.implementation.java.JavaPhysicalComponentGenerator"/>
+ </component>
+
+
+ <!-- JXTA network configurator -->
+ <!-- component name="networkConfigurator">
+ <system:implementation.system
+ class="net.jxta.platform.NetworkConfigurator"/>
+ <property name="principal">principal</property>
+ <property name="password">password</property>
+ </component-->
+
+ <!-- Discovery service -->
+ <!--component name="discoveryService">
+ <system:implementation.system
+ class="org.apache.tuscany.service.discovery.jxta.JxtaDiscoveryService"/>
+ <property name="interval">5000</property>
+ <reference name="configurator" target="networkConfigurator"/>
+ <reference name="workScheduler" target="workScheduler"/>
+ </component-->
+
+ <!-- JMS discovery service -->
+ <component name="discoveryService">
+ <system:implementation.system
+ class="org.apache.tuscany.service.discovery.jms.JmsDiscoveryService"/>
+ <property name="topic">tuscany.federation</property>
+ </component>
+
+ <!-- Marshaller registry -->
+ <component name="marshallerRegistry">
+ <system:implementation.system
+ class="org.apache.tuscany.core.marshaller.DefaultModelMarshallerRegistry"/>
+ </component>
+
+ <!-- Changeset marshaller -->
+ <component name="changeSetMarshaller">
+ <system:implementation.system
+ class="org.apache.tuscany.core.marshaller.PhysicalChangeSetMarshaller"/>
+ </component>
+
+ <!-- Wide definition marshaller -->
+ <component name="wireDefinitionMarshaller">
+ <system:implementation.system
+ class="org.apache.tuscany.core.marshaller.PhysicalWireDefinitionMarshaller"/>
+ </component>
+
+ <!-- Operation definition marshaller -->
+ <component name="operationMarshaller">
+ <system:implementation.system
+ class="org.apache.tuscany.core.marshaller.PhysicalOperationDefinitionMarshaller"/>
+ </component>
+
+ <!-- Java component definition marshaller -->
+ <component name="javaComponentDefinitionMarshaller">
+ <system:implementation.system
+ class="org.apache.tuscany.core.marshaller.extensions.java.JavaPhysicalComponentDefinitionMarshaller"/>
+ </component>
+
+ <!-- Reflective IF provider definition marshaller -->
+ <component name="reflectiveIfProviderDefinitionMarshaller">
+ <system:implementation.system
+ class="org.apache.tuscany.core.marshaller.extensions.instancefactory.ReflectiveIFProviderDefinitionMarshaller"/>
+ </component>
+
+ <!-- Java physical wire source definition marshaller -->
+ <component name="javaWireSourceDefinitionMarshaller">
+ <system:implementation.system
+ class="org.apache.tuscany.core.marshaller.extensions.java.JavaPhysicalWireSourceDefinitionMarshaller"/>
+ </component>
+
+ <!-- Java physical wire target definition marshaller -->
+ <component name="javaWireTargetDefinitionMarshaller">
+ <system:implementation.system
+ class="org.apache.tuscany.core.marshaller.extensions.java.JavaPhysicalWireTargetDefinitionMarshaller"/>
+ </component>
+
+ <!-- Builder registry -->
+ <component name="builderRegistry">
+ <system:implementation.system
+ class="org.apache.tuscany.core.builder.physical.DefaultPhysicalComponentBuilderRegistry"/>
+ </component>
+ <component name="wireAttacherRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.builder.physical.WireAttacherRegistryImpl"/>
+ </component>
+ <component name="providerBuilderRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.component.instancefactory.impl.DefaultIFProviderBuilderRegistry"/>
+ </component>
+
+ <component name="reflectiveIFProviderBuilder">
+ <system:implementation.system class="org.apache.tuscany.core.component.instancefactory.impl.ReflectiveIFProviderBuilder"/>
+ </component>
+
+ <!-- Java physical component builder -->
+ <component name="javaPhysicalComponentBuilder">
+ <system:implementation.system
+ class="org.apache.tuscany.core.implementation.java.JavaPhysicalComponentBuilder"/>
+ </component>
+
+ <!-- Federated deployer -->
+ <component name="federateDeployer">
+ <system:implementation.system
+ class="org.apache.tuscany.core.deployer.federation.FederatedDeployer"/>
+ </component>
+
+ <!-- Jetty HTTP service -->
+ <component name="httpService">
+ <system:implementation.system
+ class="org.apache.tuscany.service.jetty.JettyServiceImpl"/>
+ <property name="httpPort">7000</property>
+ </component>
+
+ <!-- Console -->
+ <include name="org.apache.tuscany.sca.console"
+ scdlResource="org/apache/tuscany/console/console.scdl"/>
+
+ <!-- Assembly service -->
+ <component name="assemblyService">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.deployment.AssemblyServiceImpl"/>
+ </component>
+
+
+ <!--_________________________________________________________________________________________-->
+
+ <!--__________________________Legacy from launcher SCDL _____________________________________-->
+
+ <!--_________________________________________________________________________________________-->
+
+ <!-- Component that provides the Deployer service -->
+ <component name="deployer">
+ <system:implementation.system
+ class="org.apache.tuscany.core.deployer.DeployerImpl"/>
+ </component>
+
+ <!-- Work management -->
+ <component name="WorkContext">
+ <system:implementation.system
+ class="org.apache.tuscany.core.component.WorkContextImpl"/>
+ </component>
+
+ <!-- Wire service -->
+ <component name="proxyService">
+ <system:implementation.system
+ class="org.apache.tuscany.core.wire.jdk.JDKProxyService"/>
+ </component>
+
+ <!-- Store infrastructure -->
+ <component name="store">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.store.memory.MemoryStore"/>
+ </component>
+
+ <!-- Builder and BuilderRegistry -->
+ <component name="builder">
+ <system:implementation.system
+ class="org.apache.tuscany.core.builder.BuilderRegistryImpl"/>
+ </component>
+
+ <!-- Resource host registry -->
+ <component name="resourceHostRegistry">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.host.DelegatingResourceHostRegistry"/>
+ </component>
+
+ <!-- Loader and LoaderRegistry -->
+ <component name="loader">
+ <system:implementation.system
+ class="org.apache.tuscany.core.loader.LoaderRegistryImpl"/>
+ </component>
+
+ <!-- Introspector and IntrospectionRegistry -->
+ <component name="interfaceProcessorRegistry">
+ <system:implementation.system
+ class="org.apache.tuscany.core.implementation.IntrospectionRegistryImpl"/>
+ </component>
+
+ <!-- Connector infrastructure -->
+ <component name="connector">
+ <system:implementation.system
+ class="org.apache.tuscany.core.builder.ConnectorImpl"/>
+ </component>
+
+ <component name="wirePostProcessorRegistry">
+ <system:implementation.system
+ class="org.apache.tuscany.core.builder.WirePostProcessorRegistryImpl"/>
+ </component>
+
+ <!-- Default scopes -->
+ <component name="scope.stateless">
+ <system:implementation.system
+ class="org.apache.tuscany.core.component.scope.StatelessScopeContainer"/>
+ </component>
+ <!--
+ <component name="scope.request">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.RequestScopeContainer"/>
+ </component>
+ -->
+ <!--
+ <component name="scope.conversational">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.ConversationalScopeContainer"/>
+ </component>
+ -->
+
+ <!-- include loader configuration -->
+ <include name="org.apache.tuscany.core.Loader"
+ scdlResource="org/apache/tuscany/core/loader.scdl"/>
+
+ <!-- include databinding configuration -->
+ <include name="org.apache.tuscany.core.DataBinding"
+ scdlResource="org/apache/tuscany/core/databinding.scdl"/>
+
+ <!-- include implementation processor configuration -->
+ <include name="org.apache.tuscany.core.Implementation"
+ scdlResource="org/apache/tuscany/core/implementation.scdl"/>
+
+ <!-- Java interface definition language -->
+ <include name="org.apache.tuscany.core.InterfaceJava"
+ scdlResource="org/apache/tuscany/core/interfaceJava.scdl"/>
+
+ <!-- include omposite implementation type -->
+ <include name="org.apache.tuscany.core.Composite"
+ scdlResource="org/apache/tuscany/core/composite.scdl"/>
+
+ <!-- System implementation type -->
+ <include name="org.apache.tuscany.core.SystemImplementation"
+ scdlResource="org/apache/tuscany/core/systemImplementation.scdl"/>
+
+ <!-- Java implementation type -->
+ <include name="org.apache.tuscany.core.JavaImplementation"
+ scdlResource="org/apache/tuscany/core/javaImplementation.scdl"/>
+
+ <!-- service for resolving artifacts using Maven repositories -->
+ <component name="artifactRepository">
+ <system:implementation.system
+ class="org.apache.tuscany.services.maven.MavenArtifactRepository"/>
+ <property name="remoteRepoUrl">
+ http://repo1.maven.org/maven2/,http://people.apache.org/repo/m2-snapshot-repository,http://people.apache.org/repo/m2-incubating-repository/,http://people.apache.org/repo/m1-snapshot-repository/</property>
+ </component>
+
+ <!-- WorkScheduler service -->
+ <component name="workManager">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.work.jsr237.workmanager.ThreadPoolWorkManager"/>
+ <property name="poolSize">10</property>
+ </component>
+
+ <component name="workSchCompositeContextImplTestCaseeduler">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler"/>
+ </component>
+
+ <component name="policyBuilderRegistry">
+ <system:implementation.system
+ class="org.apache.tuscany.core.policy.PolicyBuilderRegistryImpl"/>
+ </component>
+
+ <component name="propertyFactory">
+ <system:implementation.system
+ class="org.apache.tuscany.core.property.PropertyObjectFactoryImpl"/>
+ </component>
+
+ <!-- component that scans the extension directory -->
+ <component name="directoryScanExtender" initLevel="90">
+ <system:implementation.system
+ class="org.apache.tuscany.runtime.standalone.host.DirectoryScanExtender"/>
+ <property name="path">extensions</property>
+ </component>
+
+ <!-- the local binding -->
+ <component name="localBindingLoader">
+ <system:implementation.system
+ class="org.apache.tuscany.core.binding.local.LocalBindingLoader"/>
+ </component>
+
+ <component name="localBindingBuilder">
+ <system:implementation.system
+ class="org.apache.tuscany.core.binding.local.LocalBindingBuilder"/>
+ </component>
+
+ <component name="artifactRepository">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.artifact.LocalMavenRepository"/>
+ <property name="repository">.m2/repository</property>
+ </component>
+
+ <component name="launchedLoader">
+ <system:implementation.system
+ class="org.apache.tuscany.runtime.standalone.host.implementation.launched.LaunchedLoader"/>
+ </component>
+
+ <component name="launchedComponentLoader">
+ <system:implementation.system
+ class="org.apache.tuscany.runtime.standalone.host.implementation.launched.LaunchedComponentTypeLoader"/>
+ </component>
+
+ <component name="launchedComponentBuilder">
+ <system:implementation.system
+ class="org.apache.tuscany.runtime.standalone.host.implementation.launched.LaunchedComponentBuilder"/>
+ </component>
+
+ <component name="wiringExceptionFormatter">
+ <system:implementation.system
+ class="org.apache.tuscany.core.builder.WiringExceptionFormatter"/>
+ </component>
+
+ <component name="wiringExceptionFormatter">
+ <system:implementation.system
+ class="org.apache.tuscany.core.builder.WiringExceptionFormatter"/>
+ </component>
+
+ <component name="loaderExceptionFormatter">
+ <system:implementation.system
+ class="org.apache.tuscany.core.loader.LoaderExceptionFormatter"/>
+ </component>
+
+ <component name="incompatibleServiceContractExceptionFormatter">
+ <system:implementation.system
+ class="org.apache.tuscany.core.wire.IncompatibleServiceContractExceptionFormatter"/>
+ </component>
+
+</composite> \ No newline at end of file
diff --git a/tags/java/tsss-demo/demo/src/main/profiles/slave1/etc/runtime.properties b/tags/java/tsss-demo/demo/src/main/profiles/slave1/etc/runtime.properties
new file mode 100644
index 0000000000..cd1e824731
--- /dev/null
+++ b/tags/java/tsss-demo/demo/src/main/profiles/slave1/etc/runtime.properties
@@ -0,0 +1 @@
+domain=federation-demo \ No newline at end of file
diff --git a/tags/java/tsss-demo/demo/src/main/profiles/slave1/system.scdl b/tags/java/tsss-demo/demo/src/main/profiles/slave1/system.scdl
new file mode 100644
index 0000000000..2a6a684e87
--- /dev/null
+++ b/tags/java/tsss-demo/demo/src/main/profiles/slave1/system.scdl
@@ -0,0 +1,337 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+-->
+<!--
+Default system configuration for the launcher environment.
+
+$Rev$ $Date$
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ name="org.apache.tuscany.launcher.System" autowire="true">
+
+ <!-- Work manager -->
+ <component name="workManager">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.work.jsr237.workmanager.ThreadPoolWorkManager"/>
+ <property name="poolSize">10</property>
+ </component>
+
+ <component name="workScheduler">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler"/>
+ </component>
+
+ <!-- JXTA network configurator -->
+ <!-- component name="networkConfigurator">
+ <system:implementation.system
+ class="net.jxta.platform.NetworkConfigurator"/>
+ <property name="principal">principal</property>
+ <property name="password">password</property>
+ </component-->
+
+ <!-- Discovery service -->
+ <!--component name="discoveryService">
+ <system:implementation.system
+ class="org.apache.tuscany.service.discovery.jxta.JxtaDiscoveryService"/>
+ <property name="interval">5000</property>
+ <reference name="configurator" target="networkConfigurator"/>
+ <reference name="workScheduler" target="workScheduler"/>
+ </component-->
+
+ <!-- JMS discovery service -->
+ <component name="discoveryService">
+ <system:implementation.system
+ class="org.apache.tuscany.service.discovery.jms.JmsDiscoveryService"/>
+ <property name="topic">tuscany.federation</property>
+ </component>
+
+ <!-- Marshaller registry -->
+ <component name="marshallerRegistry">
+ <system:implementation.system
+ class="org.apache.tuscany.core.marshaller.DefaultModelMarshallerRegistry"/>
+ </component>
+
+ <!-- Changeset marshaller -->
+ <component name="changeSetMarshaller">
+ <system:implementation.system class="org.apache.tuscany.core.marshaller.PhysicalChangeSetMarshaller"/>
+ </component>
+
+ <!-- Wide definition marshaller -->
+ <component name="wireDefinitionMarshaller">
+ <system:implementation.system class="org.apache.tuscany.core.marshaller.PhysicalWireDefinitionMarshaller"/>
+ </component>
+
+ <!-- Operation definition marshaller -->
+ <component name="operationMarshaller">
+ <system:implementation.system class="org.apache.tuscany.core.marshaller.PhysicalOperationDefinitionMarshaller"/>
+ </component>
+
+ <!-- Java component definition marshaller -->
+ <component name="javaComponentDefinitionMarshaller">
+ <system:implementation.system class="org.apache.tuscany.core.marshaller.extensions.java.JavaPhysicalComponentDefinitionMarshaller"/>
+ </component>
+
+ <!-- Reflective IF provider definition marshaller -->
+ <component name="reflectiveIfProviderDefinitionMarshaller">
+ <system:implementation.system class="org.apache.tuscany.core.marshaller.extensions.instancefactory.ReflectiveIFProviderDefinitionMarshaller"/>
+ </component>
+
+ <!-- Java physical wire source definition marshaller -->
+ <component name="javaWireSourceDefinitionMarshaller">
+ <system:implementation.system class="org.apache.tuscany.core.marshaller.extensions.java.JavaPhysicalWireSourceDefinitionMarshaller"/>
+ </component>
+
+ <!-- Java physical wire target definition marshaller -->
+ <component name="javaWireTargetDefinitionMarshaller">
+ <system:implementation.system class="org.apache.tuscany.core.marshaller.extensions.java.JavaPhysicalWireTargetDefinitionMarshaller"/>
+ </component>
+
+ <!-- Builder registry -->
+ <component name="builderRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.builder.physical.DefaultPhysicalComponentBuilderRegistry"/>
+ </component>
+ <component name="wireAttacherRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.builder.physical.WireAttacherRegistryImpl"/>
+ </component>
+ <component name="providerBuilderRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.component.instancefactory.impl.DefaultIFProviderBuilderRegistry"/>
+ </component>
+
+ <component name="reflectiveIFProviderBuilder">
+ <system:implementation.system class="org.apache.tuscany.core.component.instancefactory.impl.ReflectiveIFProviderBuilder"/>
+ </component>
+
+ <!-- Java physical component builder -->
+ <component name="javaPhysicalComponentBuilder">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.java.JavaPhysicalComponentBuilder"/>
+ </component>
+
+ <!-- Federated deployer -->
+ <component name="federateDeployer">
+ <system:implementation.system class="org.apache.tuscany.core.deployer.federation.FederatedDeployer"/>
+ </component>
+
+ <!-- Jetty HTTP service -->
+ <component name="httpService">
+ <system:implementation.system
+ class="org.apache.tuscany.service.jetty.JettyServiceImpl"/>
+ <property name="httpPort">8000</property>
+ </component>
+
+ <!-- Calculator form servlet -->
+ <component runtimeId="slave1" name="calculatorForm">
+ <system:implementation.system class="org.apache.tuscany.demo.app.CalculatorForm"/>
+ <reference name="servletHost" target="httpService"/>
+ </component>
+
+ <!-- Servlet that handles the scdl submission -->
+ <component runtimeId="slave1" name="calculatorHandler">
+ <system:implementation.system class="org.apache.tuscany.demo.app.CalculatorHandler"/>
+ <reference name="servletHost" target="httpService"/>
+ </component>
+
+
+
+ <!--_________________________________________________________________________________________-->
+
+ <!--__________________________Legacy from launcher SCDL _____________________________________-->
+
+ <!--_________________________________________________________________________________________-->
+
+ <!-- Component that provides the Deployer service -->
+ <component name="deployer">
+ <system:implementation.system class="org.apache.tuscany.core.deployer.DeployerImpl"/>
+ </component>
+
+ <!-- Work management -->
+ <component name="WorkContext">
+ <system:implementation.system class="org.apache.tuscany.core.component.WorkContextImpl"/>
+ </component>
+
+ <!-- Wire service -->
+ <component name="proxyService">
+ <system:implementation.system class="org.apache.tuscany.core.wire.jdk.JDKProxyService"/>
+ </component>
+
+ <!-- Store infrastructure -->
+ <component name="store">
+ <system:implementation.system class="org.apache.tuscany.core.services.store.memory.MemoryStore"/>
+ </component>
+
+ <!-- Builder and BuilderRegistry -->
+ <component name="builder">
+ <system:implementation.system class="org.apache.tuscany.core.builder.BuilderRegistryImpl"/>
+ </component>
+
+ <!-- Resource host registry -->
+ <component name="resourceHostRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.services.host.DelegatingResourceHostRegistry"/>
+ </component>
+
+ <!-- Loader and LoaderRegistry -->
+ <component name="loader">
+ <system:implementation.system class="org.apache.tuscany.core.loader.LoaderRegistryImpl"/>
+ </component>
+
+ <!-- Introspector and IntrospectionRegistry -->
+ <component name="interfaceProcessorRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.IntrospectionRegistryImpl"/>
+ </component>
+
+ <!-- Connector infrastructure -->
+ <component name="connector">
+ <system:implementation.system class="org.apache.tuscany.core.builder.ConnectorImpl"/>
+ </component>
+
+ <component name="wirePostProcessorRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.builder.WirePostProcessorRegistryImpl"/>
+ </component>
+
+ <!-- Default scopes -->
+ <component name="scope.stateless">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.StatelessScopeContainer"/>
+ </component>
+ <!--
+ <component name="scope.request">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.RequestScopeContainer"/>
+ </component>
+ -->
+ <!--
+ <component name="scope.conversational">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.ConversationalScopeContainer"/>
+ </component>
+ -->
+
+ <!-- include loader configuration -->
+ <include name="org.apache.tuscany.core.Loader" scdlResource="org/apache/tuscany/core/loader.scdl"/>
+
+ <!-- include databinding configuration -->
+ <include name="org.apache.tuscany.core.DataBinding" scdlResource="org/apache/tuscany/core/databinding.scdl"/>
+
+ <!-- include implementation processor configuration -->
+ <include name="org.apache.tuscany.core.Implementation"
+ scdlResource="org/apache/tuscany/core/implementation.scdl"/>
+
+ <!-- Java interface definition language -->
+ <include name="org.apache.tuscany.core.InterfaceJava"
+ scdlResource="org/apache/tuscany/core/interfaceJava.scdl"/>
+
+ <!-- include omposite implementation type -->
+ <include name="org.apache.tuscany.core.Composite"
+ scdlResource="org/apache/tuscany/core/composite.scdl"/>
+
+ <!-- System implementation type -->
+ <include name="org.apache.tuscany.core.SystemImplementation"
+ scdlResource="org/apache/tuscany/core/systemImplementation.scdl"/>
+
+ <!-- Java implementation type -->
+ <include name="org.apache.tuscany.core.JavaImplementation"
+ scdlResource="org/apache/tuscany/core/javaImplementation.scdl"/>
+
+ <!-- service for resolving artifacts using Maven repositories -->
+ <component name="artifactRepository">
+ <system:implementation.system
+ class="org.apache.tuscany.services.maven.MavenArtifactRepository"/>
+ <property name="remoteRepoUrl">
+ http://repo1.maven.org/maven2/,http://people.apache.org/repo/m2-snapshot-repository,http://people.apache.org/repo/m2-incubating-repository/,http://people.apache.org/repo/m1-snapshot-repository/</property>
+ </component>
+
+ <!-- WorkScheduler service -->
+ <component name="workManager">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.work.jsr237.workmanager.ThreadPoolWorkManager"/>
+ <property name="poolSize">10</property>
+ </component>
+
+ <component name="workSchCompositeContextImplTestCaseeduler">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler"/>
+ </component>
+
+ <component name="policyBuilderRegistry">
+ <system:implementation.system
+ class="org.apache.tuscany.core.policy.PolicyBuilderRegistryImpl"/>
+ </component>
+
+ <component name="propertyFactory">
+ <system:implementation.system
+ class="org.apache.tuscany.core.property.PropertyObjectFactoryImpl"/>
+ </component>
+
+ <!-- component that scans the extension directory -->
+ <component name="directoryScanExtender" initLevel="90">
+ <system:implementation.system
+ class="org.apache.tuscany.runtime.standalone.host.DirectoryScanExtender"/>
+ <property name="path">extensions</property>
+ </component>
+
+ <!-- the local binding -->
+ <component name="localBindingLoader">
+ <system:implementation.system
+ class="org.apache.tuscany.core.binding.local.LocalBindingLoader"/>
+ </component>
+
+ <component name="localBindingBuilder">
+ <system:implementation.system
+ class="org.apache.tuscany.core.binding.local.LocalBindingBuilder"/>
+ </component>
+
+ <component name="artifactRepository">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.artifact.LocalMavenRepository"/>
+ <property name="repository">.m2/repository</property>
+ </component>
+
+ <component name="launchedLoader">
+ <system:implementation.system
+ class="org.apache.tuscany.runtime.standalone.host.implementation.launched.LaunchedLoader"/>
+ </component>
+
+ <component name="launchedComponentLoader">
+ <system:implementation.system
+ class="org.apache.tuscany.runtime.standalone.host.implementation.launched.LaunchedComponentTypeLoader"/>
+ </component>
+
+ <component name="launchedComponentBuilder">
+ <system:implementation.system
+ class="org.apache.tuscany.runtime.standalone.host.implementation.launched.LaunchedComponentBuilder"/>
+ </component>
+
+ <component name="wiringExceptionFormatter">
+ <system:implementation.system
+ class="org.apache.tuscany.core.builder.WiringExceptionFormatter"/>
+ </component>
+
+ <component name="wiringExceptionFormatter">
+ <system:implementation.system
+ class="org.apache.tuscany.core.builder.WiringExceptionFormatter"/>
+ </component>
+
+ <component name="loaderExceptionFormatter">
+ <system:implementation.system
+ class="org.apache.tuscany.core.loader.LoaderExceptionFormatter"/>
+ </component>
+
+ <component name="incompatibleServiceContractExceptionFormatter">
+ <system:implementation.system
+ class="org.apache.tuscany.core.wire.IncompatibleServiceContractExceptionFormatter"/>
+ </component>
+
+</composite> \ No newline at end of file
diff --git a/tags/java/tsss-demo/demo/src/main/profiles/slave2/etc/runtime.properties b/tags/java/tsss-demo/demo/src/main/profiles/slave2/etc/runtime.properties
new file mode 100644
index 0000000000..cd1e824731
--- /dev/null
+++ b/tags/java/tsss-demo/demo/src/main/profiles/slave2/etc/runtime.properties
@@ -0,0 +1 @@
+domain=federation-demo \ No newline at end of file
diff --git a/tags/java/tsss-demo/demo/src/main/profiles/slave2/system.scdl b/tags/java/tsss-demo/demo/src/main/profiles/slave2/system.scdl
new file mode 100644
index 0000000000..302146ca91
--- /dev/null
+++ b/tags/java/tsss-demo/demo/src/main/profiles/slave2/system.scdl
@@ -0,0 +1,340 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+-->
+<!--
+Default system configuration for the launcher environment.
+
+$Rev$ $Date$
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ name="org.apache.tuscany.launcher.System" autowire="true">
+
+ <!-- Work manager -->
+ <component name="workManager">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.work.jsr237.workmanager.ThreadPoolWorkManager"/>
+ <property name="poolSize">10</property>
+ </component>
+
+ <component name="workScheduler">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler"/>
+ </component>
+
+ <!-- JXTA network configurator -->
+ <!-- component name="networkConfigurator">
+ <system:implementation.system
+ class="net.jxta.platform.NetworkConfigurator"/>
+ <property name="principal">principal</property>
+ <property name="password">password</property>
+ </component-->
+
+ <!-- Discovery service -->
+ <!--component name="discoveryService">
+ <system:implementation.system
+ class="org.apache.tuscany.service.discovery.jxta.JxtaDiscoveryService"/>
+ <property name="interval">5000</property>
+ <reference name="configurator" target="networkConfigurator"/>
+ <reference name="workScheduler" target="workScheduler"/>
+ </component-->
+
+ <!-- JMS discovery service -->
+ <component name="discoveryService">
+ <system:implementation.system
+ class="org.apache.tuscany.service.discovery.jms.JmsDiscoveryService"/>
+ <property name="topic">tuscany.federation</property>
+ </component>
+
+ <!-- Marshaller registry -->
+ <component name="marshallerRegistry">
+ <system:implementation.system
+ class="org.apache.tuscany.core.marshaller.DefaultModelMarshallerRegistry"/>
+ </component>
+
+ <!-- Changeset marshaller -->
+ <component name="changeSetMarshaller">
+ <system:implementation.system
+ class="org.apache.tuscany.core.marshaller.PhysicalChangeSetMarshaller"/>
+ </component>
+
+ <!-- Wide definition marshaller -->
+ <component name="wireDefinitionMarshaller">
+ <system:implementation.system
+ class="org.apache.tuscany.core.marshaller.PhysicalWireDefinitionMarshaller"/>
+ </component>
+
+ <!-- Operation definition marshaller -->
+ <component name="operationMarshaller">
+ <system:implementation.system
+ class="org.apache.tuscany.core.marshaller.PhysicalOperationDefinitionMarshaller"/>
+ </component>
+
+ <!-- Java component definition marshaller -->
+ <component name="javaComponentDefinitionMarshaller">
+ <system:implementation.system
+ class="org.apache.tuscany.core.marshaller.extensions.java.JavaPhysicalComponentDefinitionMarshaller"/>
+ </component>
+
+ <!-- Reflective IF provider definition marshaller -->
+ <component name="reflectiveIfProviderDefinitionMarshaller">
+ <system:implementation.system
+ class="org.apache.tuscany.core.marshaller.extensions.instancefactory.ReflectiveIFProviderDefinitionMarshaller"/>
+ </component>
+
+ <!-- Java physical wire source definition marshaller -->
+ <component name="javaWireSourceDefinitionMarshaller">
+ <system:implementation.system
+ class="org.apache.tuscany.core.marshaller.extensions.java.JavaPhysicalWireSourceDefinitionMarshaller"/>
+ </component>
+
+ <!-- Java physical wire target definition marshaller -->
+ <component name="javaWireTargetDefinitionMarshaller">
+ <system:implementation.system
+ class="org.apache.tuscany.core.marshaller.extensions.java.JavaPhysicalWireTargetDefinitionMarshaller"/>
+ </component>
+
+ <!-- Builder registry -->
+ <component name="builderRegistry">
+ <system:implementation.system
+ class="org.apache.tuscany.core.builder.physical.DefaultPhysicalComponentBuilderRegistry"/>
+ </component>
+ <component name="wireAttacherRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.builder.physical.WireAttacherRegistryImpl"/>
+ </component>
+ <component name="providerBuilderRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.component.instancefactory.impl.DefaultIFProviderBuilderRegistry"/>
+ </component>
+
+ <component name="reflectiveIFProviderBuilder">
+ <system:implementation.system class="org.apache.tuscany.core.component.instancefactory.impl.ReflectiveIFProviderBuilder"/>
+ </component>
+
+ <!-- Java physical component builder -->
+ <component name="javaPhysicalComponentBuilder">
+ <system:implementation.system
+ class="org.apache.tuscany.core.implementation.java.JavaPhysicalComponentBuilder"/>
+ </component>
+
+ <!-- Federated deployer -->
+ <component name="federateDeployer">
+ <system:implementation.system
+ class="org.apache.tuscany.core.deployer.federation.FederatedDeployer"/>
+ </component>
+
+
+ <!--_________________________________________________________________________________________-->
+
+ <!--__________________________Legacy from launcher SCDL _____________________________________-->
+
+ <!--_________________________________________________________________________________________-->
+
+ <!-- Component that provides the Deployer service -->
+ <component name="deployer">
+ <system:implementation.system
+ class="org.apache.tuscany.core.deployer.DeployerImpl"/>
+ </component>
+
+ <!-- Work management -->
+ <component name="WorkContext">
+ <system:implementation.system
+ class="org.apache.tuscany.core.component.WorkContextImpl"/>
+ </component>
+
+ <!-- Wire service -->
+ <component name="proxyService">
+ <system:implementation.system
+ class="org.apache.tuscany.core.wire.jdk.JDKProxyService"/>
+ </component>
+
+ <!-- Store infrastructure -->
+ <component name="store">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.store.memory.MemoryStore"/>
+ </component>
+
+ <!-- Builder and BuilderRegistry -->
+ <component name="builder">
+ <system:implementation.system
+ class="org.apache.tuscany.core.builder.BuilderRegistryImpl"/>
+ </component>
+
+ <!-- Resource host registry -->
+ <component name="resourceHostRegistry">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.host.DelegatingResourceHostRegistry"/>
+ </component>
+
+ <!-- Loader and LoaderRegistry -->
+ <component name="loader">
+ <system:implementation.system
+ class="org.apache.tuscany.core.loader.LoaderRegistryImpl"/>
+ </component>
+
+ <!-- Introspector and IntrospectionRegistry -->
+ <component name="interfaceProcessorRegistry">
+ <system:implementation.system
+ class="org.apache.tuscany.core.implementation.IntrospectionRegistryImpl"/>
+ </component>
+
+ <!-- Connector infrastructure -->
+ <component name="connector">
+ <system:implementation.system
+ class="org.apache.tuscany.core.builder.ConnectorImpl"/>
+ </component>
+
+ <component name="wirePostProcessorRegistry">
+ <system:implementation.system
+ class="org.apache.tuscany.core.builder.WirePostProcessorRegistryImpl"/>
+ </component>
+
+ <!-- Default scopes -->
+ <component name="scope.stateless">
+ <system:implementation.system
+ class="org.apache.tuscany.core.component.scope.StatelessScopeContainer"/>
+ </component>
+ <!--
+ <component name="scope.request">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.RequestScopeContainer"/>
+ </component>
+ -->
+ <!--
+ <component name="scope.conversational">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.ConversationalScopeContainer"/>
+ </component>
+ -->
+
+ <!-- include loader configuration -->
+ <include name="org.apache.tuscany.core.Loader"
+ scdlResource="org/apache/tuscany/core/loader.scdl"/>
+
+ <!-- include databinding configuration -->
+ <include name="org.apache.tuscany.core.DataBinding"
+ scdlResource="org/apache/tuscany/core/databinding.scdl"/>
+
+ <!-- include implementation processor configuration -->
+ <include name="org.apache.tuscany.core.Implementation"
+ scdlResource="org/apache/tuscany/core/implementation.scdl"/>
+
+ <!-- Java interface definition language -->
+ <include name="org.apache.tuscany.core.InterfaceJava"
+ scdlResource="org/apache/tuscany/core/interfaceJava.scdl"/>
+
+ <!-- include omposite implementation type -->
+ <include name="org.apache.tuscany.core.Composite"
+ scdlResource="org/apache/tuscany/core/composite.scdl"/>
+
+ <!-- System implementation type -->
+ <include name="org.apache.tuscany.core.SystemImplementation"
+ scdlResource="org/apache/tuscany/core/systemImplementation.scdl"/>
+
+ <!-- Java implementation type -->
+ <include name="org.apache.tuscany.core.JavaImplementation"
+ scdlResource="org/apache/tuscany/core/javaImplementation.scdl"/>
+
+ <!-- service for resolving artifacts using Maven repositories -->
+ <component name="artifactRepository">
+ <system:implementation.system
+ class="org.apache.tuscany.services.maven.MavenArtifactRepository"/>
+ <property name="remoteRepoUrl">
+ http://repo1.maven.org/maven2/,http://people.apache.org/repo/m2-snapshot-repository,http://people.apache.org/repo/m2-incubating-repository/,http://people.apache.org/repo/m1-snapshot-repository/</property>
+ </component>
+
+ <!-- WorkScheduler service -->
+ <component name="workManager">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.work.jsr237.workmanager.ThreadPoolWorkManager"/>
+ <property name="poolSize">10</property>
+ </component>
+
+ <component name="workSchCompositeContextImplTestCaseeduler">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler"/>
+ </component>
+
+ <component name="policyBuilderRegistry">
+ <system:implementation.system
+ class="org.apache.tuscany.core.policy.PolicyBuilderRegistryImpl"/>
+ </component>
+
+ <component name="propertyFactory">
+ <system:implementation.system
+ class="org.apache.tuscany.core.property.PropertyObjectFactoryImpl"/>
+ </component>
+
+ <!-- component that scans the extension directory -->
+ <component name="directoryScanExtender" initLevel="90">
+ <system:implementation.system
+ class="org.apache.tuscany.runtime.standalone.host.DirectoryScanExtender"/>
+ <property name="path">extensions</property>
+ </component>
+
+ <!-- the local binding -->
+ <component name="localBindingLoader">
+ <system:implementation.system
+ class="org.apache.tuscany.core.binding.local.LocalBindingLoader"/>
+ </component>
+
+ <component name="localBindingBuilder">
+ <system:implementation.system
+ class="org.apache.tuscany.core.binding.local.LocalBindingBuilder"/>
+ </component>
+
+ <component name="artifactRepository">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.artifact.LocalMavenRepository"/>
+ <property name="repository">.m2/repository</property>
+ </component>
+
+ <component name="launchedLoader">
+ <system:implementation.system
+ class="org.apache.tuscany.runtime.standalone.host.implementation.launched.LaunchedLoader"/>
+ </component>
+
+ <component name="launchedComponentLoader">
+ <system:implementation.system
+ class="org.apache.tuscany.runtime.standalone.host.implementation.launched.LaunchedComponentTypeLoader"/>
+ </component>
+
+ <component name="launchedComponentBuilder">
+ <system:implementation.system
+ class="org.apache.tuscany.runtime.standalone.host.implementation.launched.LaunchedComponentBuilder"/>
+ </component>
+
+ <component name="wiringExceptionFormatter">
+ <system:implementation.system
+ class="org.apache.tuscany.core.builder.WiringExceptionFormatter"/>
+ </component>
+
+ <component name="wiringExceptionFormatter">
+ <system:implementation.system
+ class="org.apache.tuscany.core.builder.WiringExceptionFormatter"/>
+ </component>
+
+ <component name="loaderExceptionFormatter">
+ <system:implementation.system
+ class="org.apache.tuscany.core.loader.LoaderExceptionFormatter"/>
+ </component>
+
+ <component name="incompatibleServiceContractExceptionFormatter">
+ <system:implementation.system
+ class="org.apache.tuscany.core.wire.IncompatibleServiceContractExceptionFormatter"/>
+ </component>
+
+</composite> \ No newline at end of file
diff --git a/tags/java/tsss-demo/http.jetty/.ruleset b/tags/java/tsss-demo/http.jetty/.ruleset
new file mode 100644
index 0000000000..3886f07f2d
--- /dev/null
+++ b/tags/java/tsss-demo/http.jetty/.ruleset
@@ -0,0 +1,190 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<ruleset name="pmd-eclipse">
+ <description>PMD Plugin preferences rule set</description>
+
+
+ <rule ref="rulesets/basic.xml/BooleanInstantiation"/>
+ <rule ref="rulesets/basic.xml/CollapsibleIfStatements"/>
+ <rule ref="rulesets/basic.xml/DoubleCheckedLocking"/>
+<!--<rule ref="rulesets/basic.xml/EmptyCatchBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyFinallyBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyIfStmt"/>-->
+ <rule ref="rulesets/basic.xml/EmptyStatementNotInLoop"/>
+<!--<rule ref="rulesets/basic.xml/EmptyStaticInitializer"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptySwitchStatements"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptySynchronizedBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyTryBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyWhileStmt"/>-->
+ <rule ref="rulesets/basic.xml/ForLoopShouldBeWhileLoop"/>
+ <rule ref="rulesets/basic.xml/JumbledIncrementer"/>
+<!--<rule ref="rulesets/basic.xml/OverrideBothEqualsAndHashcode"/>-->
+ <rule ref="rulesets/basic.xml/ReturnFromFinallyBlock"/>
+ <rule ref="rulesets/basic.xml/UnconditionalIfStatement"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryConversionTemporary"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryFinalModifier"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryReturn"/>
+<!--<rule ref="rulesets/basic.xml/UselessOverridingMethod"/>-->
+
+<!--<rule ref="rulesets/braces.xml/ForLoopsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/IfElseStmtsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/IfStmtsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/WhileLoopsMustUseBraces"/>-->
+
+<!--<rule ref="rulesets/clone.xml/CloneMethodMustImplementCloneable"/>-->
+<!--<rule ref="rulesets/clone.xml/CloneThrowsCloneNotSupportedException"/>-->
+<!--<rule ref="rulesets/clone.xml/ProperCloneImplementation"/>-->
+
+<!--<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>-->
+<!--<rule ref="rulesets/codesize.xml/TooManyFields"/>-->
+
+<rule ref="rulesets/controversial.xml/AssignmentInOperand"/>
+<!--<rule ref="rulesets/controversial.xml/AtLeastOneConstructor"/>-->
+<!--<rule ref="rulesets/controversial.xml/CallSuperInConstructor"/>-->
+<!--<rule ref="rulesets/controversial.xml/DontImportSun"/>-->
+<!--<rule ref="rulesets/controversial.xml/NullAssignment"/>-->
+<!--<rule ref="rulesets/controversial.xml/OnlyOneReturn"/>-->
+<!--<rule ref="rulesets/controversial.xml/SingularField"/>-->
+<!--<rule ref="rulesets/controversial.xml/SuspiciousOctalEscape"/>-->
+<!--<rule ref="rulesets/controversial.xml/UnnecessaryConstructor"/>-->
+<rule ref="rulesets/controversial.xml/UnnecessaryParentheses"/>
+<!--<rule ref="rulesets/controversial.xml/UnusedModifier"/>-->
+
+<!--<rule ref="rulesets/coupling.xml/CouplingBetweenObjects"/>-->
+<!--<rule ref="rulesets/coupling.xml/ExcessiveImports"/>-->
+<!--<rule ref="rulesets/coupling.xml/LooseCoupling"/>-->
+
+<!--<rule ref="rulesets/design.xml/AbstractClassWithoutAbstractMethod"/>-->
+<!--<rule ref="rulesets/design.xml/AccessorClassGeneration"/>-->
+<!--<rule ref="rulesets/design.xml/AssignmentToNonFinalStatic"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidDeeplyNestedIfStmts"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidInstanceofChecksInCatchClause"/>-->
+<rule ref="rulesets/design.xml/AvoidProtectedFieldInFinalClass"/>
+<!--<rule ref="rulesets/design.xml/AvoidReassigningParameters"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidSynchronizedAtMethodLevel"/>-->
+<!--<rule ref="rulesets/design.xml/BadComparison"/>-->
+<!--<rule ref="rulesets/design.xml/CloseConnection"/>-->
+<!--<rule ref="rulesets/design.xml/CompareObjectsWithEquals"/>-->
+<!--<rule ref="rulesets/design.xml/ConfusingTernary"/>-->
+<rule ref="rulesets/design.xml/ConstructorCallsOverridableMethod"/>
+<!--<rule ref="rulesets/design.xml/DefaultLabelNotLastInSwitchStmt"/>-->
+<!--<rule ref="rulesets/design.xml/FinalFieldCouldBeStatic"/>-->
+<rule ref="rulesets/design.xml/IdempotentOperations"/>
+<!--<rule ref="rulesets/design.xml/ImmutableField"/>-->
+<!--<rule ref="rulesets/design.xml/InstantiationToGetClass"/>-->
+<!--<rule ref="rulesets/design.xml/MissingBreakInSwitch"/>-->
+<!--<rule ref="rulesets/design.xml/MissingStaticMethodInNonInstantiatableClass"/>-->
+<!--<rule ref="rulesets/design.xml/NonCaseLabelInSwitchStatement"/>-->
+<!--<rule ref="rulesets/design.xml/NonStaticInitializer"/>-->
+<rule ref="rulesets/design.xml/OptimizableToArrayCall"/>
+<rule ref="rulesets/design.xml/PositionLiteralsFirstInComparisons"/>
+<rule ref="rulesets/design.xml/SimplifyBooleanExpressions"/>
+<rule ref="rulesets/design.xml/SimplifyBooleanReturns"/>
+<rule ref="rulesets/design.xml/SimplifyConditional"/>
+<!--<rule ref="rulesets/design.xml/SwitchDensity"/>-->
+<!--<rule ref="rulesets/design.xml/SwitchStmtsShouldHaveDefault"/>-->
+<rule ref="rulesets/design.xml/UnnecessaryLocalBeforeReturn"/>
+<!--<rule ref="rulesets/design.xml/UseLocaleWithCaseConversions"/>-->
+<!--<rule ref="rulesets/design.xml/UseNotifyAllInsteadOfNotify"/>-->
+<!--<rule ref="rulesets/design.xml/UseSingleton"/>-->
+
+<!--<rule ref="rulesets/finalizers.xml/EmptyFinalizer"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeOnlyCallsSuperFinalize"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeOverloaded"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeDoesNotCallSuperFinalize"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeShouldBeProtected"/>-->
+<!--<rule ref="rulesets/finalizers.xml/AvoidCallingFinalize"/>-->
+
+<!--<rule ref="rulesets/imports.xml/DuplicateImports"/>-->
+<!--<rule ref="rulesets/imports.xml/DontImportJavaLang"/>-->
+<!--<rule ref="rulesets/imports.xml/UnusedImports"/>-->
+<!--<rule ref="rulesets/imports.xml/ImportFromSamePackage"/>-->
+
+<!--<rule ref="rulesets/javabeans.xml/BeanMembersShouldSerialize"/>-->
+<!--<rule ref="rulesets/javabeans.xml/MissingSerialVersionUID"/>-->
+
+<!--<rule ref="rulesets/junit.xml/JUnitStaticSuite"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitSpelling"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitAssertionsShouldIncludeMessage"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitTestsShouldIncludeAssert"/>-->
+<!--<rule ref="rulesets/junit.xml/TestClassWithoutTestCases"/>-->
+<!--<rule ref="rulesets/junit.xml/UnnecessaryBooleanAssertion"/>-->
+<!--<rule ref="rulesets/junit.xml/UseAssertEqualsInsteadOfAssertTrue"/>-->
+<!--<rule ref="rulesets/junit.xml/UseAssertSameInsteadOfAssertTrue"/>-->
+
+ <!--<rule ref="rulesets/logging-java.xml/AvoidPrintStackTrace"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/MoreThanOneLogger"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LogBlockWithoutIf"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/SystemPrintln"/>-->
+ <!--<rule ref="rulesets/logging-jakarta-commons.xml/UseCorrectExceptionLogging"/>-->
+ <!--<rule ref="rulesets/logging-jakarta-commons.xml/ProperLogger"/>-->
+
+ <!--<rule ref="rulesets/naming.xml/ShortVariable"/>-->
+ <!--<rule ref="rulesets/naming.xml/LongVariable"/>-->
+ <!--<rule ref="rulesets/naming.xml/ShortMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/VariableNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/MethodNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/ClassNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/AbstractNaming"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidDollarSigns"/>-->
+ <!--<rule ref="rulesets/naming.xml/MethodWithSameNameAsEnclosingClass"/>-->
+ <!--<rule ref="rulesets/naming.xml/SuspiciousHashcodeMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/SuspiciousConstantFieldName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingTypeName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidNonConstructorMethodsWithClassName"/>-->
+ <!--<rule ref="rulesets/naming.xml/NoPackage"/>-->
+ <!--<rule ref="rulesets/naming.xml/PackageCase"/>-->
+
+ <!--<rule ref="rulesets/optimizations.xml/LocalVariableCouldBeFinal"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/MethodArgumentCouldBeFinal"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/AvoidInstantiatingObjectsInLoops"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/UseArrayListInsteadOfVector"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/SimplifyStartsWith"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/UseStringBufferForStringAppends"/>-->
+
+ <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingThrowable"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/SignatureDeclareThrowsException"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/ExceptionAsFlowControl"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingNPE"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingRawExceptionTypes"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingNullPointerException"/>-->
+
+ <!--<rule ref="rulesets/strings.xml/AvoidDuplicateLiterals"/>-->
+ <!--<rule ref="rulesets/strings.xml/StringInstantiation"/>-->
+ <!--<rule ref="rulesets/strings.xml/StringToString"/>-->
+ <!--<rule ref="rulesets/strings.xml/AvoidConcatenatingNonLiteralsInStringBuffer"/>-->
+ <!--<rule ref="rulesets/strings.xml/UnnecessaryCaseChange"/>-->
+
+ <!--<rule ref="rulesets/sunsecure.xml/MethodReturnsInternalArray"/>-->
+ <!--<rule ref="rulesets/sunsecure.xml/ArrayIsStoredDirectly"/>-->
+
+ <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/>
+ <rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/>
+ <rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/>
+ <!--<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>-->
+
+</ruleset>
diff --git a/tags/java/tsss-demo/http.jetty/LICENSE.txt b/tags/java/tsss-demo/http.jetty/LICENSE.txt
new file mode 100644
index 0000000000..d645695673
--- /dev/null
+++ b/tags/java/tsss-demo/http.jetty/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/http.jetty/NOTICE.txt b/tags/java/tsss-demo/http.jetty/NOTICE.txt
new file mode 100644
index 0000000000..d83ebbe236
--- /dev/null
+++ b/tags/java/tsss-demo/http.jetty/NOTICE.txt
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/http.jetty/pom.xml b/tags/java/tsss-demo/http.jetty/pom.xml
new file mode 100644
index 0000000000..f2e7d56aac
--- /dev/null
+++ b/tags/java/tsss-demo/http.jetty/pom.xml
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany</groupId>
+ <artifactId>sca</artifactId>
+ <version>1.0-incubating</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.services</groupId>
+ <artifactId>http-jetty</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ <name>Apache Tuscany Jetty HTTP Service</name>
+ <description>Tuscany Jetty HTTP Service</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-spi</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <version>6.1.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-util</artifactId>
+ <version>6.1.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-j2ee-connector_1.5_spec</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>2.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/tags/java/tsss-demo/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyLogger.java b/tags/java/tsss-demo/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyLogger.java
new file mode 100644
index 0000000000..d42b301fbb
--- /dev/null
+++ b/tags/java/tsss-demo/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyLogger.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.service.jetty;
+
+import org.mortbay.log.Logger;
+
+/**
+ * Serves as a wrapper for a {@link TransportMonitor} to replace Jetty's logging mechanism
+ *
+ * @version $Rev$ $Date$
+ */
+public class JettyLogger implements Logger {
+
+ private TransportMonitor monitor;
+ private boolean debugEnabled;
+
+ public void setMonitor(TransportMonitor monitor) {
+ this.monitor = monitor;
+ }
+
+ public boolean isDebugEnabled() {
+ return debugEnabled;
+ }
+
+ public void setDebugEnabled(boolean debugEnabled) {
+ this.debugEnabled = debugEnabled;
+ }
+
+ public void info(String msg, Object arg0, Object arg1) {
+ if (monitor != null) {
+ monitor.debug(msg, arg0, arg1);
+ } else if (debugEnabled) {
+ System.err.println(":INFO: " + format(msg, arg0, arg1));
+ }
+ }
+
+ public void debug(String msg, Throwable th) {
+ if (debugEnabled) {
+ if (monitor != null) {
+ monitor.debug(msg, th);
+ } else {
+ System.err.println(":DEBUG: " + msg);
+ th.printStackTrace();
+ }
+ }
+ }
+
+ public void debug(String msg, Object arg0, Object arg1) {
+ if (debugEnabled) {
+ if (monitor != null) {
+ monitor.debug(msg, arg0, arg1);
+ } else {
+ System.err.println(":DEBUG: " + format(msg, arg0, arg1));
+ }
+ }
+ }
+
+ public void warn(String msg, Object arg0, Object arg1) {
+ if (monitor != null) {
+ monitor.warn(msg, arg0, arg1);
+ } else if (debugEnabled) {
+ System.err.println(":WARN: " + format(msg, arg0, arg1));
+ }
+ }
+
+ public void warn(String msg, Throwable th) {
+ if (monitor != null) {
+ monitor.warn(msg, th);
+ } else if (debugEnabled) {
+ System.err.println(":WARN: " + msg);
+ th.printStackTrace();
+ }
+ }
+
+ public Logger getLogger(String name) {
+ return this;
+ }
+
+ private String format(String msg, Object arg0, Object arg1) {
+ int i0 = msg.indexOf("{}");
+ int i1 = i0 < 0 ? -1 : msg.indexOf("{}", i0 + 2);
+ if (arg1 != null && i1 >= 0) {
+ msg = msg.substring(0, i1) + arg1 + msg.substring(i1 + 2);
+ }
+ if (arg0 != null && i0 >= 0) {
+ msg = msg.substring(0, i0) + arg0 + msg.substring(i0 + 2);
+ }
+ return msg;
+ }
+}
diff --git a/tags/java/tsss-demo/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyService.java b/tags/java/tsss-demo/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyService.java
new file mode 100644
index 0000000000..6fd68813df
--- /dev/null
+++ b/tags/java/tsss-demo/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyService.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.service.jetty;
+
+import org.apache.tuscany.spi.host.ServletHost;
+
+import org.mortbay.jetty.Server;
+
+/**
+ * Implementations provide a Jetty transport service to the runtime
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public interface JettyService extends ServletHost {
+
+ /**
+ * Returns the active Jetty server
+ */
+ Server getServer();
+
+
+}
diff --git a/tags/java/tsss-demo/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyServiceImpl.java b/tags/java/tsss-demo/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyServiceImpl.java
new file mode 100644
index 0000000000..588c0b406d
--- /dev/null
+++ b/tags/java/tsss-demo/http.jetty/src/main/java/org/apache/tuscany/service/jetty/JettyServiceImpl.java
@@ -0,0 +1,326 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.service.jetty;
+
+import java.io.File;
+import java.io.IOException;
+import javax.resource.spi.work.Work;
+import javax.servlet.Servlet;
+
+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.Reference;
+import org.osoa.sca.annotations.Service;
+
+import org.apache.tuscany.spi.host.ServletHost;
+import org.apache.tuscany.spi.services.work.WorkScheduler;
+
+import org.apache.tuscany.api.annotation.Monitor;
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.handler.ContextHandler;
+import org.mortbay.jetty.nio.SelectChannelConnector;
+import org.mortbay.jetty.security.SslSocketConnector;
+import org.mortbay.jetty.servlet.ServletHandler;
+import org.mortbay.jetty.servlet.ServletHolder;
+import org.mortbay.jetty.servlet.ServletMapping;
+import org.mortbay.jetty.servlet.SessionHandler;
+import org.mortbay.log.Log;
+import org.mortbay.log.Logger;
+import org.mortbay.thread.BoundedThreadPool;
+import org.mortbay.thread.ThreadPool;
+
+/**
+ * Implements an HTTP transport service using Jetty.
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+@Service(ServletHost.class)
+@EagerInit
+public class JettyServiceImpl implements JettyService {
+
+ private static final String ROOT = "/";
+ private static final int ERROR = 0;
+ private static final int UNINITIALIZED = 0;
+ private static final int STARTING = 1;
+ private static final int STARTED = 2;
+ private static final int STOPPING = 3;
+ private static final int STOPPED = 4;
+
+ private final Object joinLock = new Object();
+ private int state = UNINITIALIZED;
+ private int httpPort = 8080;
+ private int httpsPort = 8484;
+ private String keystore;
+ private String certPassword;
+ private String keyPassword;
+ private boolean sendServerVersion;
+ private boolean https;
+ private TransportMonitor monitor;
+ private WorkScheduler scheduler;
+ private boolean debug;
+ private Server server;
+ private Connector connector;
+ private ServletHandler servletHandler;
+
+ static {
+ // hack to replace the static Jetty logger
+ System.setProperty("org.mortbay.log.class", JettyLogger.class.getName());
+ }
+
+ public JettyServiceImpl(@Monitor TransportMonitor monitor,
+ @Reference WorkScheduler scheduler) {
+ this.monitor = monitor;
+ this.scheduler = scheduler;
+ // Jetty uses a static logger, so jam in the monitor into a static reference
+ Logger logger = Log.getLogger(null);
+ if (logger instanceof JettyLogger) {
+ JettyLogger jettyLogger = (JettyLogger) logger;
+ jettyLogger.setMonitor(monitor);
+ if (debug) {
+ jettyLogger.setDebugEnabled(true);
+ }
+ }
+ }
+
+ public JettyServiceImpl(TransportMonitor monitor) {
+ this.monitor = monitor;
+ }
+
+ public JettyServiceImpl(TransportMonitor monitor,
+ WorkScheduler scheduler,
+ Connector connector) {
+ this(monitor, scheduler);
+ this.connector = connector;
+ }
+
+ @Property
+ public void setHttpPort(int httpPort) {
+ this.httpPort = httpPort;
+ }
+
+ @Property
+ public void setHttpsPort(int httpsPort) {
+ this.httpsPort = httpsPort;
+ }
+
+ @Property
+ public void setSendServerVersion(boolean sendServerVersion) {
+ this.sendServerVersion = sendServerVersion;
+ }
+
+ @Property
+ public void setHttps(boolean https) {
+ this.https = https;
+ }
+
+ @Property
+ public void setKeystore(String keystore) {
+ this.keystore = keystore;
+ }
+
+ @Property
+ public void setCertPassword(String certPassword) {
+ this.certPassword = certPassword;
+ }
+
+ @Property
+ public void setKeyPassword(String keyPassword) {
+ this.keyPassword = keyPassword;
+ }
+
+ @Property
+ public void setDebug(boolean val) {
+ debug = val;
+ }
+
+ @Init
+ public void init() throws Exception {
+ try {
+ state = STARTING;
+ server = new Server();
+ if (scheduler == null) {
+ BoundedThreadPool threadPool = new BoundedThreadPool();
+ threadPool.setMaxThreads(100);
+ server.setThreadPool(threadPool);
+ } else {
+ server.setThreadPool(new TuscanyThreadPool());
+ }
+ if (connector == null) {
+ if (https) {
+ Connector httpConnector = new SelectChannelConnector();
+ httpConnector.setPort(httpPort);
+ SslSocketConnector sslConnector = new SslSocketConnector();
+ sslConnector.setPort(httpsPort);
+ sslConnector.setKeystore(keystore);
+ sslConnector.setPassword(certPassword);
+ sslConnector.setKeyPassword(keyPassword);
+ server.setConnectors(new Connector[]{httpConnector, sslConnector});
+ } else {
+ SelectChannelConnector selectConnector = new SelectChannelConnector();
+ selectConnector.setPort(httpPort);
+ server.setConnectors(new Connector[]{selectConnector});
+ }
+ } else {
+ connector.setPort(httpPort);
+ server.setConnectors(new Connector[]{connector});
+ }
+
+ ContextHandler contextHandler = new ContextHandler();
+ contextHandler.setContextPath(ROOT);
+ server.setHandler(contextHandler);
+
+ SessionHandler sessionHandler = new SessionHandler();
+ servletHandler = new ServletHandler();
+ sessionHandler.addHandler(servletHandler);
+
+ contextHandler.setHandler(sessionHandler);
+
+ server.setStopAtShutdown(true);
+ server.setSendServerVersion(sendServerVersion);
+ monitor.started();
+ server.start();
+ state = STARTED;
+ } catch (Exception e) {
+ state = ERROR;
+ throw e;
+ }
+ }
+
+ @Destroy
+ public void destroy() throws Exception {
+ state = STOPPING;
+ synchronized (joinLock) {
+ joinLock.notifyAll();
+ }
+ server.stop();
+ state = STOPPED;
+ monitor.shutdown();
+ }
+
+ public void registerMapping(String path, Servlet servlet) {
+ ServletHolder holder = new ServletHolder(servlet);
+ servletHandler.addServlet(holder);
+ ServletMapping mapping = new ServletMapping();
+ mapping.setServletName(holder.getName());
+ mapping.setPathSpec(path);
+ servletHandler.addServletMapping(mapping);
+ }
+
+ public Servlet unregisterMapping(String string) {
+// throw new UnsupportedOperationException();
+ return null;
+ }
+
+ public boolean isMappingRegistered(String path) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void registerComposite(File compositeLocation) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ public Server getServer() {
+ return server;
+ }
+
+ public int getHttpPort() {
+ return httpPort;
+ }
+
+ /**
+ * An integration wrapper to enable use of a {@link WorkScheduler} with Jetty
+ */
+ private class TuscanyThreadPool implements ThreadPool {
+
+ public boolean dispatch(Runnable job) {
+ scheduler.scheduleWork(new TuscanyWork(job));
+ return true;
+ }
+
+ public void join() throws InterruptedException {
+ synchronized (joinLock) {
+ joinLock.wait();
+ }
+ }
+
+ public int getThreads() {
+ throw new UnsupportedOperationException();
+ }
+
+ public int getIdleThreads() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean isLowOnThreads() {
+ // TODO FIXME
+ return false;
+ }
+
+ public void start() throws Exception {
+
+ }
+
+ public void stop() throws Exception {
+
+ }
+
+ public boolean isRunning() {
+ return state == STARTING || state == STARTED;
+ }
+
+ public boolean isStarted() {
+ return state == STARTED;
+ }
+
+ public boolean isStarting() {
+ return state == STARTING;
+ }
+
+ public boolean isStopping() {
+ return state == STOPPING;
+ }
+
+ public boolean isFailed() {
+ return state == ERROR;
+ }
+ }
+
+ /**
+ * A unit of work dispatched to the runtime work scheduler
+ */
+ private class TuscanyWork implements Work {
+
+ Runnable job;
+
+ public TuscanyWork(Runnable job) {
+ this.job = job;
+ }
+
+ public void release() {
+ }
+
+ public void run() {
+ job.run();
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/http.jetty/src/main/java/org/apache/tuscany/service/jetty/TransportMonitor.java b/tags/java/tsss-demo/http.jetty/src/main/java/org/apache/tuscany/service/jetty/TransportMonitor.java
new file mode 100644
index 0000000000..c68eacd21c
--- /dev/null
+++ b/tags/java/tsss-demo/http.jetty/src/main/java/org/apache/tuscany/service/jetty/TransportMonitor.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.service.jetty;
+
+/**
+ * The monitoring interfaces used by the Jetty system service
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public interface TransportMonitor {
+
+ /**
+ * Called after the service is initialized
+ */
+ void started();
+
+ /**
+ * Called after the service is stopped
+ */
+ void shutdown();
+
+ void warn(String msg, Object...args);
+
+ void debug(String msg, Object...args);
+
+}
diff --git a/tags/java/tsss-demo/http.jetty/src/test/java/org/apache/tuscany/service/jetty/JettyServiceImplTestCase.java b/tags/java/tsss-demo/http.jetty/src/test/java/org/apache/tuscany/service/jetty/JettyServiceImplTestCase.java
new file mode 100644
index 0000000000..6863a478a0
--- /dev/null
+++ b/tags/java/tsss-demo/http.jetty/src/test/java/org/apache/tuscany/service/jetty/JettyServiceImplTestCase.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.service.jetty;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.Socket;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tuscany.spi.services.work.WorkScheduler;
+
+import junit.framework.TestCase;
+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 org.easymock.IAnswer;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JettyServiceImplTestCase extends TestCase {
+
+ private static final String REQUEST1_HEADER =
+ "GET / HTTP/1.0\n"
+ + "Host: localhost\n"
+ + "Content-Type: text/xml\n"
+ + "Connection: close\n"
+ + "Content-Length: ";
+ private static final String REQUEST1_CONTENT =
+ "";
+ private static final String REQUEST1 =
+ REQUEST1_HEADER + REQUEST1_CONTENT.getBytes().length + "\n\n" + REQUEST1_CONTENT;
+
+ private static final int HTTP_PORT = 8585;
+
+ private TransportMonitor monitor;
+ private WorkScheduler scheduler;
+ private ExecutorService executor = Executors.newCachedThreadPool();
+
+ /**
+ * Verifies requests are properly routed according to the servlet mapping
+ */
+ public void testRegisterServletMapping() throws Exception {
+ JettyServiceImpl service = new JettyServiceImpl(monitor);
+ service.setHttpPort(HTTP_PORT);
+ service.init();
+ TestServlet servlet = new TestServlet();
+ service.registerMapping("/", servlet);
+ Socket client = new Socket("127.0.0.1", HTTP_PORT);
+ OutputStream os = client.getOutputStream();
+ os.write(REQUEST1.getBytes());
+ os.flush();
+ read(client);
+ service.destroy();
+ assertTrue(servlet.invoked);
+ }
+
+ public void testRequestSession() throws Exception {
+ JettyServiceImpl service = new JettyServiceImpl(monitor, scheduler);
+ service.setDebug(true);
+ service.setHttpPort(HTTP_PORT);
+ service.init();
+ TestServlet servlet = new TestServlet();
+ service.registerMapping("/", servlet);
+ Socket client = new Socket("127.0.0.1", HTTP_PORT);
+ OutputStream os = client.getOutputStream();
+ os.write(REQUEST1.getBytes());
+ os.flush();
+ read(client);
+ service.destroy();
+ assertTrue(servlet.invoked);
+ assertNotNull(servlet.sessionId);
+ }
+
+ public void testUseWorkScheduler() throws Exception {
+ JettyServiceImpl service = new JettyServiceImpl(monitor, scheduler);
+ service.setDebug(true);
+ service.setHttpPort(HTTP_PORT);
+ service.init();
+ TestServlet servlet = new TestServlet();
+ service.registerMapping("/", servlet);
+ Socket client = new Socket("127.0.0.1", HTTP_PORT);
+ OutputStream os = client.getOutputStream();
+ os.write(REQUEST1.getBytes());
+ os.flush();
+ read(client);
+ service.destroy();
+ assertTrue(servlet.invoked);
+ }
+
+ public void testRestart() throws Exception {
+ JettyServiceImpl service = new JettyServiceImpl(monitor);
+ service.setHttpPort(HTTP_PORT);
+ service.init();
+ service.destroy();
+ service.init();
+ service.destroy();
+ }
+
+ public void testNoMappings() throws Exception {
+ JettyServiceImpl service = new JettyServiceImpl(monitor);
+ service.setHttpPort(HTTP_PORT);
+ service.init();
+ Socket client = new Socket("127.0.0.1", HTTP_PORT);
+ OutputStream os = client.getOutputStream();
+ os.write(REQUEST1.getBytes());
+ os.flush();
+ read(client);
+ service.destroy();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ //executor.submit();
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+ monitor = createMock(TransportMonitor.class);
+ scheduler = createMock(WorkScheduler.class);
+ scheduler.scheduleWork(isA(Runnable.class));
+
+ expectLastCall().andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ Runnable runnable = (Runnable) getCurrentArguments()[0];
+ executor.execute(runnable);
+ return null;
+ }
+ });
+ replay(scheduler);
+ }
+
+ private static String read(Socket socket) throws IOException {
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ StringBuffer sb = new StringBuffer();
+ String str;
+ while ((str = reader.readLine()) != null) {
+ sb.append(str);
+ }
+ return sb.toString();
+ } finally {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+ }
+
+ private class TestServlet extends HttpServlet {
+ private static final long serialVersionUID = 1L;
+ boolean invoked;
+ String sessionId;
+
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ invoked = true;
+ sessionId = req.getSession().getId();
+ OutputStream writer = resp.getOutputStream();
+ try {
+ writer.write("result".getBytes());
+ } finally {
+ writer.close();
+ }
+ }
+
+
+ }
+}
diff --git a/tags/java/tsss-demo/jms/.classpath b/tags/java/tsss-demo/jms/.classpath
new file mode 100644
index 0000000000..94b4dc29d7
--- /dev/null
+++ b/tags/java/tsss-demo/jms/.classpath
@@ -0,0 +1,26 @@
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/main/resources"/>
+ <classpathentry kind="src" path="src/test/java" output="target/test-classes"/>
+ <classpathentry kind="src" path="src/test/resources" output="target/test-classes"/>
+ <classpathentry kind="output" path="target/classes"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.13/log4j-1.2.13.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/geronimo/specs/geronimo-j2ee-management_1.0_spec/1.0/geronimo-j2ee-management_1.0_spec-1.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/logkit/logkit/1.0.1/logkit-1.0.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/stax/stax-api/1.0.1/stax-api-1.0.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/codehaus/woodstox/wstx-asl/3.2.0/wstx-asl-3.2.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/tuscany/sca/kernel/tuscany-api/2.0-alpha2-incubating-SNAPSHOT/tuscany-api-2.0-alpha2-incubating-SNAPSHOT.jar"/>
+ <classpathentry kind="var" path="M2_REPO/backport-util-concurrent/backport-util-concurrent/2.1/backport-util-concurrent-2.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/activemq/activemq-core/4.1.0-incubator/activemq-core-4.1.0-incubator.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/activemq/activeio-core/3.0.0-incubator/activeio-core-3.0.0-incubator.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/osoa/sca-api-r1.0/1.0-incubating/sca-api-r1.0-1.0-incubating.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/geronimo/specs/geronimo-jms_1.1_spec/1.0/geronimo-jms_1.1_spec-1.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1/commons-logging-1.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/avalon-framework/avalon-framework/4.1.3/avalon-framework-4.1.3.jar"/>
+ <classpathentry kind="var" path="M2_REPO/javax/servlet/servlet-api/2.3/servlet-api-2.3.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/jxta/platform/jxta/2.4.1/jxta-2.4.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/tuscany/sca/kernel/tuscany-host-api/2.0-alpha2-incubating-SNAPSHOT/tuscany-host-api-2.0-alpha2-incubating-SNAPSHOT.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/tuscany/sca/kernel/tuscany-spi/2.0-alpha2-incubating-SNAPSHOT/tuscany-spi-2.0-alpha2-incubating-SNAPSHOT.jar"/>
+</classpath> \ No newline at end of file
diff --git a/tags/java/tsss-demo/jms/.project b/tags/java/tsss-demo/jms/.project
new file mode 100644
index 0000000000..7b9b6fa034
--- /dev/null
+++ b/tags/java/tsss-demo/jms/.project
@@ -0,0 +1,14 @@
+<projectDescription>
+ <name>discovery-jms</name>
+ <comment>Apache Tuscany JMS Discovery</comment>
+ <projects/>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments/>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription> \ No newline at end of file
diff --git a/tags/java/tsss-demo/jms/LICENSE.txt b/tags/java/tsss-demo/jms/LICENSE.txt
new file mode 100644
index 0000000000..0084319535
--- /dev/null
+++ b/tags/java/tsss-demo/jms/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, serviceDefinition marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/jms/NOTICE.txt b/tags/java/tsss-demo/jms/NOTICE.txt
new file mode 100644
index 0000000000..d83ebbe236
--- /dev/null
+++ b/tags/java/tsss-demo/jms/NOTICE.txt
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/jms/pom.xml b/tags/java/tsss-demo/jms/pom.xml
new file mode 100644
index 0000000000..eb4c76efe4
--- /dev/null
+++ b/tags/java/tsss-demo/jms/pom.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany</groupId>
+ <artifactId>sca</artifactId>
+ <version>1.0-incubating</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.runtime.services.discovery</groupId>
+ <artifactId>discovery-jms</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>Apache Tuscany JMS Discovery</name>
+ <description>Apache Tuscany JMS Discovery</description>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-spi</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-core</artifactId>
+ <version>4.1.0-incubator</version>
+ <scope>compile</scope>
+ </dependency>
+
+<!--
+ <dependency>
+ <groupId>org.jxta.platform</groupId>
+ <artifactId>jxta</artifactId>
+ <version>2.4.1</version>
+ <scope>compile</scope>
+ </dependency>
+-->
+
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.13</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ <version>3.2.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+</project>
diff --git a/tags/java/tsss-demo/jms/src/main/java/org/apache/tuscany/service/discovery/jms/JmsDiscoveryService.java b/tags/java/tsss-demo/jms/src/main/java/org/apache/tuscany/service/discovery/jms/JmsDiscoveryService.java
new file mode 100644
index 0000000000..518d482245
--- /dev/null
+++ b/tags/java/tsss-demo/jms/src/main/java/org/apache/tuscany/service/discovery/jms/JmsDiscoveryService.java
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.service.discovery.jms;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.ExceptionListener;
+import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.activemq.ActiveMQConnection;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.command.ActiveMQTopic;
+import org.apache.tuscany.spi.services.discovery.AbstractDiscoveryService;
+import org.apache.tuscany.spi.services.discovery.DiscoveryException;
+import org.apache.tuscany.spi.util.stax.StaxUtil;
+import org.osoa.sca.annotations.Property;
+
+/**
+ * JMS based implementation of the discovery service. This class uses
+ * ActiveMQ specific API instead of JNDI based administered objects. This can
+ * be changed later if required.
+ *
+ * @version $Revision$ $Date$
+ */
+public class JmsDiscoveryService extends AbstractDiscoveryService {
+
+ // Connection factory
+ private ConnectionFactory connectionFactory;
+
+ // Underlying JMS connection
+ private Connection connection;
+
+ // Session used for reception
+ private Session receiverSession;
+
+ // Message consumer
+ private MessageConsumer messageConsumer;
+
+ // Topic to use
+ private Topic topic;
+
+ // String broker url
+ private String brokerUrl = ActiveMQConnection.DEFAULT_BROKER_URL;
+
+ /**
+ * Injects the topic used for communication.
+ * @param topic Topic used for communication.
+ */
+ @Property
+ public void setTopic(String topic) {
+ this.topic = new ActiveMQTopic(topic);
+ }
+
+ /**
+ * Injects the broker URL.
+ * @param brokerUrl Broker URL to use.
+ */
+ @Property
+ public void setBrokerUrl(String brokerUrl) {
+ this.brokerUrl = brokerUrl;
+ }
+
+ /**
+ * Starts the service and sets up the message listener.
+ */
+ @Override
+ protected synchronized void onStart() throws DiscoveryException {
+
+ String runtimeId = getRuntimeInfo().getRuntimeId();
+
+ try {
+
+ connectionFactory = new ActiveMQConnectionFactory(brokerUrl);
+
+ connection = connectionFactory.createConnection();
+ connection.setExceptionListener(new ExceptionListener() {
+ public void onException(JMSException jmsException) {
+ // Try restarting: TODO this may need further refinement
+ try {
+ onStop();
+ } catch (DiscoveryException ex) {
+ ex.printStackTrace();
+ }
+ try {
+ onStart();
+ } catch (DiscoveryException ex) {
+ ex.printStackTrace();
+ }
+ }
+ });
+ receiverSession = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
+
+ messageConsumer = receiverSession.createConsumer(topic);
+ final MessageListener messageListener = new TuscanyMessageListener(this, runtimeId);
+ messageConsumer.setMessageListener(messageListener);
+ connection.start();
+
+ } catch (JMSException ex) {
+ throw new DiscoveryException(ex);
+ }
+
+ }
+
+ /**
+ * Closes the connection.
+ */
+ @Override
+ protected synchronized void onStop() throws DiscoveryException {
+
+ try {
+ receiverSession.close();
+ } catch (JMSException ex) {
+ throw new DiscoveryException(ex);
+ } finally {
+ try {
+ connection.close();
+ } catch (JMSException ex) {
+ throw new DiscoveryException(ex);
+ }
+ }
+
+ }
+
+ /**
+ * Sends the message.
+ */
+ public synchronized int sendMessage(String runtimeId, XMLStreamReader reader) throws DiscoveryException {
+
+ try {
+
+ String text = StaxUtil.serialize(reader);
+ Session senderSession = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer messageProducer = senderSession.createProducer(topic);
+
+ TextMessage textMessage = senderSession.createTextMessage(text);
+
+ textMessage.setStringProperty("runtimeId", runtimeId);
+ messageProducer.send(textMessage);
+ senderSession.commit();
+ senderSession.close();
+
+ return 1;
+
+ } catch (XMLStreamException ex) {
+ throw new DiscoveryException(ex);
+ } catch (JMSException ex) {
+ throw new DiscoveryException(ex);
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/jms/src/main/java/org/apache/tuscany/service/discovery/jms/TuscanyJmsException.java b/tags/java/tsss-demo/jms/src/main/java/org/apache/tuscany/service/discovery/jms/TuscanyJmsException.java
new file mode 100644
index 0000000000..6b5f4066bf
--- /dev/null
+++ b/tags/java/tsss-demo/jms/src/main/java/org/apache/tuscany/service/discovery/jms/TuscanyJmsException.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.service.discovery.jms;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * @version $Revision$ $Date$
+ */
+@SuppressWarnings("serial")
+public class TuscanyJmsException extends TuscanyRuntimeException {
+
+ /**
+ * Initializes the cause.
+ * @param th Root cause for the exception.
+ */
+ public TuscanyJmsException(Throwable th) {
+ super(th);
+ }
+
+}
diff --git a/tags/java/tsss-demo/jms/src/main/java/org/apache/tuscany/service/discovery/jms/TuscanyMessageListener.java b/tags/java/tsss-demo/jms/src/main/java/org/apache/tuscany/service/discovery/jms/TuscanyMessageListener.java
new file mode 100644
index 0000000000..e34e1f6199
--- /dev/null
+++ b/tags/java/tsss-demo/jms/src/main/java/org/apache/tuscany/service/discovery/jms/TuscanyMessageListener.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.service.discovery.jms;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.TextMessage;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.services.discovery.RequestListener;
+import org.apache.tuscany.spi.util.stax.StaxUtil;
+
+/**
+ * Tuscany JMS message listsner.
+ *
+ * @version $Revision$ $Date$
+ */
+public class TuscanyMessageListener implements MessageListener {
+
+ // Discovery service
+ private JmsDiscoveryService discoveryService;
+
+ // Runtime id
+ private String runtimeId;
+
+ /**
+ * Initializes the discovery service.
+ * @param discoveryService Discovery service.
+ */
+ public TuscanyMessageListener(JmsDiscoveryService discoveryService, String runtimeId) {
+ this.discoveryService = discoveryService;
+ this.runtimeId = runtimeId;
+ }
+
+ /**
+ * Message listener callback.
+ */
+ public void onMessage(Message message) {
+
+ try {
+
+ // TODO investigate why selectors are not working
+ if(!runtimeId.equals(message.getStringProperty("runtimeId"))) {
+ return;
+ }
+
+ final TextMessage textMessage = (TextMessage)message;
+ final String text = textMessage.getText();
+
+ final QName messageType = StaxUtil.getDocumentElementQName(text);
+ System.err.println("Message received: " + messageType);
+
+ RequestListener messageListener = discoveryService.getRequestListener(messageType);
+ if (messageListener != null) {
+ XMLStreamReader requestReader = StaxUtil.createReader(text);
+ messageListener.onRequest(requestReader);
+ }
+
+ } catch (JMSException ex) {
+ throw new TuscanyJmsException(ex);
+ } catch (XMLStreamException ex) {
+ throw new TuscanyJmsException(ex);
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/LICENSE.txt b/tags/java/tsss-demo/kernel/LICENSE.txt
new file mode 100644
index 0000000000..0084319535
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, serviceDefinition marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/kernel/NOTICE.txt b/tags/java/tsss-demo/kernel/NOTICE.txt
new file mode 100644
index 0000000000..e78268b863
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/NOTICE.txt
@@ -0,0 +1,14 @@
+Apache Tuscany SCA Kernel Sub-Project
+Copyright (c) 2005 - 2007 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/kernel/README.txt b/tags/java/tsss-demo/kernel/README.txt
new file mode 100644
index 0000000000..ca024316d5
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/README.txt
@@ -0,0 +1,44 @@
+This Release of the Apache Tuscany SCA Kernel is designed as a baseline for extension development
+and early access to the Java programming model based on the SCA 1.0 Java Common Annotations
+and API Specification and the Java Component Implementation Specification. Copies of the
+specifications may be obtained from http://www.osoa.org.
+
+*** Please Note that extension SPIs are subject to change in future alpha and beta releases ***
+
+Release Features
+----------------
+A goal of the release has been closer alignment with the SCA specifications, and in particular,
+the implementation of new Java annotations and APIs introduced in the 1.0 version.
+New features include:
+
+- Support for full composite recursion (N-levels)
+- Improved and simplified non-blocking operations
+- Support for SCA 1.0 conversational callbacks, including synchronous operations
+- Support for many of the SCA 1.0 Annotations and APIs, including: scopes,
+ conversational annotations, ComponentContext, callback annotations,
+- Support for SCA 1.0 autowire
+- Support for service target syntax
+- Support for reference promotion syntax (multiple level promotion is not yet implemented
+ but planned for the next release)
+- Support for exception formatting
+- Improved exception handling
+- Reduced disk and memory footprint
+
+
+This release also includes significant architectural enhancements and refactors.
+Much of this work has been focused on simplification of the core architecture.
+In addition, changes have been introduced to support federated service networks
+and multi-VM wiring. It is expected that those features will be added in the next alpha release.
+
+- Greatly simplified wiring architecture, including elimination of inbound and outbound wiring
+- Support for sparse component trees distributed across multiple-VMs
+- Improved autowire support including changes to enable federated autowire in the next release
+- Introduction of a ComponentManager
+- Refactored Connector
+- Refactored Component interface and hierarchy
+- Increased test coverage (~70%)
+- An early implementation of federated assembly changeset marshalling
+
+
+In bocca al lupo!
+The Tuscany Team
diff --git a/tags/java/tsss-demo/kernel/api/.checkstyle b/tags/java/tsss-demo/kernel/api/.checkstyle
new file mode 100644
index 0000000000..3e57539570
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/api/.checkstyle
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<fileset-config file-format-version="1.2.0" simple-config="true">
+ <fileset name="all" enabled="true" check-config-name="Tuscany Checks" local="false">
+ <file-match-pattern match-pattern="." include-pattern="true"/>
+ </fileset>
+</fileset-config>
diff --git a/tags/java/tsss-demo/kernel/api/.pmd b/tags/java/tsss-demo/kernel/api/.pmd
new file mode 100644
index 0000000000..ffc4fe2bbb
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/api/.pmd
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<pmd><useProjectRuleSet>true</useProjectRuleSet><rules/></pmd>
diff --git a/tags/java/tsss-demo/kernel/api/.ruleset b/tags/java/tsss-demo/kernel/api/.ruleset
new file mode 100644
index 0000000000..3886f07f2d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/api/.ruleset
@@ -0,0 +1,190 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<ruleset name="pmd-eclipse">
+ <description>PMD Plugin preferences rule set</description>
+
+
+ <rule ref="rulesets/basic.xml/BooleanInstantiation"/>
+ <rule ref="rulesets/basic.xml/CollapsibleIfStatements"/>
+ <rule ref="rulesets/basic.xml/DoubleCheckedLocking"/>
+<!--<rule ref="rulesets/basic.xml/EmptyCatchBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyFinallyBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyIfStmt"/>-->
+ <rule ref="rulesets/basic.xml/EmptyStatementNotInLoop"/>
+<!--<rule ref="rulesets/basic.xml/EmptyStaticInitializer"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptySwitchStatements"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptySynchronizedBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyTryBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyWhileStmt"/>-->
+ <rule ref="rulesets/basic.xml/ForLoopShouldBeWhileLoop"/>
+ <rule ref="rulesets/basic.xml/JumbledIncrementer"/>
+<!--<rule ref="rulesets/basic.xml/OverrideBothEqualsAndHashcode"/>-->
+ <rule ref="rulesets/basic.xml/ReturnFromFinallyBlock"/>
+ <rule ref="rulesets/basic.xml/UnconditionalIfStatement"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryConversionTemporary"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryFinalModifier"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryReturn"/>
+<!--<rule ref="rulesets/basic.xml/UselessOverridingMethod"/>-->
+
+<!--<rule ref="rulesets/braces.xml/ForLoopsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/IfElseStmtsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/IfStmtsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/WhileLoopsMustUseBraces"/>-->
+
+<!--<rule ref="rulesets/clone.xml/CloneMethodMustImplementCloneable"/>-->
+<!--<rule ref="rulesets/clone.xml/CloneThrowsCloneNotSupportedException"/>-->
+<!--<rule ref="rulesets/clone.xml/ProperCloneImplementation"/>-->
+
+<!--<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>-->
+<!--<rule ref="rulesets/codesize.xml/TooManyFields"/>-->
+
+<rule ref="rulesets/controversial.xml/AssignmentInOperand"/>
+<!--<rule ref="rulesets/controversial.xml/AtLeastOneConstructor"/>-->
+<!--<rule ref="rulesets/controversial.xml/CallSuperInConstructor"/>-->
+<!--<rule ref="rulesets/controversial.xml/DontImportSun"/>-->
+<!--<rule ref="rulesets/controversial.xml/NullAssignment"/>-->
+<!--<rule ref="rulesets/controversial.xml/OnlyOneReturn"/>-->
+<!--<rule ref="rulesets/controversial.xml/SingularField"/>-->
+<!--<rule ref="rulesets/controversial.xml/SuspiciousOctalEscape"/>-->
+<!--<rule ref="rulesets/controversial.xml/UnnecessaryConstructor"/>-->
+<rule ref="rulesets/controversial.xml/UnnecessaryParentheses"/>
+<!--<rule ref="rulesets/controversial.xml/UnusedModifier"/>-->
+
+<!--<rule ref="rulesets/coupling.xml/CouplingBetweenObjects"/>-->
+<!--<rule ref="rulesets/coupling.xml/ExcessiveImports"/>-->
+<!--<rule ref="rulesets/coupling.xml/LooseCoupling"/>-->
+
+<!--<rule ref="rulesets/design.xml/AbstractClassWithoutAbstractMethod"/>-->
+<!--<rule ref="rulesets/design.xml/AccessorClassGeneration"/>-->
+<!--<rule ref="rulesets/design.xml/AssignmentToNonFinalStatic"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidDeeplyNestedIfStmts"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidInstanceofChecksInCatchClause"/>-->
+<rule ref="rulesets/design.xml/AvoidProtectedFieldInFinalClass"/>
+<!--<rule ref="rulesets/design.xml/AvoidReassigningParameters"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidSynchronizedAtMethodLevel"/>-->
+<!--<rule ref="rulesets/design.xml/BadComparison"/>-->
+<!--<rule ref="rulesets/design.xml/CloseConnection"/>-->
+<!--<rule ref="rulesets/design.xml/CompareObjectsWithEquals"/>-->
+<!--<rule ref="rulesets/design.xml/ConfusingTernary"/>-->
+<rule ref="rulesets/design.xml/ConstructorCallsOverridableMethod"/>
+<!--<rule ref="rulesets/design.xml/DefaultLabelNotLastInSwitchStmt"/>-->
+<!--<rule ref="rulesets/design.xml/FinalFieldCouldBeStatic"/>-->
+<rule ref="rulesets/design.xml/IdempotentOperations"/>
+<!--<rule ref="rulesets/design.xml/ImmutableField"/>-->
+<!--<rule ref="rulesets/design.xml/InstantiationToGetClass"/>-->
+<!--<rule ref="rulesets/design.xml/MissingBreakInSwitch"/>-->
+<!--<rule ref="rulesets/design.xml/MissingStaticMethodInNonInstantiatableClass"/>-->
+<!--<rule ref="rulesets/design.xml/NonCaseLabelInSwitchStatement"/>-->
+<!--<rule ref="rulesets/design.xml/NonStaticInitializer"/>-->
+<rule ref="rulesets/design.xml/OptimizableToArrayCall"/>
+<rule ref="rulesets/design.xml/PositionLiteralsFirstInComparisons"/>
+<rule ref="rulesets/design.xml/SimplifyBooleanExpressions"/>
+<rule ref="rulesets/design.xml/SimplifyBooleanReturns"/>
+<rule ref="rulesets/design.xml/SimplifyConditional"/>
+<!--<rule ref="rulesets/design.xml/SwitchDensity"/>-->
+<!--<rule ref="rulesets/design.xml/SwitchStmtsShouldHaveDefault"/>-->
+<rule ref="rulesets/design.xml/UnnecessaryLocalBeforeReturn"/>
+<!--<rule ref="rulesets/design.xml/UseLocaleWithCaseConversions"/>-->
+<!--<rule ref="rulesets/design.xml/UseNotifyAllInsteadOfNotify"/>-->
+<!--<rule ref="rulesets/design.xml/UseSingleton"/>-->
+
+<!--<rule ref="rulesets/finalizers.xml/EmptyFinalizer"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeOnlyCallsSuperFinalize"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeOverloaded"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeDoesNotCallSuperFinalize"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeShouldBeProtected"/>-->
+<!--<rule ref="rulesets/finalizers.xml/AvoidCallingFinalize"/>-->
+
+<!--<rule ref="rulesets/imports.xml/DuplicateImports"/>-->
+<!--<rule ref="rulesets/imports.xml/DontImportJavaLang"/>-->
+<!--<rule ref="rulesets/imports.xml/UnusedImports"/>-->
+<!--<rule ref="rulesets/imports.xml/ImportFromSamePackage"/>-->
+
+<!--<rule ref="rulesets/javabeans.xml/BeanMembersShouldSerialize"/>-->
+<!--<rule ref="rulesets/javabeans.xml/MissingSerialVersionUID"/>-->
+
+<!--<rule ref="rulesets/junit.xml/JUnitStaticSuite"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitSpelling"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitAssertionsShouldIncludeMessage"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitTestsShouldIncludeAssert"/>-->
+<!--<rule ref="rulesets/junit.xml/TestClassWithoutTestCases"/>-->
+<!--<rule ref="rulesets/junit.xml/UnnecessaryBooleanAssertion"/>-->
+<!--<rule ref="rulesets/junit.xml/UseAssertEqualsInsteadOfAssertTrue"/>-->
+<!--<rule ref="rulesets/junit.xml/UseAssertSameInsteadOfAssertTrue"/>-->
+
+ <!--<rule ref="rulesets/logging-java.xml/AvoidPrintStackTrace"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/MoreThanOneLogger"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LogBlockWithoutIf"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/SystemPrintln"/>-->
+ <!--<rule ref="rulesets/logging-jakarta-commons.xml/UseCorrectExceptionLogging"/>-->
+ <!--<rule ref="rulesets/logging-jakarta-commons.xml/ProperLogger"/>-->
+
+ <!--<rule ref="rulesets/naming.xml/ShortVariable"/>-->
+ <!--<rule ref="rulesets/naming.xml/LongVariable"/>-->
+ <!--<rule ref="rulesets/naming.xml/ShortMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/VariableNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/MethodNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/ClassNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/AbstractNaming"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidDollarSigns"/>-->
+ <!--<rule ref="rulesets/naming.xml/MethodWithSameNameAsEnclosingClass"/>-->
+ <!--<rule ref="rulesets/naming.xml/SuspiciousHashcodeMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/SuspiciousConstantFieldName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingTypeName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidNonConstructorMethodsWithClassName"/>-->
+ <!--<rule ref="rulesets/naming.xml/NoPackage"/>-->
+ <!--<rule ref="rulesets/naming.xml/PackageCase"/>-->
+
+ <!--<rule ref="rulesets/optimizations.xml/LocalVariableCouldBeFinal"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/MethodArgumentCouldBeFinal"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/AvoidInstantiatingObjectsInLoops"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/UseArrayListInsteadOfVector"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/SimplifyStartsWith"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/UseStringBufferForStringAppends"/>-->
+
+ <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingThrowable"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/SignatureDeclareThrowsException"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/ExceptionAsFlowControl"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingNPE"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingRawExceptionTypes"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingNullPointerException"/>-->
+
+ <!--<rule ref="rulesets/strings.xml/AvoidDuplicateLiterals"/>-->
+ <!--<rule ref="rulesets/strings.xml/StringInstantiation"/>-->
+ <!--<rule ref="rulesets/strings.xml/StringToString"/>-->
+ <!--<rule ref="rulesets/strings.xml/AvoidConcatenatingNonLiteralsInStringBuffer"/>-->
+ <!--<rule ref="rulesets/strings.xml/UnnecessaryCaseChange"/>-->
+
+ <!--<rule ref="rulesets/sunsecure.xml/MethodReturnsInternalArray"/>-->
+ <!--<rule ref="rulesets/sunsecure.xml/ArrayIsStoredDirectly"/>-->
+
+ <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/>
+ <rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/>
+ <rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/>
+ <!--<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>-->
+
+</ruleset>
diff --git a/tags/java/tsss-demo/kernel/api/LICENSE.txt b/tags/java/tsss-demo/kernel/api/LICENSE.txt
new file mode 100644
index 0000000000..0084319535
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/api/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, serviceDefinition marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/kernel/api/NOTICE.txt b/tags/java/tsss-demo/kernel/api/NOTICE.txt
new file mode 100644
index 0000000000..d83ebbe236
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/api/NOTICE.txt
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/kernel/api/pom.xml b/tags/java/tsss-demo/kernel/api/pom.xml
new file mode 100644
index 0000000000..f781dc2bc1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/api/pom.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>kernel</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-api</artifactId>
+ <name>Apache Tuscany SCA API</name>
+ <description>Tuscany Application Programming Interfaces.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osoa</groupId>
+ <artifactId>sca-api-r${scaSpecVersion}</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyException.java b/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyException.java
new file mode 100644
index 0000000000..346972bbee
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyException.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.api;
+
+import java.io.PrintWriter;
+
+/**
+ * The root checked exception for the Tuscany runtime.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class TuscanyException extends Exception {
+ private static final long serialVersionUID = -7847121698339635268L;
+ private final String identifier;
+
+ /**
+ * Override constructor from Exception.
+ *
+ * @see Exception
+ */
+ public TuscanyException() {
+ super();
+ this.identifier = null;
+ }
+
+ /**
+ * Override constructor from Exception.
+ *
+ * @param message passed to Exception
+ * @see Exception
+ */
+ public TuscanyException(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 TuscanyException(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 TuscanyException(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 TuscanyException(String message, String identifier, Throwable cause) {
+ super(message, cause);
+ this.identifier = identifier;
+ }
+
+ /**
+ * Override constructor from Exception.
+ *
+ * @param cause passed to Exception
+ * @see Exception
+ */
+ public TuscanyException(Throwable cause) {
+ super(cause);
+ this.identifier = null;
+ }
+
+ /**
+ * Returns a string representing additional error information referred to in the error message.
+ *
+ * @return additional error information
+ */
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ public PrintWriter appendBaseMessage(PrintWriter writer) {
+ if (identifier == null) {
+ if (super.getMessage() == null) {
+ return writer;
+ }
+ return writer.append(super.getMessage());
+ }
+ if (super.getMessage() != null) {
+ writer.append(super.getMessage());
+ }
+ writer.append(" [").append(identifier).append(']');
+ return writer;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyRuntimeException.java b/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyRuntimeException.java
new file mode 100644
index 0000000000..aec4b774e4
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/TuscanyRuntimeException.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.api;
+
+import java.io.PrintWriter;
+
+/**
+ * The root unchecked exception for the Tuscany runtime.
+ *
+ * @version $Rev$ $Date$
+ */
+
+public abstract class TuscanyRuntimeException extends RuntimeException {
+ private static final long serialVersionUID = -759677431966121786L;
+ private final String identifier;
+
+ /**
+ * Override constructor from RuntimeException.
+ *
+ * @see RuntimeException
+ */
+ public TuscanyRuntimeException() {
+ super();
+ this.identifier = null;
+ }
+
+ /**
+ * Override constructor from RuntimeException.
+ *
+ * @param message passed to RuntimeException
+ * @see RuntimeException
+ */
+ public TuscanyRuntimeException(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
+ */
+ protected TuscanyRuntimeException(String message, String identifier) {
+ super(message);
+ this.identifier = identifier;
+ }
+
+ /**
+ * Override constructor from RuntimeException.
+ *
+ * @param message passed to RuntimeException
+ * @param cause passed to RuntimeException
+ * @see RuntimeException
+ */
+ public TuscanyRuntimeException(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 RuntimeException
+ * @see Exception
+ */
+ protected TuscanyRuntimeException(String message, String identifier, Throwable cause) {
+ super(message, cause);
+ this.identifier = identifier;
+ }
+
+ /**
+ * Override constructor from RuntimeException.
+ *
+ * @param cause passed to RuntimeException
+ * @see RuntimeException
+ */
+ public TuscanyRuntimeException(Throwable cause) {
+ super(cause);
+ this.identifier = null;
+ }
+
+ /**
+ * Returns a string representing additional error information referred to in the error message.
+ *
+ * @return additional error information
+ */
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ public PrintWriter appendBaseMessage(PrintWriter writer) {
+ if (identifier == null) {
+ if (super.getMessage() == null) {
+ return writer;
+ }
+ return writer.append(super.getMessage());
+ }
+ if (super.getMessage() != null) {
+ writer.append(super.getMessage());
+ }
+ writer.append(" [").append(identifier).append(']');
+ return writer;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/DataContext.java b/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/DataContext.java
new file mode 100644
index 0000000000..ab74ba9e5c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/DataContext.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.api.annotation;
+
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * A key/value pair to represent information pertaining to a {@link DataType}
+ */
+@Target(ANNOTATION_TYPE)
+@Retention(RUNTIME)
+public @interface DataContext {
+ /**
+ * @return key for the context entry
+ */
+ String key();
+
+ /**
+ * @return key for the context value
+ */
+ String value();
+
+}
diff --git a/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/DataType.java b/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/DataType.java
new file mode 100644
index 0000000000..439aa837d2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/DataType.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.api.annotation;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * Used to demarcate expected data types for an operation
+ *
+ * @version $Rev$ $Date$
+ */
+@Target({TYPE, METHOD})
+@Retention(RUNTIME)
+public @interface DataType {
+
+ /**
+ * Returns the unique name of the data binding
+ * @return the unique name of the data binding
+ */
+ String name();
+
+ /**
+ * Returns the logical data type
+ * @return the logical data type
+ */
+ Class logicalType() default Object.class;
+
+ /**
+ * Returns the physical data type
+ * @return the physical data type
+ */
+ Class physicalType() default Object.class;
+
+ /**
+ * Returns an array of extensibility elements
+ * @return an array of extensibility elements
+ */
+ DataContext[] context() default {};
+
+}
diff --git a/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/LogLevel.java b/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/LogLevel.java
new file mode 100644
index 0000000000..83c5df26d9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/LogLevel.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.api.annotation;
+
+import static java.lang.annotation.ElementType.METHOD;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation that can be applied to methods in a monitoring interface to indicate to logging frameworks the severity of
+ * the event.
+ *
+ * @version $Rev$ $Date$
+ */
+@Target({METHOD})
+@Retention(RUNTIME)
+public @interface LogLevel {
+
+ /**
+ * The log level as specified by {@link java.util.logging.Level}.
+ */
+ @SuppressWarnings({"JavaDoc"}) String value();
+}
diff --git a/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/Monitor.java b/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/Monitor.java
new file mode 100644
index 0000000000..dea9489e5b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/Monitor.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.api.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * A system annotation to inject a monitor
+ *
+ * @version $Rev$ $Date$
+ */
+@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Monitor {
+}
diff --git a/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/Resource.java b/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/Resource.java
new file mode 100644
index 0000000000..a7158ab6b8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/Resource.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.api.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation used to indicate a resource should be provided to an implementation by the runtime.
+ *
+ * @version $Rev$ $Date$
+ */
+@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Resource {
+
+ /**
+ * Denotes the name of the resource declared by the implementation.
+ */
+ String name() default "";
+
+ /**
+ * Denotes if the resource is optional
+ */
+ boolean optional() default false;
+
+ /**
+ * Denotes the default name of the resource provided by the runtime environment.
+ */
+ String mappedName() default "";
+}
diff --git a/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/package-info.java b/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/package-info.java
new file mode 100644
index 0000000000..3968efe1da
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/annotation/package-info.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.
+ */
+
+/**
+ * Annotations that enable Apache Tuscany programming model extensions
+ * in application components.
+ */
+package org.apache.tuscany.api.annotation; \ No newline at end of file
diff --git a/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/package-info.java b/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/package-info.java
new file mode 100644
index 0000000000..19f187edbf
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/api/src/main/java/org/apache/tuscany/api/package-info.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.
+ */
+
+/**
+ * Overview of Apache Tuscany Application Programming Interface.
+ *
+ * This package contains classes and annotations intended for use by application code.
+ * In general, the programming models supported by Apache Tuscany are designed to be
+ * non-intrusive. The goal is for application code to be portable to any framework
+ * supporting an Inversion of Control style programming model and as such does
+ * not require application code to inherit from framework classes or to implement
+ * framework specific interfaces. Where additional information is required by the
+ * framework, Java annotations are used.
+ *
+ * <h1>Monitoring Framework</h1>
+ *
+ * Apache Tuscany provides a monitoring framework that application code can use to
+ * send management events to the host's logging framework in a manner that is
+ * independent of the actual framework used by the runtime environment. This is
+ * the same infrastructure as used by Tuscany itself, allowing events from
+ * applications, the Apache Tuscany runtime and the host itself to all be handled
+ * by the host's logging infrastructure. These events can be combined in one stream
+ * or seperated as supported by the host infrastructure.
+ *
+ * To use this framework, application code should define a component-specific interface
+ * defining the monitoring events that it wishes to send and mark a field, setter or
+ * constructor with the {@link org.apache.tuscany.api.annotation.Monitor @Monitor} annotation.
+ * The framework will inject a implementation of the monitoring interface that dispatches
+ * events to the underlying infrastructure.
+ *
+ * <pre>
+ * public class MyComponent {
+ * private final MyComponentMonitor monitor;
+ *
+ * public MyComponent(@Monitor MyComponentMonitor monitor) {
+ * this.monitor = monitor;
+ * }
+ *
+ * public void start() {
+ * monitor.started();
+ * }
+ *
+ * public void stop() {
+ * monitor.stopped();
+ * }
+ *
+ * public interface MyComponentMonitor {
+ * void started();
+ * void stopped();
+ * }
+ * }
+ * </pre>
+ *
+ * The {@link org.apache.tuscany.api.annotation.LogLevel @LogLevel} annotation
+ * can be used to provide a hint for the logging level to associate with the event.
+ * The actual level used is determined by the configuration of the monitoring framework.
+ *
+ * For performance reasons, the objects passed as parameters should typically be instances
+ * that are already in use by the application code; operations that allocate new objects
+ * (such as string concatenation) should be avoided.
+ *
+ * <h1></h1>
+ */
+package org.apache.tuscany.api; \ No newline at end of file
diff --git a/tags/java/tsss-demo/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyExceptionTestCase.java b/tags/java/tsss-demo/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyExceptionTestCase.java
new file mode 100644
index 0000000000..ace75e6b10
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyExceptionTestCase.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.api;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TuscanyExceptionTestCase extends TestCase {
+ private static final Throwable CAUSE = new Throwable("Cause");
+ private static final String IDENTIFIER = "IDENTIFIER";
+ private static final String MESSAGE = "Message";
+
+ public void testNoArgConstructor() {
+ TuscanyException ex = new DummyException();
+ assertNull(ex.getMessage());
+ assertNull(ex.getCause());
+ assertNull(ex.getIdentifier());
+ }
+
+ public void testMessageConstructor() {
+ TuscanyException ex = new DummyException(MESSAGE);
+ assertEquals(MESSAGE, ex.getMessage());
+ assertNull(ex.getCause());
+ assertNull(ex.getIdentifier());
+ }
+
+ public void testAppendBaseMessage() {
+ TuscanyException ex = new DummyException(MESSAGE, IDENTIFIER);
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ ex.appendBaseMessage(pw);
+ assertEquals("Message [IDENTIFIER]", writer.toString());
+ }
+
+ public void testAppendBaseMessageNoIdentifier() {
+ TuscanyException ex = new DummyException(MESSAGE);
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ ex.appendBaseMessage(pw);
+ assertEquals("Message", writer.toString());
+ }
+
+ public void testThrowableConstructor() {
+ TuscanyException ex = new DummyException(CAUSE);
+ assertEquals(CAUSE.getClass().getName() + ": " + CAUSE.getMessage(), ex.getMessage());
+ assertEquals(CAUSE, ex.getCause());
+ assertNull(ex.getIdentifier());
+ }
+
+ public void testMessageThrowableConstructor() {
+ TuscanyException ex = new DummyException(MESSAGE, CAUSE);
+ assertEquals(MESSAGE, ex.getMessage());
+ assertEquals(CAUSE, ex.getCause());
+ assertNull(ex.getIdentifier());
+ }
+
+ public void testGetMessage() throws Exception {
+ TuscanyException e = new DummyException();
+ e.getMessage();
+ }
+
+ public void testFullMessage() throws Exception {
+ TuscanyException e = new DummyException("message", "foo");
+ e.getMessage();
+ }
+
+ public static class DummyException extends TuscanyException {
+
+ public DummyException() {
+ }
+
+ public DummyException(String message) {
+ super(message);
+ }
+
+
+ public DummyException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public DummyException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public DummyException(Throwable cause) {
+ super(cause);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyRuntimeExceptionTestCase.java b/tags/java/tsss-demo/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyRuntimeExceptionTestCase.java
new file mode 100644
index 0000000000..a32bdbb1a6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/api/src/test/java/org/apache/tuscany/api/TuscanyRuntimeExceptionTestCase.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.api;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TuscanyRuntimeExceptionTestCase extends TestCase {
+ private static final Throwable CAUSE = new Throwable("Cause");
+ private static final String MESSAGE = "Message";
+ private static final String IDENTIFIER = "IDENTIFIER";
+ private static final String CONTEXT1 = "CONTEXT1";
+ private static final String CONTEXT2 = "CONTEXT2";
+
+ public void testNoArgConstructor() {
+ TuscanyRuntimeException ex = new DummyException();
+ assertNull(ex.getMessage());
+ assertNull(ex.getCause());
+ assertNull(ex.getIdentifier());
+ }
+
+ public void testMessageConstructor() {
+ TuscanyRuntimeException ex = new DummyException(MESSAGE);
+ assertSame(MESSAGE, ex.getMessage());
+ assertNull(ex.getCause());
+ assertNull(ex.getIdentifier());
+ }
+
+ public void testThrowableConstructor() {
+ TuscanyRuntimeException ex = new DummyException(CAUSE);
+ assertEquals(CAUSE.getClass().getName() + ": " + CAUSE.getMessage(), ex.getMessage());
+ assertSame(CAUSE, ex.getCause());
+ assertNull(ex.getIdentifier());
+ }
+
+ public void testMessageThrowableConstructor() {
+ TuscanyRuntimeException ex = new DummyException(MESSAGE, CAUSE);
+ assertSame(MESSAGE, ex.getMessage());
+ assertSame(CAUSE, ex.getCause());
+ assertNull(ex.getIdentifier());
+ }
+
+ public void testIdentifier() {
+ TuscanyRuntimeException ex = new DummyException(MESSAGE, IDENTIFIER);
+ assertEquals(IDENTIFIER, ex.getIdentifier());
+ }
+
+ public void testAppendBaseMessage() {
+ TuscanyRuntimeException ex = new DummyException(MESSAGE, IDENTIFIER);
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ ex.appendBaseMessage(pw);
+ assertEquals("Message [IDENTIFIER]", writer.toString());
+ }
+
+ public void testAppendBaseMessageNoIdentifier() {
+ TuscanyRuntimeException ex = new DummyException(MESSAGE);
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ ex.appendBaseMessage(pw);
+ assertEquals("Message", writer.toString());
+ }
+
+ public static class DummyException extends TuscanyRuntimeException {
+ public DummyException() {
+ }
+
+ public DummyException(String message) {
+ super(message);
+ }
+
+ public DummyException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public DummyException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public DummyException(Throwable cause) {
+ super(cause);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/.checkstyle b/tags/java/tsss-demo/kernel/core/.checkstyle
new file mode 100644
index 0000000000..3e57539570
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/.checkstyle
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<fileset-config file-format-version="1.2.0" simple-config="true">
+ <fileset name="all" enabled="true" check-config-name="Tuscany Checks" local="false">
+ <file-match-pattern match-pattern="." include-pattern="true"/>
+ </fileset>
+</fileset-config>
diff --git a/tags/java/tsss-demo/kernel/core/.pmd b/tags/java/tsss-demo/kernel/core/.pmd
new file mode 100644
index 0000000000..ffc4fe2bbb
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/.pmd
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<pmd><useProjectRuleSet>true</useProjectRuleSet><rules/></pmd>
diff --git a/tags/java/tsss-demo/kernel/core/.ruleset b/tags/java/tsss-demo/kernel/core/.ruleset
new file mode 100644
index 0000000000..ba9b5ce886
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/.ruleset
@@ -0,0 +1,190 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<ruleset name="pmd-eclipse">
+ <description>PMD Plugin preferences rule set</description>
+
+
+ <rule ref="rulesets/basic.xml/BooleanInstantiation"/>
+ <rule ref="rulesets/basic.xml/CollapsibleIfStatements"/>
+ <rule ref="rulesets/basic.xml/DoubleCheckedLocking"/>
+<!--<rule ref="rulesets/basic.xml/EmptyCatchBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyFinallyBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyIfStmt"/>-->
+ <rule ref="rulesets/basic.xml/EmptyStatementNotInLoop"/>
+<!--<rule ref="rulesets/basic.xml/EmptyStaticInitializer"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptySwitchStatements"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptySynchronizedBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyTryBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyWhileStmt"/>-->
+ <rule ref="rulesets/basic.xml/ForLoopShouldBeWhileLoop"/>
+ <rule ref="rulesets/basic.xml/JumbledIncrementer"/>
+<!--<rule ref="rulesets/basic.xml/OverrideBothEqualsAndHashcode"/>-->
+ <rule ref="rulesets/basic.xml/ReturnFromFinallyBlock"/>
+ <rule ref="rulesets/basic.xml/UnconditionalIfStatement"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryConversionTemporary"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryFinalModifier"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryReturn"/>
+<!--<rule ref="rulesets/basic.xml/UselessOverridingMethod"/>-->
+
+<!--<rule ref="rulesets/braces.xml/ForLoopsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/IfElseStmtsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/IfStmtsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/WhileLoopsMustUseBraces"/>-->
+
+<!--<rule ref="rulesets/clone.xml/CloneMethodMustImplementCloneable"/>-->
+<!--<rule ref="rulesets/clone.xml/CloneThrowsCloneNotSupportedException"/>-->
+<!--<rule ref="rulesets/clone.xml/ProperCloneImplementation"/>-->
+
+<!--<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>-->
+<!--<rule ref="rulesets/codesize.xml/TooManyFields"/>-->
+
+<rule ref="rulesets/controversial.xml/AssignmentInOperand"/>
+<!--<rule ref="rulesets/controversial.xml/AtLeastOneConstructor"/>-->
+<!--<rule ref="rulesets/controversial.xml/CallSuperInConstructor"/>-->
+<!--<rule ref="rulesets/controversial.xml/DontImportSun"/>-->
+<!--<rule ref="rulesets/controversial.xml/NullAssignment"/>-->
+<!--<rule ref="rulesets/controversial.xml/OnlyOneReturn"/>-->
+<!--<rule ref="rulesets/controversial.xml/SingularField"/>-->
+<!--<rule ref="rulesets/controversial.xml/SuspiciousOctalEscape"/>-->
+<!--<rule ref="rulesets/controversial.xml/UnnecessaryConstructor"/>-->
+<rule ref="rulesets/controversial.xml/UnnecessaryParentheses"/>
+<!--<rule ref="rulesets/controversial.xml/UnusedModifier"/>-->
+
+<!--<rule ref="rulesets/coupling.xml/CouplingBetweenObjects"/>-->
+<!--<rule ref="rulesets/coupling.xml/ExcessiveImports"/>-->
+<!--<rule ref="rulesets/coupling.xml/LooseCoupling"/>-->
+
+<!--<rule ref="rulesets/design.xml/AbstractClassWithoutAbstractMethod"/>-->
+<!--<rule ref="rulesets/design.xml/AccessorClassGeneration"/>-->
+<!--<rule ref="rulesets/design.xml/AssignmentToNonFinalStatic"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidDeeplyNestedIfStmts"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidInstanceofChecksInCatchClause"/>-->
+<rule ref="rulesets/design.xml/AvoidProtectedFieldInFinalClass"/>
+<!--<rule ref="rulesets/design.xml/AvoidReassigningParameters"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidSynchronizedAtMethodLevel"/>-->
+<!--<rule ref="rulesets/design.xml/BadComparison"/>-->
+<!--<rule ref="rulesets/design.xml/CloseConnection"/>-->
+<!--<rule ref="rulesets/design.xml/CompareObjectsWithEquals"/>-->
+<!--<rule ref="rulesets/design.xml/ConfusingTernary"/>-->
+<rule ref="rulesets/design.xml/ConstructorCallsOverridableMethod"/>
+<!--<rule ref="rulesets/design.xml/DefaultLabelNotLastInSwitchStmt"/>-->
+<!--<rule ref="rulesets/design.xml/FinalFieldCouldBeStatic"/>-->
+<rule ref="rulesets/design.xml/IdempotentOperations"/>
+<!--<rule ref="rulesets/design.xml/ImmutableField"/>-->
+<!--<rule ref="rulesets/design.xml/InstantiationToGetClass"/>-->
+<!--<rule ref="rulesets/design.xml/MissingBreakInSwitch"/>-->
+<!--<rule ref="rulesets/design.xml/MissingStaticMethodInNonInstantiatableClass"/>-->
+<!--<rule ref="rulesets/design.xml/NonCaseLabelInSwitchStatement"/>-->
+<!--<rule ref="rulesets/design.xml/NonStaticInitializer"/>-->
+<rule ref="rulesets/design.xml/OptimizableToArrayCall"/>
+<rule ref="rulesets/design.xml/PositionLiteralsFirstInComparisons"/>
+<rule ref="rulesets/design.xml/SimplifyBooleanExpressions"/>
+<rule ref="rulesets/design.xml/SimplifyBooleanReturns"/>
+<rule ref="rulesets/design.xml/SimplifyConditional"/>
+<!--<rule ref="rulesets/design.xml/SwitchDensity"/>-->
+<!--<rule ref="rulesets/design.xml/SwitchStmtsShouldHaveDefault"/>-->
+<!--<rule ref="rulesets/design.xml/UnnecessaryLocalBeforeReturn"/>-->
+<!--<rule ref="rulesets/design.xml/UseLocaleWithCaseConversions"/>-->
+<!--<rule ref="rulesets/design.xml/UseNotifyAllInsteadOfNotify"/>-->
+<!--<rule ref="rulesets/design.xml/UseSingleton"/>-->
+
+<!--<rule ref="rulesets/finalizers.xml/EmptyFinalizer"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeOnlyCallsSuperFinalize"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeOverloaded"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeDoesNotCallSuperFinalize"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeShouldBeProtected"/>-->
+<!--<rule ref="rulesets/finalizers.xml/AvoidCallingFinalize"/>-->
+
+<!--<rule ref="rulesets/imports.xml/DuplicateImports"/>-->
+<!--<rule ref="rulesets/imports.xml/DontImportJavaLang"/>-->
+<!--<rule ref="rulesets/imports.xml/UnusedImports"/>-->
+<!--<rule ref="rulesets/imports.xml/ImportFromSamePackage"/>-->
+
+<!--<rule ref="rulesets/javabeans.xml/BeanMembersShouldSerialize"/>-->
+<!--<rule ref="rulesets/javabeans.xml/MissingSerialVersionUID"/>-->
+
+<!--<rule ref="rulesets/junit.xml/JUnitStaticSuite"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitSpelling"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitAssertionsShouldIncludeMessage"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitTestsShouldIncludeAssert"/>-->
+<!--<rule ref="rulesets/junit.xml/TestClassWithoutTestCases"/>-->
+<!--<rule ref="rulesets/junit.xml/UnnecessaryBooleanAssertion"/>-->
+<!--<rule ref="rulesets/junit.xml/UseAssertEqualsInsteadOfAssertTrue"/>-->
+<!--<rule ref="rulesets/junit.xml/UseAssertSameInsteadOfAssertTrue"/>-->
+
+ <!--<rule ref="rulesets/logging-java.xml/AvoidPrintStackTrace"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/MoreThanOneLogger"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LogBlockWithoutIf"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/SystemPrintln"/>-->
+ <!--<rule ref="rulesets/logging-jakarta-commons.xml/UseCorrectExceptionLogging"/>-->
+ <!--<rule ref="rulesets/logging-jakarta-commons.xml/ProperLogger"/>-->
+
+ <!--<rule ref="rulesets/naming.xml/ShortVariable"/>-->
+ <!--<rule ref="rulesets/naming.xml/LongVariable"/>-->
+ <!--<rule ref="rulesets/naming.xml/ShortMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/VariableNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/MethodNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/ClassNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/AbstractNaming"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidDollarSigns"/>-->
+ <!--<rule ref="rulesets/naming.xml/MethodWithSameNameAsEnclosingClass"/>-->
+ <!--<rule ref="rulesets/naming.xml/SuspiciousHashcodeMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/SuspiciousConstantFieldName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingTypeName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidNonConstructorMethodsWithClassName"/>-->
+ <!--<rule ref="rulesets/naming.xml/NoPackage"/>-->
+ <!--<rule ref="rulesets/naming.xml/PackageCase"/>-->
+
+ <!--<rule ref="rulesets/optimizations.xml/LocalVariableCouldBeFinal"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/MethodArgumentCouldBeFinal"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/AvoidInstantiatingObjectsInLoops"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/UseArrayListInsteadOfVector"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/SimplifyStartsWith"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/UseStringBufferForStringAppends"/>-->
+
+ <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingThrowable"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/SignatureDeclareThrowsException"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/ExceptionAsFlowControl"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingNPE"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingRawExceptionTypes"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingNullPointerException"/>-->
+
+ <!--<rule ref="rulesets/strings.xml/AvoidDuplicateLiterals"/>-->
+ <!--<rule ref="rulesets/strings.xml/StringInstantiation"/>-->
+ <!--<rule ref="rulesets/strings.xml/StringToString"/>-->
+ <!--<rule ref="rulesets/strings.xml/AvoidConcatenatingNonLiteralsInStringBuffer"/>-->
+ <!--<rule ref="rulesets/strings.xml/UnnecessaryCaseChange"/>-->
+
+ <!--<rule ref="rulesets/sunsecure.xml/MethodReturnsInternalArray"/>-->
+ <!--<rule ref="rulesets/sunsecure.xml/ArrayIsStoredDirectly"/>-->
+
+ <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/>
+ <rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/>
+ <rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/>
+ <!--<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>-->
+
+</ruleset>
diff --git a/tags/java/tsss-demo/kernel/core/LICENSE.txt b/tags/java/tsss-demo/kernel/core/LICENSE.txt
new file mode 100644
index 0000000000..0084319535
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, serviceDefinition marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/kernel/core/NOTICE.txt b/tags/java/tsss-demo/kernel/core/NOTICE.txt
new file mode 100644
index 0000000000..d83ebbe236
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/NOTICE.txt
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/kernel/core/pom.xml b/tags/java/tsss-demo/kernel/core/pom.xml
new file mode 100644
index 0000000000..1cd71c751b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/pom.xml
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>kernel</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-core</artifactId>
+ <packaging>jar</packaging>
+ <name>Apache Tuscany SCA Core</name>
+ <description>Core Tuscany runtime.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-spi</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany</groupId>
+ <artifactId>commonj-api_r1.1</artifactId>
+ <version>1.0-incubator-M2</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-j2ee-connector_1.5_spec</artifactId>
+ <version>1.0.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.3</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ <resource>
+ <directory>${notice.dir}</directory>
+ <targetPath>META-INF</targetPath>
+ <filtering>true</filtering>
+ <includes>
+ <include>LICENSE.txt</include>
+ <include>NOTICE.txt</include>
+ </includes>
+ </resource>
+ </resources>
+ </build>
+</project>
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvoker.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvoker.java
new file mode 100644
index 0000000000..4a06bc8c74
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvoker.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.core.binding.local;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.component.WorkContext;
+
+/**
+ * Base class for dispatching to a composite reference using the local binding
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractLocalTargetInvoker implements TargetInvoker {
+ protected boolean cacheable;
+
+ 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 Object invokeTarget(final Object payload, short sequence, WorkContext workContext) throws InvocationTargetException {
+ throw new InvocationTargetException(new UnsupportedOperationException());
+ }
+
+ protected Message invoke(InvocationChain chain, TargetInvoker invoker, Message msg) throws Throwable {
+ Interceptor headInterceptor = chain.getHeadInterceptor();
+ if (headInterceptor == null) {
+ try {
+ // short-circuit the dispatch and invoke the target directly
+ if (invoker == null) {
+ String name = chain.getOperation().getName();
+ throw new AssertionError("No target invoker [" + name + "]");
+ }
+ return invoker.invoke(msg);
+ } catch (InvocationRuntimeException e) {
+ // the cause was thrown by the target so throw it
+ throw e.getCause();
+ }
+ } else {
+ msg.setTargetInvoker(invoker);
+ return headInterceptor.invoke(msg);
+ }
+ }
+
+ @Override
+ public AbstractLocalTargetInvoker clone() throws CloneNotSupportedException {
+ return (AbstractLocalTargetInvoker) super.clone();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalBindingBuilder.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalBindingBuilder.java
new file mode 100644
index 0000000000..63a9147b29
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalBindingBuilder.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.core.binding.local;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.BindingBuilderExtension;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+/**
+ * Creates runtime artifacts for the local binding
+ *
+ * @version $Rev$ $Date$
+ */
+public class LocalBindingBuilder extends BindingBuilderExtension<LocalBindingDefinition> {
+
+ protected Class<LocalBindingDefinition> getBindingType() {
+ return LocalBindingDefinition.class;
+ }
+
+ public ServiceBinding build(ServiceDefinition serviceDefinition,
+ LocalBindingDefinition bindingDefinition,
+ DeploymentContext context) throws BuilderException {
+ return new LocalServiceBinding(serviceDefinition.getUri());
+ }
+
+
+ public ReferenceBinding build(ReferenceDefinition referenceDefinition,
+ LocalBindingDefinition bindingDefinition,
+ DeploymentContext context) throws BuilderException {
+ return new LocalReferenceBinding(referenceDefinition.getUri(), bindingDefinition.getTargetUri());
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalBindingDefinition.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalBindingDefinition.java
new file mode 100644
index 0000000000..9317a47457
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalBindingDefinition.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.core.binding.local;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.model.BindingDefinition;
+
+
+/**
+ * Represents the local by-reference binding
+ *
+ * @version $Rev$ $Date$
+ */
+public class LocalBindingDefinition extends BindingDefinition {
+
+ public LocalBindingDefinition() {
+ }
+
+ public LocalBindingDefinition(URI targetUri) {
+ super(targetUri);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalBindingLoader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalBindingLoader.java
new file mode 100644
index 0000000000..3442f1ca4c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalBindingLoader.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.core.binding.local;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * Loader responsible for handling the local binding
+ *
+ * @version $Rev$ $Date$
+ */
+public class LocalBindingLoader extends LoaderExtension<LocalBindingDefinition> {
+
+ /**
+ * Constructor specifies the registry to register with.
+ *
+ * @param registry the LoaderRegistry this loader should register with
+ */
+ public LocalBindingLoader(@Reference LoaderRegistry registry) {
+ super(registry);
+ }
+
+ public QName getXMLType() {
+ return Wire.LOCAL_BINDING;
+ }
+
+ public LocalBindingDefinition load(
+ ModelObject object,
+ XMLStreamReader reader,
+ DeploymentContext deploymentContext) throws XMLStreamException, LoaderException {
+ String uri = reader.getAttributeValue(null, "uri");
+ if (uri != null) {
+ try {
+ return new LocalBindingDefinition(new URI(uri));
+ } catch (URISyntaxException e) {
+ throw new LoaderException(e);
+ }
+ }
+ return new LocalBindingDefinition();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvoker.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvoker.java
new file mode 100644
index 0000000000..c505ee99ab
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvoker.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.core.binding.local;
+
+import java.util.Map;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * Dispatches a callback invocation to the callback instance
+ *
+ * @version $Rev$ $Date$
+ */
+public class LocalCallbackTargetInvoker extends AbstractLocalTargetInvoker {
+ private Operation operation;
+ private Wire wire;
+
+ public LocalCallbackTargetInvoker(Operation operation, Wire wire) {
+ assert operation != null : "Operation method cannot be null";
+ this.operation = operation;
+ this.wire = wire;
+ }
+
+ public Message invoke(Message msg) throws InvocationRuntimeException {
+ try {
+ return invoke(operation, msg);
+ } catch (Throwable e) {
+ Message faultMsg = new MessageImpl();
+ faultMsg.setBodyWithFault(e);
+ return faultMsg;
+ }
+ }
+
+ private Message invoke(Operation operation, Message msg) throws Throwable {
+ //TODO optimize as this is slow in local invocations
+ Map<Operation<?>, InvocationChain> chains = wire.getCallbackInvocationChains();
+ InvocationChain chain = chains.get(operation);
+ TargetInvoker invoker = chain.getTargetInvoker();
+ return invoke(chain, invoker, msg);
+ }
+
+ @Override
+ public LocalCallbackTargetInvoker clone() throws CloneNotSupportedException {
+ return (LocalCallbackTargetInvoker) super.clone();
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalReferenceBinding.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalReferenceBinding.java
new file mode 100644
index 0000000000..b70df0e23a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalReferenceBinding.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.core.binding.local;
+
+import java.net.URI;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.CoreRuntimeException;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.extension.ReferenceBindingExtension;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * The runtime representaion of the local reference binding
+ *
+ * @version $Rev$ $Date$
+ * @Deprecated
+ */
+public class LocalReferenceBinding extends ReferenceBindingExtension {
+
+ public LocalReferenceBinding(URI name, URI targetUri) throws CoreRuntimeException {
+ super(name, targetUri);
+ }
+
+ public QName getBindingType() {
+ return Wire.LOCAL_BINDING;
+ }
+
+ public TargetInvoker createTargetInvoker(String name, Operation operation)
+ throws TargetInvokerCreationException {
+ if (operation.isCallback()) {
+ return new LocalCallbackTargetInvoker(operation, wire);
+ } else {
+ return new LocalTargetInvoker(operation, wire);
+ }
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, PhysicalOperationDefinition operation)
+ throws TargetInvokerCreationException {
+ return null;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalServiceBinding.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalServiceBinding.java
new file mode 100644
index 0000000000..543a0f53b4
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalServiceBinding.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.core.binding.local;
+
+import java.net.URI;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.CoreRuntimeException;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.extension.ServiceBindingExtension;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * The runtime representaion of the local service binding
+ *
+ * @version $Rev$ $Date$
+ */
+public class LocalServiceBinding extends ServiceBindingExtension {
+
+ public LocalServiceBinding(URI name) throws CoreRuntimeException {
+ super(name);
+ }
+
+ public QName getBindingType() {
+ return Wire.LOCAL_BINDING;
+ }
+
+ public TargetInvoker createTargetInvoker(String name, Operation operation)
+ throws TargetInvokerCreationException {
+ if (operation.isCallback()) {
+ return new LocalCallbackTargetInvoker(operation, getWire());
+ } else {
+ return new LocalTargetInvoker(operation, getWire());
+ }
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, PhysicalOperationDefinition operation)
+ throws TargetInvokerCreationException {
+ return null;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalTargetInvoker.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalTargetInvoker.java
new file mode 100644
index 0000000000..b89a70a9e0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/binding/local/LocalTargetInvoker.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.core.binding.local;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.util.UriHelper;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * Dispatches an invocation through a composite service or reference using the local binding
+ *
+ * @version $Rev$ $Date$
+ */
+public class LocalTargetInvoker extends AbstractLocalTargetInvoker {
+ private InvocationChain chain;
+ private URI fromAddress;
+ private boolean contractHasCallback;
+
+ public LocalTargetInvoker(Operation operation, Wire wire) {
+ assert operation != null;
+ chain = wire.getInvocationChains().get(operation);
+ assert chain != null;
+ if (wire.getSourceUri() != null) {
+ fromAddress = URI.create(UriHelper.getBaseName(wire.getSourceUri()));
+ }
+ contractHasCallback = !wire.getCallbackInvocationChains().isEmpty();
+ }
+
+ @Override
+ public LocalTargetInvoker clone() throws CloneNotSupportedException {
+ return (LocalTargetInvoker) super.clone();
+ }
+
+ public Message invoke(Message msg) throws InvocationRuntimeException {
+ try {
+ TargetInvoker invoker = chain.getTargetInvoker();
+ assert invoker != null;
+ // Pushing the from address only needs to happen in the outbound (forward) direction for callbacks
+ if (contractHasCallback) {
+ //JFM do we need this?
+ msg.pushCallbackUri(fromAddress);
+ }
+
+ return invoke(chain, invoker, msg);
+ } catch (Throwable e) {
+ Message faultMsg = new MessageImpl();
+ faultMsg.setBodyWithFault(e);
+ return faultMsg;
+ }
+ }
+
+
+ public boolean isOptimizable() {
+ return true;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/bootstrap/Bootstrapper.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/bootstrap/Bootstrapper.java
new file mode 100644
index 0000000000..58d182a590
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/bootstrap/Bootstrapper.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.core.bootstrap;
+
+import org.apache.tuscany.spi.builder.Connector;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.deployer.Deployer;
+import org.apache.tuscany.spi.implementation.java.Introspector;
+import org.apache.tuscany.spi.loader.Loader;
+import org.apache.tuscany.spi.loader.PropertyObjectFactory;
+
+import org.apache.tuscany.core.resolver.AutowireResolver;
+import org.apache.tuscany.host.MonitorFactory;
+
+/**
+ * Interface that abstracts the process used to create a running Tuscany system. Implementation of this may provide
+ * different mechanisms for creating the primoridal system components used to boot the core to the level where it can
+ * support end-user applications.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Bootstrapper {
+ /**
+ * Return the MonitorFactory being used by the implementation to provide monitor interfaces for the primordial
+ * components.
+ *
+ * @return the MonitorFactory being used by the bootstrapper
+ */
+ MonitorFactory getMonitorFactory();
+
+ /**
+ * Create a Deployer that can be used to deploy the system definition. This will most likely only support a small
+ * subset of the available programming model.
+ *
+ * @return a new primordial Deployer
+ */
+ Deployer createDeployer();
+
+ /**
+ * Create a Loader for parsing a system definition represented as a XML SCDL file.
+ *
+ * @param propertyFactory the StAXPropertyFactory to be used to parse property values
+ * @param introspector the introspector to be used to extract component type information from a Java class
+ * @return a new prmordial Loader
+ */
+ Loader createLoader(PropertyObjectFactory propertyFactory, Introspector introspector);
+
+ /**
+ * Create a ScopeRegistry that supports the Scopes supported for primordial components
+ *
+ * @return a new primordial ScopeRegistry
+ */
+ ScopeRegistry createScopeRegistry();
+
+ /**
+ * Create a Connector that can wire together primordial components.
+ *
+ * @return a new primordial Connector
+ */
+ Connector getConnector();
+
+ /**
+ * Returns the AutowireResolver that resolves autowire targets
+ *
+ * @return the AutowireResolver that resolves autowire targets
+ */
+ AutowireResolver getAutowireResolver();
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/bootstrap/DefaultBootstrapper.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/bootstrap/DefaultBootstrapper.java
new file mode 100644
index 0000000000..d8650b7ebf
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/bootstrap/DefaultBootstrapper.java
@@ -0,0 +1,257 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.bootstrap;
+
+import javax.xml.stream.XMLInputFactory;
+
+import org.apache.tuscany.spi.builder.Builder;
+import org.apache.tuscany.spi.builder.Connector;
+import org.apache.tuscany.spi.component.ComponentManager;
+import org.apache.tuscany.spi.component.ScopeContainerMonitor;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.deployer.Deployer;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService;
+import org.apache.tuscany.spi.implementation.java.Introspector;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.PropertyObjectFactory;
+
+import org.apache.tuscany.core.binding.local.LocalBindingBuilder;
+import org.apache.tuscany.core.binding.local.LocalBindingDefinition;
+import org.apache.tuscany.core.binding.local.LocalBindingLoader;
+import org.apache.tuscany.core.builder.BuilderRegistryImpl;
+import org.apache.tuscany.core.component.scope.ScopeRegistryImpl;
+import org.apache.tuscany.core.component.scope.CompositeScopeContainer;
+import org.apache.tuscany.core.deployer.DeployerImpl;
+import org.apache.tuscany.core.idl.java.InterfaceJavaLoader;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.IntrospectionRegistryImpl;
+import org.apache.tuscany.core.implementation.composite.CompositeLoader;
+import org.apache.tuscany.core.implementation.composite.SystemCompositeBuilder;
+import org.apache.tuscany.core.implementation.processor.ConstructorProcessor;
+import org.apache.tuscany.core.implementation.processor.DestroyProcessor;
+import org.apache.tuscany.core.implementation.processor.EagerInitProcessor;
+import org.apache.tuscany.core.implementation.processor.HeuristicPojoProcessor;
+import org.apache.tuscany.core.implementation.processor.ImplementationProcessorServiceImpl;
+import org.apache.tuscany.core.implementation.processor.InitProcessor;
+import org.apache.tuscany.core.implementation.processor.MonitorProcessor;
+import org.apache.tuscany.core.implementation.processor.PropertyProcessor;
+import org.apache.tuscany.core.implementation.processor.ReferenceProcessor;
+import org.apache.tuscany.core.implementation.processor.ResourceProcessor;
+import org.apache.tuscany.core.implementation.processor.ScopeProcessor;
+import org.apache.tuscany.core.implementation.processor.ServiceProcessor;
+import org.apache.tuscany.core.implementation.system.builder.SystemComponentBuilder;
+import org.apache.tuscany.core.implementation.system.loader.SystemComponentTypeLoader;
+import org.apache.tuscany.core.implementation.system.loader.SystemCompositeComponentTypeLoader;
+import org.apache.tuscany.core.implementation.system.loader.SystemImplementationLoader;
+import org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation;
+import org.apache.tuscany.core.implementation.system.model.SystemImplementation;
+import org.apache.tuscany.core.loader.ComponentLoader;
+import org.apache.tuscany.core.loader.ComponentTypeElementLoader;
+import org.apache.tuscany.core.loader.IncludeLoader;
+import org.apache.tuscany.core.loader.LoaderRegistryImpl;
+import org.apache.tuscany.core.loader.PropertyLoader;
+import org.apache.tuscany.core.loader.ReferenceLoader;
+import org.apache.tuscany.core.loader.ServiceLoader;
+import org.apache.tuscany.core.property.PropertyObjectFactoryImpl;
+import org.apache.tuscany.core.resolver.AutowireResolver;
+import org.apache.tuscany.host.MonitorFactory;
+
+/**
+ * A default implementation of a Bootstrapper. Please see the documentation on the individual methods for how the
+ * primordial components are created.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultBootstrapper implements Bootstrapper {
+ private final MonitorFactory monitorFactory;
+ private final XMLInputFactory xmlFactory;
+ private final ComponentManager componentManager;
+ private final AutowireResolver resolver;
+ private final Connector connector;
+ private final ScopeRegistry scopeRegistry;
+
+ /**
+ * Create a default bootstrapper.
+ *
+ * @param monitorFactory the MonitorFactory to be used to create monitors for the primordial components
+ * @param xmlFactory the XMLInputFactory to be used by the components to load XML artifacts
+ * @param componentManager the component manager for the runtime instance
+ * @param resolver the autowire resolver for the runtime instance
+ * @param connector the connector for the runtime instance
+ * @param scopeRegistry the scope registry for the runtime instance
+ */
+ public DefaultBootstrapper(MonitorFactory monitorFactory,
+ XMLInputFactory xmlFactory,
+ ComponentManager componentManager,
+ AutowireResolver resolver,
+ Connector connector,
+ ScopeRegistry scopeRegistry
+ ) {
+ this.monitorFactory = monitorFactory;
+ this.xmlFactory = xmlFactory;
+ this.componentManager = componentManager;
+ this.resolver = resolver;
+ this.connector = connector;
+ this.scopeRegistry = scopeRegistry;
+ }
+
+ /**
+ * Returns the MonitorFactory being used by this bootstrapper.
+ *
+ * @return the MonitorFactory being used by this bootstrapper
+ */
+ public MonitorFactory getMonitorFactory() {
+ return monitorFactory;
+ }
+
+ /**
+ * Create primordial deployer that can be used to load the system definition.
+ *
+ * @return the primordial deployer
+ */
+ public Deployer createDeployer() {
+ Builder builder = createBuilder(scopeRegistry);
+ JavaInterfaceProcessorRegistry interfaceIntrospector = new JavaInterfaceProcessorRegistryImpl();
+ Introspector introspector = createIntrospector(interfaceIntrospector);
+ LoaderRegistry loader = createLoader(new PropertyObjectFactoryImpl(), introspector);
+ DeployerImpl deployer = new DeployerImpl(xmlFactory, loader, builder, componentManager, resolver, connector);
+ deployer.setMonitor(getMonitorFactory().getMonitor(ScopeContainerMonitor.class));
+ deployer.setScopeRegistry(scopeRegistry);
+ return deployer;
+ }
+
+ /**
+ * Create a basic ScopeRegistry containing the ScopeContainers that are available to components in the system
+ * definition. The implementation returned only support COMPOSITE scope.
+ *
+ * @return a new ScopeRegistry
+ */
+ public ScopeRegistry createScopeRegistry() {
+ ScopeRegistry scopeRegistry = new ScopeRegistryImpl();
+ CompositeScopeContainer scopeContainer =
+ new CompositeScopeContainer(monitorFactory.getMonitor(ScopeContainerMonitor.class));
+ scopeContainer.start();
+ scopeRegistry.register(scopeContainer);
+ return scopeRegistry;
+ }
+
+ /**
+ * Create a Loader that can be used to parse an XML file containing the SCDL for the system definition. The
+ * following Implementation types are supported: <ul> <li>SystemImplementation</li>
+ * <li>SystemCompositeImplementation</li> </ul> and the following SCDL elements are supported: <ul>
+ * <li>composite</li> <li>component</li> <li>componentType</li> <li>interface.java</li> <li>property</li>
+ * <li>reference</li> <li>service</li> <li>implementation.system</li> </ul> Note the Java component type and the
+ * WSDL interface type are not supported.
+ *
+ * @param propertyFactory the StAXPropertyFactory to be used for parsing Property values
+ * @param introspector the Introspector to be used to inspect component implementations
+ * @return a new StAX XML loader
+ */
+ public LoaderRegistry createLoader(PropertyObjectFactory propertyFactory, Introspector introspector) {
+ LoaderRegistryImpl loaderRegistry =
+ new LoaderRegistryImpl(monitorFactory.getMonitor(LoaderRegistryImpl.Monitor.class));
+
+ // register component type loaders
+ loaderRegistry.registerLoader(SystemImplementation.class, new SystemComponentTypeLoader(introspector));
+ loaderRegistry.registerLoader(SystemCompositeImplementation.class,
+ new SystemCompositeComponentTypeLoader(loaderRegistry));
+
+ // register element loaders
+ registerLoader(loaderRegistry, new ComponentLoader(loaderRegistry, propertyFactory));
+ registerLoader(loaderRegistry, new ComponentTypeElementLoader(loaderRegistry));
+ registerLoader(loaderRegistry, new CompositeLoader(loaderRegistry, null));
+ registerLoader(loaderRegistry, new IncludeLoader(loaderRegistry));
+ JavaInterfaceProcessorRegistryImpl processorRegistry = new JavaInterfaceProcessorRegistryImpl();
+ registerLoader(loaderRegistry, new InterfaceJavaLoader(loaderRegistry, processorRegistry));
+ registerLoader(loaderRegistry, new PropertyLoader(loaderRegistry));
+ registerLoader(loaderRegistry, new ReferenceLoader(loaderRegistry));
+ registerLoader(loaderRegistry, new ServiceLoader(loaderRegistry));
+ registerLoader(loaderRegistry, new SystemImplementationLoader(loaderRegistry));
+ registerLoader(loaderRegistry, new LocalBindingLoader(loaderRegistry));
+ return loaderRegistry;
+ }
+
+ /**
+ * Create new Introspector for extracting a ComponentType definition from a Java class.
+ *
+ * @return a new Introspector
+ */
+ public Introspector createIntrospector(JavaInterfaceProcessorRegistry registry) {
+ ImplementationProcessorService service = new ImplementationProcessorServiceImpl(registry);
+ IntrospectionRegistryImpl.Monitor monitor = monitorFactory.getMonitor(IntrospectionRegistryImpl.Monitor.class);
+ IntrospectionRegistryImpl introspectionRegistry = new IntrospectionRegistryImpl(monitor);
+ introspectionRegistry.registerProcessor(new ConstructorProcessor(service));
+ introspectionRegistry.registerProcessor(new DestroyProcessor());
+ introspectionRegistry.registerProcessor(new InitProcessor());
+ introspectionRegistry.registerProcessor(new EagerInitProcessor());
+ introspectionRegistry.registerProcessor(new ScopeProcessor());
+ introspectionRegistry.registerProcessor(new PropertyProcessor(service));
+ introspectionRegistry.registerProcessor(new ReferenceProcessor(registry));
+ introspectionRegistry.registerProcessor(new ResourceProcessor());
+ introspectionRegistry.registerProcessor(new ServiceProcessor(service));
+ introspectionRegistry.registerProcessor(new HeuristicPojoProcessor(service));
+ introspectionRegistry.registerProcessor(new MonitorProcessor(monitorFactory, service));
+ return introspectionRegistry;
+ }
+
+ /**
+ * Create a new Connector that can be used to wire primordial components together.
+ *
+ * @return a new Connector
+ */
+ public Connector getConnector() {
+ return connector;
+ }
+
+
+ public AutowireResolver getAutowireResolver() {
+ return resolver;
+ }
+
+ /**
+ * Helper method for registering a loader with the registry. The Loader is registered once for the QName returned by
+ * its {@link LoaderExtension#getXMLType()} method.
+ *
+ * @param registry the LoaderRegistry to register with
+ * @param loader the Loader to register
+ */
+ protected void registerLoader(LoaderRegistry registry, LoaderExtension<?> loader) {
+ registry.registerLoader(loader.getXMLType(), loader);
+ }
+
+ /**
+ * Create a Builder that can be used to build the components in the system definition. The default implementation
+ * only supports implementations from the system programming model.
+ *
+ * @param scopeRegistry the ScopeRegistry defining the component scopes that will be supported
+ * @return a new Builder
+ */
+ private Builder createBuilder(ScopeRegistry scopeRegistry) {
+ BuilderRegistryImpl builderRegistry =
+ new BuilderRegistryImpl(scopeRegistry);
+ SystemCompositeBuilder builder = new SystemCompositeBuilder(builderRegistry);
+ builderRegistry.register(SystemCompositeImplementation.class, builder);
+ builderRegistry.register(SystemImplementation.class, new SystemComponentBuilder());
+ builderRegistry.register(LocalBindingDefinition.class, new LocalBindingBuilder());
+ return builderRegistry;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/BuilderRegistryImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/BuilderRegistryImpl.java
new file mode 100644
index 0000000000..33dd2175f9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/BuilderRegistryImpl.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.builder;
+
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.osoa.sca.annotations.EagerInit;
+
+import org.apache.tuscany.spi.builder.BindingBuilder;
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.builder.BuilderRegistry;
+import org.apache.tuscany.spi.builder.ComponentBuilder;
+import org.apache.tuscany.spi.builder.ScopeNotFoundException;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.model.BindingDefinition;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import org.apache.tuscany.core.binding.local.LocalBindingDefinition;
+import org.apache.tuscany.core.implementation.composite.ReferenceImpl;
+import org.apache.tuscany.core.implementation.composite.ServiceImpl;
+
+/**
+ * The default builder registry in the runtime
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+public class BuilderRegistryImpl implements BuilderRegistry {
+ private ScopeRegistry scopeRegistry;
+
+ private final Map<Class<? extends Implementation<?>>, ComponentBuilder<? extends Implementation<?>>> componentBuilders =
+ new HashMap<Class<? extends Implementation<?>>, ComponentBuilder<? extends Implementation<?>>>();
+ private final Map<Class<? extends BindingDefinition>, BindingBuilder<? extends BindingDefinition>> bindingBuilders =
+ new HashMap<Class<? extends BindingDefinition>, BindingBuilder<? extends BindingDefinition>>();
+
+ public BuilderRegistryImpl(@org.osoa.sca.annotations.Reference ScopeRegistry scopeRegistry) {
+ this.scopeRegistry = scopeRegistry;
+ }
+
+ public <I extends Implementation<?>> void register(Class<I> implClass, ComponentBuilder<I> builder) {
+ componentBuilders.put(implClass, builder);
+ }
+
+ public <I extends Implementation<?>> void unregister(Class<I> implClass) {
+ componentBuilders.remove(implClass);
+ }
+
+ public <B extends BindingDefinition> void register(Class<B> implClass, BindingBuilder<B> builder) {
+ bindingBuilders.put(implClass, builder);
+ }
+
+ @SuppressWarnings("unchecked")
+ public <I extends Implementation<?>> Component build(
+ ComponentDefinition<I> componentDefinition,
+ DeploymentContext context) throws BuilderException {
+ Class<?> implClass = componentDefinition.getImplementation().getClass();
+ // noinspection SuspiciousMethodCalls
+ ComponentBuilder<I> componentBuilder = (ComponentBuilder<I>) componentBuilders.get(implClass);
+ if (componentBuilder == null) {
+ String name = implClass.getName();
+ throw new NoRegisteredBuilderException("No builder registered for implementation", name);
+ }
+ Component component = componentBuilder.build(componentDefinition, context);
+ assert component != null;
+ component.setDefaultPropertyValues(componentDefinition.getPropertyValues());
+ Scope scope = componentDefinition.getImplementation().getComponentType().getImplementationScope();
+ if (scope == Scope.SYSTEM || scope == Scope.COMPOSITE) {
+ component.setScopeContainer(context.getCompositeScope());
+ } else {
+ // Check for conversational contract if conversational scope
+ if (scope == Scope.CONVERSATION) {
+ boolean hasConversationalContract = false;
+ ComponentType<ServiceDefinition, ReferenceDefinition, ?> componentType =
+ componentDefinition.getImplementation().getComponentType();
+ Map<String, ServiceDefinition> services = componentType.getServices();
+ for (ServiceDefinition serviceDef : services.values()) {
+ ServiceContract<?> contract = serviceDef.getServiceContract();
+ if (contract.isConversational()) {
+ hasConversationalContract = true;
+ break;
+ }
+ }
+ if (!hasConversationalContract) {
+ String name = implClass.getName();
+ throw new NoConversationalContractException(
+ "No conversational contract for conversational implementation", name);
+ }
+ }
+ // Now it's ok to set the scope container
+ ScopeContainer scopeContainer = scopeRegistry.getScopeContainer(scope);
+ if (scopeContainer == null) {
+ throw new ScopeNotFoundException(scope.toString());
+ }
+ component.setScopeContainer(scopeContainer);
+ }
+ context.getComponents().put(component.getUri(), component);
+ ComponentType<?, ?, ?> componentType = componentDefinition.getImplementation().getComponentType();
+ assert componentType != null : "Component type must be set";
+ return component;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public Service build(ServiceDefinition serviceDefinition, DeploymentContext context) throws BuilderException {
+ URI uri = serviceDefinition.getUri();
+ ServiceContract<?> serviceContract = serviceDefinition.getServiceContract();
+ if (serviceDefinition.getBindings().isEmpty()) {
+ // if no bindings are configured, default to the local binding.
+ // this should be changed to allow runtime selection
+ if (serviceDefinition.getBindings().isEmpty()) {
+ // TODO JFM implement capability for the runtime to choose a binding
+ serviceDefinition.addBinding(new LocalBindingDefinition());
+ }
+ }
+ URI targetUri = serviceDefinition.getTarget();
+ Service service = new ServiceImpl(uri, serviceContract, targetUri);
+ for (BindingDefinition definition : serviceDefinition.getBindings()) {
+ Class<?> bindingClass = definition.getClass();
+ // noinspection SuspiciousMethodCalls
+ BindingBuilder bindingBuilder = bindingBuilders.get(bindingClass);
+ if (bindingBuilder == null) {
+ throw new NoRegisteredBuilderException("No builder registered for type", bindingClass.getName());
+ }
+ ServiceBinding binding = bindingBuilder.build(serviceDefinition, definition, context);
+ service.addServiceBinding(binding);
+ }
+ return service;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Reference build(ReferenceDefinition referenceDefinition, DeploymentContext context) throws BuilderException {
+ URI uri = referenceDefinition.getUri();
+ ServiceContract<?> contract = referenceDefinition.getServiceContract();
+ if (referenceDefinition.getBindings().isEmpty()) {
+ // if no bindings are configured, default to the local binding.
+ // this should be changed to allow runtime selection
+ if (referenceDefinition.getBindings().isEmpty()) {
+ // TODO JFM implement capability for the runtime to choose a binding
+ referenceDefinition.addBinding(new LocalBindingDefinition());
+ }
+ }
+
+ Reference reference = new ReferenceImpl(uri, contract);
+ for (BindingDefinition bindingDefinition : referenceDefinition.getBindings()) {
+ Class<?> bindingClass = bindingDefinition.getClass();
+ // noinspection SuspiciousMethodCalls
+ BindingBuilder bindingBuilder = bindingBuilders.get(bindingClass);
+ ReferenceBinding binding = bindingBuilder.build(referenceDefinition, bindingDefinition, context);
+ reference.addReferenceBinding(binding);
+
+ }
+ return reference;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/ComponentNotFoundException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/ComponentNotFoundException.java
new file mode 100644
index 0000000000..a46e038cb9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/ComponentNotFoundException.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.core.builder;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.WiringException;
+
+/**
+ * Indicates a component was not found during wiring
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentNotFoundException extends WiringException {
+
+ public ComponentNotFoundException(String message, URI name) {
+ super(message, name, name);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java
new file mode 100644
index 0000000000..e2fd652f96
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/ConnectorImpl.java
@@ -0,0 +1,384 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.builder;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import javax.xml.namespace.QName;
+
+import org.osoa.sca.annotations.Constructor;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.builder.Connector;
+import org.apache.tuscany.spi.builder.WiringException;
+import org.apache.tuscany.spi.builder.interceptor.InterceptorBuilderRegistry;
+import org.apache.tuscany.spi.builder.physical.WireAttacherRegistry;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ComponentManager;
+import org.apache.tuscany.spi.component.Invocable;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalInterceptorDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition;
+import org.apache.tuscany.spi.services.work.WorkScheduler;
+import org.apache.tuscany.spi.util.UriHelper;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.WirePostProcessorRegistry;
+
+import org.apache.tuscany.core.wire.InvocationChainImpl;
+import org.apache.tuscany.core.wire.InvokerInterceptor;
+import org.apache.tuscany.core.wire.NonBlockingInterceptor;
+import org.apache.tuscany.core.wire.WireImpl;
+import org.apache.tuscany.core.wire.WireUtils;
+
+/**
+ * The default connector implmentation
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class ConnectorImpl implements Connector {
+ private WirePostProcessorRegistry postProcessorRegistry;
+ private ComponentManager componentManager;
+ private WorkContext workContext;
+ private WorkScheduler scheduler;
+ private InterceptorBuilderRegistry interceptorBuilderRegistry;
+ private WireAttacherRegistry attacherRegistry;
+
+ public ConnectorImpl(ComponentManager componentManager) {
+ this.componentManager = componentManager;
+ }
+
+ @Constructor
+ public ConnectorImpl(
+ @org.osoa.sca.annotations.Reference InterceptorBuilderRegistry interceptorBuilderRegistry,
+ @org.osoa.sca.annotations.Reference WireAttacherRegistry attacherRegistry,
+ @org.osoa.sca.annotations.Reference WirePostProcessorRegistry processorRegistry,
+ @org.osoa.sca.annotations.Reference ComponentManager componentManager,
+ @org.osoa.sca.annotations.Reference WorkScheduler scheduler,
+ @org.osoa.sca.annotations.Reference WorkContext workContext) {
+ this.attacherRegistry = attacherRegistry;
+ this.interceptorBuilderRegistry = interceptorBuilderRegistry;
+ this.postProcessorRegistry = processorRegistry;
+ this.componentManager = componentManager;
+ this.scheduler = scheduler;
+ this.workContext = workContext;
+ }
+
+ /**
+ * <strong>Note this method will not work yet</strong>
+ * <p/>
+ * Wires a source and target component based on a wire defintion
+ *
+ * @param definition the wire definition
+ * @throws WiringException
+ */
+ public void connect(PhysicalWireDefinition definition) throws BuilderException {
+ URI sourceUri = definition.getSourceUri();
+ assert sourceUri != null;
+ URI targetUri = definition.getTargetUri();
+ assert targetUri != null;
+ URI baseSourceUri = UriHelper.getDefragmentedName(sourceUri);
+ URI baseTargetUri = UriHelper.getDefragmentedName(targetUri);
+ Component source = componentManager.getComponent(baseSourceUri);
+ if (source == null) {
+ throw new ComponentNotFoundException("Wire source component not found", baseSourceUri);
+ }
+ Wire wire = createWire(definition);
+
+ PhysicalWireSourceDefinition sourceDefinition = definition.getSource();
+ PhysicalWireTargetDefinition targetDefinition = definition.getTarget();
+ Component target;
+ if (baseTargetUri != null) {
+ target = componentManager.getComponent(baseTargetUri);
+ if (target == null) {
+ throw new ComponentNotFoundException("Wire target component not found", baseTargetUri);
+ }
+ } else {
+ target = null;
+ }
+ attacherRegistry.attachToSource(source, sourceDefinition, target, targetDefinition, wire);
+ attacherRegistry.attachToTarget(source, sourceDefinition, target, targetDefinition, wire);
+ }
+
+ public void connect(ComponentDefinition<? extends Implementation<?>> definition) throws WiringException {
+ URI sourceUri = definition.getUri();
+ Component source = componentManager.getComponent(sourceUri);
+ if (source == null) {
+ throw new ComponentNotFoundException("Source not found", sourceUri);
+ }
+ ComponentType<?, ?, ?> type = definition.getImplementation().getComponentType();
+ if (type instanceof CompositeComponentType) {
+ CompositeComponentType<?, ?, ?> compositeType = (CompositeComponentType<?, ?, ?>) type;
+ for (ComponentDefinition<? extends Implementation<?>> child : compositeType.getComponents().values()) {
+ connect(child);
+ }
+ for (ServiceDefinition child : compositeType.getServices().values()) {
+ connect(child);
+ }
+ for (ReferenceDefinition child : compositeType.getReferences().values()) {
+ connect(child);
+ }
+ }
+ Map<String, ReferenceTarget> targets = definition.getReferenceTargets();
+ for (ReferenceTarget referenceTarget : targets.values()) {
+ List<Wire> wires = new ArrayList<Wire>();
+ String refName = referenceTarget.getReferenceName().getFragment();
+ ReferenceDefinition refDefinition = type.getReferences().get(refName);
+ assert refDefinition != null;
+ List<URI> uris = referenceTarget.getTargets();
+ for (URI uri : uris) {
+ URI targetUri = UriHelper.getDefragmentedName(uri);
+ Component target = componentManager.getComponent(targetUri);
+ if (target == null && !refDefinition.isRequired()) {
+ // a non-required reference, just skip
+ continue;
+ }
+ if (target == null) {
+ throw new ComponentNotFoundException("Target not found", targetUri);
+ }
+ String fragment = uri.getFragment();
+ URI sourceURI = refDefinition.getUri();
+ Wire wire = createWire(sourceURI, uri, refDefinition.getServiceContract(), Wire.LOCAL_BINDING);
+ try {
+ attachInvokers(fragment, wire, source, target);
+ } catch (TargetInvokerCreationException e) {
+ throw new WireCreationException("Error creating invoker", sourceUri, targetUri, e);
+ }
+ if (postProcessorRegistry != null) {
+ postProcessorRegistry.process(wire);
+ }
+ optimize(source, target, wire);
+ wires.add(wire);
+ if (!wire.getCallbackInvocationChains().isEmpty()) {
+ target.attachCallbackWire(wire);
+ }
+ }
+ if (wires.size() > 1) {
+ // attach as a multiplicity
+ source.attachWires(wires);
+ } else if (wires.size() == 1) {
+ // attach as a single wire
+ Wire wire = wires.get(0);
+ source.attachWire(wire);
+ }
+ }
+ }
+
+ /**
+ * @deprecated
+ */
+ protected void connect(ServiceDefinition definition) throws WiringException {
+ URI uri = definition.getUri();
+ URI sourceUri = UriHelper.getDefragmentedName(uri);
+ URI targetUri = definition.getTarget();
+ URI baseTargetUri = UriHelper.getDefragmentedName(targetUri);
+ Component source = componentManager.getComponent(sourceUri);
+ if (source == null) {
+ throw new ComponentNotFoundException("Source not found", sourceUri);
+ }
+ Service service = source.getService(uri.getFragment());
+ if (service == null) {
+ throw new SourceServiceNotFoundException("Service not found on composite", uri);
+ }
+ Component target = componentManager.getComponent(baseTargetUri);
+ if (target == null) {
+ throw new ComponentNotFoundException("Target not found", sourceUri);
+ }
+ ServiceContract<?> contract = definition.getServiceContract();
+ // TODO if no binding, do local
+ for (ServiceBinding binding : service.getServiceBindings()) {
+ Wire wire = createWire(uri, targetUri, contract, binding.getBindingType());
+ binding.setWire(wire);
+ if (postProcessorRegistry != null) {
+ postProcessorRegistry.process(wire);
+ }
+ try {
+ attachInvokers(definition.getTarget().getFragment(), wire, binding, target);
+ } catch (TargetInvokerCreationException e) {
+ throw new WireCreationException("Error creating invoker", sourceUri, baseTargetUri, e);
+ }
+ }
+ }
+
+ /**
+ * @deprecated
+ */
+ protected void connect(ReferenceDefinition definition) throws WiringException {
+ URI uri = definition.getUri();
+ URI sourceUri = UriHelper.getDefragmentedName(uri);
+ Component source = componentManager.getComponent(sourceUri);
+ if (source == null) {
+ throw new ComponentNotFoundException("Source not found", sourceUri);
+ }
+ Reference reference = source.getReference(uri.getFragment());
+ if (reference == null) {
+ throw new SourceServiceNotFoundException("Reference not found on composite", uri);
+ }
+
+ for (ReferenceBinding binding : reference.getReferenceBindings()) {
+ // create wire
+ if (Wire.LOCAL_BINDING.equals(binding.getBindingType())) {
+ URI targetUri = binding.getTargetUri();
+ ServiceContract<?> contract = binding.getBindingServiceContract();
+ QName type = binding.getBindingType();
+ Wire wire = createWire(sourceUri, targetUri, contract, type);
+ binding.setWire(wire);
+ // wire local bindings to their targets
+ Component target = componentManager.getComponent(UriHelper.getDefragmentedName(targetUri));
+ if (target == null) {
+ throw new ComponentNotFoundException("Target not found", sourceUri);
+ }
+ try {
+ attachInvokers(targetUri.getFragment(), wire, binding, target);
+ } catch (TargetInvokerCreationException e) {
+ throw new WireCreationException("Error creating invoker", sourceUri, targetUri, e);
+ }
+ } else {
+ Wire wire = createWire(sourceUri, null, binding.getBindingServiceContract(), binding.getBindingType());
+ if (postProcessorRegistry != null) {
+ postProcessorRegistry.process(wire);
+ }
+ binding.setWire(wire);
+ }
+ }
+ }
+
+ protected Wire createWire(PhysicalWireDefinition definition) throws BuilderException {
+ URI sourceURI = definition.getSourceUri();
+ URI targetUri = definition.getTargetUri();
+ Wire wire = new WireImpl();
+ wire.setSourceUri(sourceURI);
+ wire.setTargetUri(targetUri);
+ for (PhysicalOperationDefinition operation : definition.getOperations()) {
+ InvocationChain chain = new InvocationChainImpl(operation);
+ for (PhysicalInterceptorDefinition interceptorDefinition : operation.getInterceptors()) {
+ Interceptor interceptor = interceptorBuilderRegistry.build(interceptorDefinition);
+ chain.addInterceptor(interceptor);
+ }
+ wire.addInvocationChain(operation, chain);
+ }
+ return wire;
+ }
+
+ protected Wire createWire(URI sourceURI, URI targetUri, ServiceContract<?> contract, QName bindingType) {
+ Wire wire = new WireImpl(bindingType);
+ wire.setSourceContract(contract);
+ wire.setSourceUri(sourceURI);
+ wire.setTargetUri(targetUri);
+ for (Operation<?> operation : contract.getOperations().values()) {
+ InvocationChain chain = new InvocationChainImpl(operation);
+ if (operation.isNonBlocking()) {
+ chain.addInterceptor(new NonBlockingInterceptor(scheduler, workContext));
+ }
+ chain.addInterceptor(new InvokerInterceptor());
+ wire.addInvocationChain(operation, chain);
+
+ }
+ for (Operation<?> operation : contract.getCallbackOperations().values()) {
+ InvocationChain chain = new InvocationChainImpl(operation);
+ if (operation.isNonBlocking()) {
+ chain.addInterceptor(new NonBlockingInterceptor(scheduler, workContext));
+ }
+ chain.addInterceptor(new InvokerInterceptor());
+ wire.addCallbackInvocationChain(operation, chain);
+ }
+ return wire;
+ }
+
+ /**
+ * @Deprecated
+ */
+ private void attachInvokers(String name, Wire wire, Invocable source, Invocable target)
+ throws TargetInvokerCreationException {
+ // TODO section will deleted be replaced when we cut-over to the physical marshallers
+ for (InvocationChain chain : wire.getInvocationChains().values()) {
+ chain.setTargetInvoker(target.createTargetInvoker(name, chain.getOperation()));
+ }
+ for (InvocationChain chain : wire.getCallbackInvocationChains().values()) {
+ chain.setTargetInvoker(source.createTargetInvoker(null, chain.getOperation()));
+ }
+ }
+
+ /**
+ * @Deprecated
+ */
+ protected void optimize(Component source, Component target, Wire wire) {
+ boolean optimizableScopes = isOptimizable(source.getScope(), target.getScope());
+ if (optimizableScopes && target.isOptimizable() && WireUtils.isOptimizable(wire)) {
+ wire.setOptimizable(true);
+ wire.setTarget((AtomicComponent) target);
+ } else {
+ wire.setOptimizable(false);
+ }
+ }
+
+ protected boolean isOptimizable(Scope pReferrer, Scope pReferee) {
+ if (pReferrer == Scope.UNDEFINED
+ || pReferee == Scope.UNDEFINED
+ || pReferrer == Scope.CONVERSATION
+ || pReferee == Scope.CONVERSATION) {
+ return false;
+ }
+ if (pReferee == pReferrer) {
+ return true;
+ } else if (pReferrer == Scope.STATELESS) {
+ return true;
+ } else if (pReferee == Scope.STATELESS) {
+ return false;
+ } else if (pReferrer == Scope.REQUEST && pReferee == Scope.SESSION) {
+ return true;
+ } else if (pReferrer == Scope.REQUEST && pReferee == Scope.COMPOSITE) {
+ return true;
+ } else if (pReferrer == Scope.REQUEST && pReferee == Scope.SYSTEM) {
+ return true;
+ } else if (pReferrer == Scope.SESSION && pReferee == Scope.COMPOSITE) {
+ return true;
+ } else if (pReferrer == Scope.SESSION && pReferee == Scope.SYSTEM) {
+ return true;
+ } else //noinspection SimplifiableIfStatement
+ if (pReferrer == Scope.SYSTEM && pReferee == Scope.COMPOSITE) {
+ // case where a service context points to a composite scoped component
+ return true;
+ } else {
+ return pReferrer == Scope.COMPOSITE && pReferee == Scope.SYSTEM;
+ }
+ }
+} \ No newline at end of file
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/IllegalCallbackException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/IllegalCallbackException.java
new file mode 100644
index 0000000000..183ccea1b8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/IllegalCallbackException.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.core.builder;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.WiringException;
+
+/**
+ * Denotes an illegal callback
+ *
+ * @version $Rev$ $Date$
+ */
+public class IllegalCallbackException extends WiringException {
+
+ public IllegalCallbackException(String message, String identifier, URI sourceUri, URI targetUri) {
+ super(message, identifier, sourceUri, targetUri);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/IncompatibleInterfacesException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/IncompatibleInterfacesException.java
new file mode 100644
index 0000000000..1a9c74aa3b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/IncompatibleInterfacesException.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.core.builder;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.WiringException;
+
+/**
+ * Denotes an attempt to wire incompatible interfaces
+ *
+ * @version $Rev$ $Date$
+ */
+public class IncompatibleInterfacesException extends WiringException {
+
+ public IncompatibleInterfacesException(URI source, URI target) {
+ super("Incompatible source and target interfaces", source, target);
+ }
+
+ public IncompatibleInterfacesException(URI source, URI target, Throwable throwable) {
+ super("Incompatible source and target interfaces", source, target, throwable);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/InvalidSourceTypeException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/InvalidSourceTypeException.java
new file mode 100644
index 0000000000..d9df445530
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/InvalidSourceTypeException.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.core.builder;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.WiringException;
+
+/**
+ * Denotes an invalid source type for a wire
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidSourceTypeException extends WiringException {
+
+ public InvalidSourceTypeException(String message, URI sourceUri, URI targetUri) {
+ super(message, sourceUri, targetUri);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/InvalidTargetTypeException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/InvalidTargetTypeException.java
new file mode 100644
index 0000000000..e3c26c75d2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/InvalidTargetTypeException.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.core.builder;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.WiringException;
+
+/**
+ * Denotes an invalid target service for a wire
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidTargetTypeException extends WiringException {
+
+ public InvalidTargetTypeException(String message, URI sourceUri, URI targetUri) {
+ super(message, sourceUri, targetUri);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/NoBindingException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/NoBindingException.java
new file mode 100644
index 0000000000..c351013297
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/NoBindingException.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.core.builder;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.WiringException;
+
+/**
+ * Denotes no binding was specified for a wire
+ *
+ * @version $Rev$ $Date$
+ */
+public class NoBindingException extends WiringException {
+
+ public NoBindingException(String message, URI sourceUri, URI targetUri) {
+ super(message, sourceUri, targetUri);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/NoCompatibleBindingsException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/NoCompatibleBindingsException.java
new file mode 100644
index 0000000000..3c49767333
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/NoCompatibleBindingsException.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.core.builder;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.WiringException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class NoCompatibleBindingsException extends WiringException {
+
+ public NoCompatibleBindingsException(URI sourceName, URI targetName) {
+ super("No compatible bindings for source and target", sourceName, targetName);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/NoConversationalContractException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/NoConversationalContractException.java
new file mode 100644
index 0000000000..71eb9ebd26
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/NoConversationalContractException.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.core.builder;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+
+/**
+ * Raised when a component has conversational scope but no conversational contract
+ *
+ * @version $Rev: 487877 $ $Date: 2006-12-16 15:32:16 -0500 (Sat, 16 Dec 2006) $
+ */
+public class NoConversationalContractException extends BuilderException {
+
+ public NoConversationalContractException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public NoConversationalContractException(String message) {
+ super(message);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/NoRegisteredBuilderException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/NoRegisteredBuilderException.java
new file mode 100644
index 0000000000..340a20f239
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/NoRegisteredBuilderException.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.core.builder;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+
+/**
+ * Raised when a builder cannot be found for a SCDL entry type
+ *
+ * @version $Rev$ $Date$
+ */
+public class NoRegisteredBuilderException extends BuilderException {
+
+ public NoRegisteredBuilderException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public NoRegisteredBuilderException(String message) {
+ super(message);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/SourceServiceNotFoundException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/SourceServiceNotFoundException.java
new file mode 100644
index 0000000000..7d3d49b937
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/SourceServiceNotFoundException.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.core.builder;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.WiringException;
+
+/**
+ * Indicates the source service of a wire was not found
+ *
+ * @version $Rev$ $Date$
+ */
+public class SourceServiceNotFoundException extends WiringException {
+
+ public SourceServiceNotFoundException(String message, URI sourceName) {
+ super(message, sourceName, null);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/TargetServiceNotFoundException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/TargetServiceNotFoundException.java
new file mode 100644
index 0000000000..f22b421aa7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/TargetServiceNotFoundException.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.core.builder;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.WiringException;
+
+/**
+ * Indicates the target service of a reference was not found
+ *
+ * @version $Rev$ $Date$
+ */
+public class TargetServiceNotFoundException extends WiringException {
+
+ public TargetServiceNotFoundException(String message, URI sourceName, URI targetName) {
+ super(message, sourceName, targetName);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/WireCreationException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/WireCreationException.java
new file mode 100644
index 0000000000..117bb23180
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/WireCreationException.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.core.builder;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.WiringException;
+
+/**
+ * Denotes an error creating a wire
+ *
+ * @version $Rev$ $Date$
+ */
+public class WireCreationException extends WiringException {
+
+ public WireCreationException(String message, URI sourceUri, Throwable e) {
+ super(message, sourceUri, null, e);
+ }
+
+ public WireCreationException(String message, URI sourceUri, URI targetUri, Throwable e) {
+ super(message, sourceUri, targetUri, e);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImpl.java
new file mode 100644
index 0000000000..6f611956be
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImpl.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.core.builder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.WirePostProcessor;
+import org.apache.tuscany.spi.wire.WirePostProcessorRegistry;
+
+/**
+ * The default implementation of a <code>WirePostProcessor</code>
+ *
+ * @version $Rev$ $Date$
+ */
+public class WirePostProcessorRegistryImpl implements WirePostProcessorRegistry {
+
+ private final List<WirePostProcessor> processors = new ArrayList<WirePostProcessor>();
+
+ public void process(Wire wire) {
+ for (WirePostProcessor processor : processors) {
+ processor.process(wire);
+ }
+ }
+
+ public void register(WirePostProcessor processor) {
+ processors.add(processor);
+ }
+
+ public void unregister(WirePostProcessor processor) {
+ processors.remove(processor);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/WiringExceptionFormatter.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/WiringExceptionFormatter.java
new file mode 100644
index 0000000000..661dc8bfea
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/WiringExceptionFormatter.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.core.builder;
+
+import java.io.PrintWriter;
+
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.builder.WiringException;
+
+import org.apache.tuscany.host.monitor.ExceptionFormatter;
+import org.apache.tuscany.host.monitor.FormatterRegistry;
+
+/**
+ * Formats {@link WiringException}s
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+public class WiringExceptionFormatter implements ExceptionFormatter {
+ private FormatterRegistry factory;
+
+ public WiringExceptionFormatter(@Reference FormatterRegistry factory) {
+ this.factory = factory;
+ factory.register(this);
+ }
+
+ public boolean canFormat(Class<?> type) {
+ return WiringException.class.isAssignableFrom(type);
+ }
+
+ @Destroy
+ public void destroy() {
+ factory.unregister(this);
+ }
+
+ public PrintWriter write(PrintWriter writer, Throwable exception) {
+ assert exception instanceof WiringException;
+ WiringException e = (WiringException) exception;
+ e.appendBaseMessage(writer);
+ if (e.getSourceUri() != null) {
+ writer.write("\nSource : " + e.getSourceUri());
+ }
+ if (e.getTargetUri() != null) {
+ writer.write("\nTarget : " + e.getTargetUri());
+ }
+ return writer;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/interceptor/InterceptorBuilderNotFoundException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/interceptor/InterceptorBuilderNotFoundException.java
new file mode 100644
index 0000000000..0bf32a6f98
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/interceptor/InterceptorBuilderNotFoundException.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.core.builder.interceptor;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+
+/**
+ * Thrown when an interceptor builder is not found for an QName
+ *
+ * @version $Rev$ $Date$
+ */
+public class InterceptorBuilderNotFoundException extends BuilderException {
+
+ public InterceptorBuilderNotFoundException(QName name) {
+ super("Interceptor builder not found", name.toString());
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/interceptor/InterceptorBuilderRegistryImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/interceptor/InterceptorBuilderRegistryImpl.java
new file mode 100644
index 0000000000..a009ddfeb6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/interceptor/InterceptorBuilderRegistryImpl.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.core.builder.interceptor;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.builder.interceptor.InterceptorBuilder;
+import org.apache.tuscany.spi.builder.interceptor.InterceptorBuilderRegistry;
+import org.apache.tuscany.spi.model.physical.PhysicalInterceptorDefinition;
+import org.apache.tuscany.spi.wire.Interceptor;
+
+/**
+ * Default implementation of an InterceptorBuilderRegistry
+ *
+ * @version $Rev$ $Date$
+ */
+public class InterceptorBuilderRegistryImpl implements InterceptorBuilderRegistry {
+ private Map<QName, InterceptorBuilder> builders = new ConcurrentHashMap<QName, InterceptorBuilder>();
+
+ public void register(QName name, InterceptorBuilder builder) {
+ builders.put(name, builder);
+ }
+
+ public void unregister(QName name) {
+ builders.remove(name);
+ }
+
+ public Interceptor build(PhysicalInterceptorDefinition definition) throws BuilderException {
+ QName name = definition.getBuilder();
+ InterceptorBuilder builder = builders.get(name);
+ if (builder == null) {
+ throw new InterceptorBuilderNotFoundException(name);
+ }
+ return builder.build(definition);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/DefaultPhysicalComponentBuilderRegistry.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/DefaultPhysicalComponentBuilderRegistry.java
new file mode 100644
index 0000000000..0841fa07f8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/DefaultPhysicalComponentBuilderRegistry.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.core.builder.physical;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.tuscany.spi.builder.BuilderConfigException;
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.builder.physical.PhysicalComponentBuilder;
+import org.apache.tuscany.spi.builder.physical.PhysicalComponentBuilderRegistry;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.model.physical.PhysicalComponentDefinition;
+
+/**
+ * Default map-based implementation of the physical component builder registry.
+ * <p/>
+ * TODO may be we can factor out all the registries into a parameterized one.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultPhysicalComponentBuilderRegistry implements PhysicalComponentBuilderRegistry {
+
+ // Internal cache
+ private Map<Class<?>,
+ PhysicalComponentBuilder<? extends PhysicalComponentDefinition, ? extends Component>> registry =
+ new ConcurrentHashMap<Class<?>,
+ PhysicalComponentBuilder<? extends PhysicalComponentDefinition, ? extends Component>>();
+
+ /**
+ * Registers a physical component builder.
+ *
+ * @param <PCD> Type of the physical component definition.
+ * @param definitionClass Class of the physical component definition.
+ * @param builder Builder for the physical component definition.
+ */
+ public <PCD extends PhysicalComponentDefinition,
+ C extends Component> void register(Class<?> definitionClass, PhysicalComponentBuilder<PCD, C> builder) {
+ registry.put(definitionClass, builder);
+ }
+
+ /**
+ * Builds a physical component from component definition.
+ *
+ * @param componentDefinition Component definition.
+ * @return Component to be built.
+ */
+ @SuppressWarnings("unchecked")
+ public Component build(PhysicalComponentDefinition componentDefinition) throws BuilderException {
+
+ PhysicalComponentBuilder builder = registry.get(componentDefinition.getClass());
+ if(builder == null) {
+ throw new BuilderConfigException("Builder not found for " + componentDefinition.getClass());
+ }
+ return builder.build(componentDefinition);
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/WireAttacherNotFound.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/WireAttacherNotFound.java
new file mode 100644
index 0000000000..dff5b0b29d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/WireAttacherNotFound.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.core.builder.physical;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.WiringException;
+
+/**
+ * Thrown when a WireAttacher cannot be found for a type
+ *
+ * @version $Rev$ $Date$
+ */
+public class WireAttacherNotFound extends WiringException {
+ public WireAttacherNotFound(Class<?> type, URI source, URI target) {
+ super("WireAttacher not registered for type", type.getName(), source, target);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/WireAttacherRegistryImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/WireAttacherRegistryImpl.java
new file mode 100644
index 0000000000..7ee9558df8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/WireAttacherRegistryImpl.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.core.builder.physical;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.tuscany.spi.builder.WiringException;
+import org.apache.tuscany.spi.builder.physical.WireAttacher;
+import org.apache.tuscany.spi.builder.physical.WireAttacherRegistry;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * Default implementation of the WireAttacher
+ *
+ * @version $Rev$ $Date$
+ */
+public class WireAttacherRegistryImpl implements WireAttacherRegistry {
+
+ Map<Class<?>, WireAttacher<? extends Component,
+ ? extends PhysicalWireSourceDefinition,
+ ? extends PhysicalWireTargetDefinition>> attachers =
+ new ConcurrentHashMap<Class<?>, WireAttacher<? extends Component,
+ ? extends PhysicalWireSourceDefinition,
+ ? extends PhysicalWireTargetDefinition>>();
+
+ public <C extends Component, PWSD extends PhysicalWireSourceDefinition, PWTD extends PhysicalWireTargetDefinition>
+ void register(Class<?> clazz, WireAttacher<C, PWSD, PWTD> attacher) {
+ attachers.put(clazz, attacher);
+ }
+
+ @SuppressWarnings("unchecked")
+ public <C extends Component, PWSD extends PhysicalWireSourceDefinition>
+ void attachToSource(C source,
+ PWSD sourceDefinition,
+ Component target,
+ PhysicalWireTargetDefinition targetDefinition,
+ Wire wire) throws WiringException {
+ Class<?> type = sourceDefinition.getClass();
+ WireAttacher attacher = attachers.get(type);
+ if (attacher == null) {
+ throw new WireAttacherNotFound(type, source.getUri(), wire.getTargetUri());
+ }
+ attacher.attachToSource(source, sourceDefinition, target, targetDefinition, wire);
+ }
+
+ @SuppressWarnings("unchecked")
+ public <C extends Component, PWTD extends PhysicalWireTargetDefinition>
+ void attachToTarget(Component source,
+ PhysicalWireSourceDefinition sourceDefinition,
+ C target,
+ PWTD targetDefinition,
+ Wire wire) throws WiringException {
+ Class<?> type = targetDefinition.getClass();
+ WireAttacher attacher = attachers.get(type);
+ if (attacher == null) {
+ throw new WireAttacherNotFound(type, target.getUri(), targetDefinition.getUri());
+ }
+ attacher.attachToTarget(source, sourceDefinition, target, targetDefinition, wire);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/CallableReferenceImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/CallableReferenceImpl.java
new file mode 100644
index 0000000000..e674112a89
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/CallableReferenceImpl.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.core.component;
+
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.Conversation;
+
+import org.apache.tuscany.spi.ObjectFactory;
+
+/**
+ * Base class for implementations of service and callback references.
+ *
+ * @version $Rev$ $Date$
+ * @param <B> the type of the business interface
+ */
+public abstract class CallableReferenceImpl<B> implements CallableReference<B> {
+ private final Class<B> businessInterface;
+ private final ObjectFactory<B> factory;
+
+ protected CallableReferenceImpl(Class<B> businessInterface, ObjectFactory<B> factory) {
+ this.businessInterface = businessInterface;
+ this.factory = factory;
+ }
+
+ public B getService() {
+ return factory.getInstance();
+ }
+
+ public Class<B> getBusinessInterface() {
+ return businessInterface;
+ }
+
+ public boolean isConversational() {
+ return false;
+ }
+
+ public Conversation getConversation() {
+ return null;
+ }
+
+ public Object getCallbackID() {
+ return null;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/CallbackReferenceImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/CallbackReferenceImpl.java
new file mode 100644
index 0000000000..532a8b2bad
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/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.core.component;
+
+import org.apache.tuscany.spi.ObjectFactory;
+
+/**
+ * Default implementation of a callback reference.
+ *
+ * @version $Rev$ $Date$
+ * @param <CB> the type of the business interface
+ */
+public class CallbackReferenceImpl<CB> extends CallableReferenceImpl<CB> {
+ public CallbackReferenceImpl(Class<CB> businessInterface, ObjectFactory<CB> factory) {
+ super(businessInterface, factory);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ComponentContextImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ComponentContextImpl.java
new file mode 100644
index 0000000000..c2da089178
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ComponentContextImpl.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.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;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * 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 (TuscanyRuntimeException e) {
+ throw new ServiceRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+ try {
+ return (R) component.cast(target);
+ } catch (TuscanyRuntimeException e) {
+ throw new ServiceRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public <B> B getService(Class<B> businessInterface, String referenceName) {
+ try {
+ return component.getService(businessInterface, referenceName);
+ } catch (TuscanyRuntimeException e) {
+ throw new ServiceRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String referenceName) {
+ try {
+ return component.getServiceReference(businessInterface, referenceName);
+ } catch (TuscanyRuntimeException e) {
+ throw new ServiceRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public <B> B getProperty(Class<B> type, String propertyName) {
+ try {
+ return component.getProperty(type, propertyName);
+ } catch (TuscanyRuntimeException e) {
+ throw new ServiceRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public <B> ServiceReference<B> createSelfReference(Class<B> businessInterface) {
+ return null;
+ }
+
+ public <B> ServiceReference<B> createSelfReference(Class<B> businessInterface, String serviceName) {
+ return null;
+ }
+
+ public RequestContext getRequestContext() {
+ return null;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ComponentContextProvider.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ComponentContextProvider.java
new file mode 100644
index 0000000000..4237d8b09f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/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.core.component;
+
+import java.net.URI;
+
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.CallableReference;
+
+/**
+ * Interface implemented by Component's that want to expose a ComponentContext.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ComponentContextProvider {
+ ComponentContext getComponentContext();
+
+ URI getUri();
+
+ <B> B getService(Class<B> businessInterface, String referenceName);
+
+ <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String referenceName);
+
+ <B> B getProperty(Class<B> type, String propertyName);
+
+ <B, R extends CallableReference<B>> R cast(B target);
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ComponentManagerImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ComponentManagerImpl.java
new file mode 100644
index 0000000000..76958c88ff
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ComponentManagerImpl.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.core.component;
+
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ComponentManager;
+import org.apache.tuscany.spi.component.DuplicateNameException;
+import org.apache.tuscany.spi.component.RegistrationException;
+import org.apache.tuscany.spi.event.Event;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.services.management.TuscanyManagementService;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+
+import org.apache.tuscany.core.resolver.AutowireResolver;
+
+/**
+ * Default implementation of the component manager
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentManagerImpl implements ComponentManager {
+ private TuscanyManagementService managementService;
+ private AutowireResolver resolver;
+ private Map<URI, Component> components;
+
+ public ComponentManagerImpl() {
+ components = new ConcurrentHashMap<URI, Component>();
+ }
+
+ public ComponentManagerImpl(TuscanyManagementService managementService, AutowireResolver resolver) {
+ this();
+ this.managementService = managementService;
+ this.resolver = resolver;
+ }
+
+ public synchronized void register(Component component) throws RegistrationException {
+ URI uri = component.getUri();
+ assert uri != null;
+ assert !uri.toString().endsWith("/");
+ if (components.containsKey(uri)) {
+ throw new DuplicateNameException(uri.toString());
+ }
+ components.put(uri, component);
+
+ if (managementService != null && component instanceof AtomicComponent) {
+ // FIXME shouldn't it take the canonical name and also not distinguish atomic components?
+ managementService.registerComponent(component.getUri().toString(), component);
+ }
+ }
+
+ public <S, I extends S> void registerJavaObject(URI uri, JavaServiceContract<S> service, I instance)
+ throws RegistrationException {
+ SystemSingletonAtomicComponent<S, I> component =
+ new SystemSingletonAtomicComponent<S, I>(uri, service, instance);
+ register(component);
+ if (resolver != null) {
+ for (ServiceContract contract : component.getServiceContracts()) {
+ resolver.addHostUri(contract, uri);
+ }
+ }
+ }
+
+ public <S, I extends S> void registerJavaObject(URI uri, List<JavaServiceContract<?>> services, I instance)
+ throws RegistrationException {
+ SystemSingletonAtomicComponent<S, I> component =
+ new SystemSingletonAtomicComponent<S, I>(uri, services, instance);
+ register(component);
+ if (resolver != null) {
+ for (ServiceContract contract : component.getServiceContracts()) {
+ resolver.addHostUri(contract, uri);
+ }
+ }
+ }
+
+ public synchronized void unregister(Component component) throws RegistrationException {
+ URI uri = component.getUri();
+ components.remove(uri);
+ }
+
+ public Component getComponent(URI name) {
+ return components.get(name);
+ }
+
+ public void onEvent(Event event) {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ComponentObjectFactory.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ComponentObjectFactory.java
new file mode 100644
index 0000000000..f7d6609251
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ComponentObjectFactory.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.core.component;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.core.implementation.PojoWorkContextTunnel;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ComponentObjectFactory<T, CONTEXT> implements ObjectFactory<T> {
+ private final AtomicComponent<T> component;
+ private final ScopeContainer<CONTEXT> scopeContainer;
+
+ public ComponentObjectFactory(AtomicComponent<T> component, ScopeContainer<CONTEXT> scopeContainer) {
+ this.component = component;
+ this.scopeContainer = scopeContainer;
+ }
+
+ public T getInstance() throws ObjectCreationException {
+ try {
+ WorkContext workContext = PojoWorkContextTunnel.getThreadWorkContext();
+ @SuppressWarnings("unchecked")
+ CONTEXT contextId = (CONTEXT) workContext.getIdentifier(scopeContainer.getScope());
+ return scopeContainer.getWrapper(component, contextId).getInstance();
+ } catch (TargetResolutionException e) {
+ throw new ObjectCreationException(e);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/InstanceFactory.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/InstanceFactory.java
new file mode 100644
index 0000000000..4cbf3c02fc
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/InstanceFactory.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.core.component;
+
+import org.apache.tuscany.spi.component.InstanceWrapper;
+
+/**
+ * Interface for a factory that returns an injected component instance.
+ * This is used by a Component implementation to create new instances of
+ * application implementation objects as determined by the component scope's
+ * lifecycle.
+ * <p/>
+ * The implementation of this interface may be supplied by the user,
+ * may be generated during deployment, or may be dynamic.
+ *
+ * @version $Rev$ $Date$
+ * @param <T> Type of the instance generated by the factory.
+ */
+public interface InstanceFactory<T> {
+ /**
+ * Creates a new instance of the component.
+ * All injected values must be set but any @Init methods must not have been invoked.
+ *
+ * @return A wrapper for the created component instance.
+ */
+ InstanceWrapper<T> newInstance();
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/InstanceFactoryProvider.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/InstanceFactoryProvider.java
new file mode 100644
index 0000000000..a31cdf4707
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/InstanceFactoryProvider.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.core.component;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.ObjectFactory;
+
+import org.apache.tuscany.core.model.physical.instancefactory.InjectionSource;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface InstanceFactoryProvider<T> {
+ /**
+ * Return the implementation class.
+ *
+ * @return the implementation class.
+ */
+ Class<T> getImplementationClass();
+
+ /**
+ * Sets an object factory for an injection site
+ *
+ * @param name the injection site name
+ * @param objectFactory the object factory
+ */
+ void setObjectFactory(InjectionSource name, ObjectFactory<?> objectFactory);
+
+ /**
+ * Returns the type for the injection site
+ *
+ * @param injectionSite the injection site name
+ * @return the required type
+ */
+ Class<?> getMemberType(InjectionSource injectionSite);
+
+ /**
+ * Create an instance factory that can be used to create component instances.
+ *
+ * @return a new instance factory
+ */
+ InstanceFactory<T> createFactory();
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ReflectiveInstanceFactory.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ReflectiveInstanceFactory.java
new file mode 100644
index 0000000000..a4db6d4e75
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ReflectiveInstanceFactory.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.core.component;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.core.component.scope.ReflectiveInstanceWrapper;
+import org.apache.tuscany.core.injection.EventInvoker;
+import org.apache.tuscany.core.injection.Injector;
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReflectiveInstanceFactory<T> implements InstanceFactory<T> {
+ private final Constructor<T> ctr;
+ private final ObjectFactory<?>[] ctrArgs;
+ private final Injector<T>[] injectors;
+ private final EventInvoker<T> initInvoker;
+ private final EventInvoker<T> destroyInvoker;
+
+ public ReflectiveInstanceFactory(Constructor<T> ctr,
+ ObjectFactory<?>[] ctrArgs,
+ Injector<T>[] injectors,
+ EventInvoker<T> initInvoker,
+ EventInvoker<T> destroyInvoker) {
+ this.ctr = ctr;
+ this.ctrArgs = ctrArgs;
+ this.injectors = injectors;
+ this.initInvoker = initInvoker;
+ this.destroyInvoker = destroyInvoker;
+ }
+
+ public InstanceWrapper<T> newInstance() {
+ T instance;
+ try {
+ if (ctrArgs != null) {
+ Object[] args = new Object[ctrArgs.length];
+ for (int i = 0; i < args.length; i++) {
+ args[i] = ctrArgs[i].getInstance();
+ }
+ instance = ctr.newInstance(args);
+ } else {
+ instance = ctr.newInstance();
+ }
+ } catch (InstantiationException e) {
+ String name = ctr.getDeclaringClass().getName();
+ throw new AssertionError("Class is not instantiable [" + name + "]");
+ } catch (IllegalAccessException e) {
+ String name = ctr.getName();
+ throw new AssertionError("Constructor is not accessible [" + name + "]");
+ } catch (
+ InvocationTargetException e) {
+ String name = ctr.getName();
+ throw new ObjectCreationException("Exception thrown by constructor", name, e);
+ }
+
+ if (injectors != null) {
+ for (Injector<T> injector : injectors) {
+ injector.inject(instance);
+ }
+ }
+
+ return new ReflectiveInstanceWrapper<T>(instance, initInvoker, destroyInvoker);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ReflectiveInstanceFactoryProvider.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ReflectiveInstanceFactoryProvider.java
new file mode 100644
index 0000000000..14b737c1a8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ReflectiveInstanceFactoryProvider.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.core.injection.EventInvoker;
+import org.apache.tuscany.core.injection.FieldInjector;
+import org.apache.tuscany.core.injection.Injector;
+import org.apache.tuscany.core.injection.MethodInjector;
+import org.apache.tuscany.core.injection.MethodEventInvoker;
+import org.apache.tuscany.core.model.physical.instancefactory.InjectionSource;
+import org.apache.tuscany.spi.ObjectFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReflectiveInstanceFactoryProvider<T> implements InstanceFactoryProvider<T> {
+ private final Class<T> implementationClass;
+ private final Constructor<T> constructor;
+ private final List<InjectionSource> constructorNames;
+ private final Map<InjectionSource, Member> injectionSites;
+ private final EventInvoker<T> initInvoker;
+ private final EventInvoker<T> destroyInvoker;
+ private final Map<InjectionSource, ObjectFactory<?>> factories = new HashMap<InjectionSource, ObjectFactory<?>>();
+
+ public ReflectiveInstanceFactoryProvider(Constructor<T> constructor,
+ List<InjectionSource> constructorNames,
+ Map<InjectionSource, Member> injectionSites,
+ Method initMethod,
+ Method destroyMethod) {
+ this.implementationClass = constructor.getDeclaringClass();
+ this.constructor = constructor;
+ this.constructorNames = constructorNames;
+ this.injectionSites = injectionSites;
+ this.initInvoker = initMethod == null ? null : new MethodEventInvoker<T>(initMethod);
+ this.destroyInvoker = destroyMethod == null ? null : new MethodEventInvoker<T>(destroyMethod);
+ }
+
+ public void setObjectFactory(InjectionSource name, ObjectFactory<?> objectFactory) {
+ factories.put(name, objectFactory);
+ }
+
+ public Class<?> getMemberType(InjectionSource injectionSource) {
+
+ // TODO How do we decide whether this is a member or constructor arg
+ Member member = injectionSites.get(injectionSource);
+ if(member != null) {
+ if(member instanceof Field) {
+ return ((Field) member).getType();
+ } else {
+ return ((Method) member).getParameterTypes()[0];
+ }
+ } else {
+ int index = constructorNames.indexOf(injectionSource);
+ if(index >= 0) {
+ return constructor.getParameterTypes()[index];
+ }
+ }
+ return null;
+ }
+
+ public Class<T> getImplementationClass() {
+ return implementationClass;
+ }
+
+ public InstanceFactory<T> createFactory() {
+ ObjectFactory<?>[] initArgs = getConstructorArgs();
+ Injector<T>[] injectors = getInjectors();
+ return new ReflectiveInstanceFactory<T>(constructor, initArgs, injectors, initInvoker, destroyInvoker);
+ }
+
+ protected ObjectFactory<?>[] getConstructorArgs() {
+ ObjectFactory<?>[] initArgs = new ObjectFactory<?>[constructorNames.size()];
+ for (int i = 0; i < initArgs.length; i++) {
+ InjectionSource name = constructorNames.get(i);
+ ObjectFactory<?> factory = factories.get(name);
+ assert factory != null;
+ initArgs[i] = factory;
+ }
+ return initArgs;
+ }
+
+ protected Injector<T>[] getInjectors() {
+ // work around JDK1.5 issue with allocating generic arrays
+ @SuppressWarnings("unchecked")
+ Injector<T>[] injectors = (Injector<T>[]) new Injector[injectionSites.size()];
+
+ int i = 0;
+ for (Map.Entry<InjectionSource, Member> entry : injectionSites.entrySet()) {
+ InjectionSource name = entry.getKey();
+ Member site = entry.getValue();
+ ObjectFactory<?> factory = factories.get(name);
+ assert factory != null;
+ if (site instanceof Field) {
+ injectors[i++] = new FieldInjector<T>((Field) site, factory);
+ } else if (site instanceof Method) {
+ injectors[i++] = new MethodInjector<T>((Method) site, factory);
+ } else {
+ throw new AssertionError(String.valueOf(site));
+ }
+ }
+ return injectors;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ScopeIdentifier.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ScopeIdentifier.java
new file mode 100644
index 0000000000..35125b85ef
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/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.core.component;
+
+/**
+ * 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.spi.component.WorkContext
+ */
+public interface ScopeIdentifier {
+
+ /**
+ * Returns the scope id for the request.
+ */
+ Object getIdentifier();
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ServiceReferenceImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ServiceReferenceImpl.java
new file mode 100644
index 0000000000..4d57d3efe0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/ServiceReferenceImpl.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.core.component;
+
+import org.osoa.sca.ServiceReference;
+
+import org.apache.tuscany.spi.ObjectFactory;
+
+/**
+ * Default implementation of a ServiceReference.
+ *
+ * @version $Rev$ $Date$
+ * @param <B> the type of the business interface
+ */
+public class ServiceReferenceImpl<B> extends CallableReferenceImpl<B> implements ServiceReference<B> {
+ public ServiceReferenceImpl(Class<B> businessInterface, ObjectFactory<B> 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/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/SimpleWorkContext.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/SimpleWorkContext.java
new file mode 100644
index 0000000000..b9370664e4
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/SimpleWorkContext.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.core.component;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+import java.util.LinkedList;
+import java.util.ArrayList;
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * A simple WorkContext implementation that provides basic thread-local support for storing work context
+ * information. The implementation is <em>not</em> thread safe.
+ *
+ * @version $Rev$ $Date$
+ */
+public class SimpleWorkContext implements WorkContext {
+ private final Map<Object, Object> identifiers = new HashMap<Object,Object>();
+ private final List<String> serviceNameStack = new ArrayList<String>();
+
+ private LinkedList<URI> callbackUris;
+ private LinkedList<Wire> callbackWires;
+ private Object correlationId;
+ private AtomicComponent currentAtomicComponent;
+
+ public Object getIdentifier(Object type) {
+ return identifiers.get(type);
+ }
+
+ public void setIdentifier(Object type, Object identifier) {
+ identifiers.put(type, identifier);
+ }
+
+ public void clearIdentifier(Object type) {
+ identifiers.remove(type);
+ }
+
+ public void clearIdentifiers() {
+ identifiers.clear();
+ }
+
+ public LinkedList<URI> getCallbackUris() {
+ return callbackUris;
+ }
+
+ public void setCallbackUris(LinkedList<URI> uris) {
+ this.callbackUris = uris;
+ }
+
+ public LinkedList<Wire> getCallbackWires() {
+ return callbackWires;
+ }
+
+ public void setCallbackWires(LinkedList<Wire> wires) {
+ this.callbackWires = wires;
+ }
+
+ public Object getCorrelationId() {
+ return correlationId;
+ }
+
+ public void setCorrelationId(Object correlationId) {
+ this.correlationId = correlationId;
+ }
+
+ public AtomicComponent getCurrentAtomicComponent() {
+ return currentAtomicComponent;
+ }
+
+ public void setCurrentAtomicComponent(AtomicComponent currentAtomicComponent) {
+ this.currentAtomicComponent = currentAtomicComponent;
+ }
+
+ public String getCurrentServiceName() {
+ assert !serviceNameStack.isEmpty();
+ return serviceNameStack.get(serviceNameStack.size()-1);
+ }
+
+ public void pushServiceName(String name) {
+ serviceNameStack.add(name);
+ }
+
+ public String popServiceName() {
+ assert !serviceNameStack.isEmpty();
+ return serviceNameStack.remove(serviceNameStack.size()-1);
+ }
+
+ public void clearServiceNames() {
+ serviceNameStack.clear();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/SystemSingletonAtomicComponent.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/SystemSingletonAtomicComponent.java
new file mode 100644
index 0000000000..872853506e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/SystemSingletonAtomicComponent.java
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.core.injection.SingletonObjectFactory;
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.extension.AbstractComponentExtension;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * An {@link org.apache.tuscany.spi.component.AtomicComponent} used when registering objects directly into a composite
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class SystemSingletonAtomicComponent<S, T extends S> extends AbstractComponentExtension
+ implements AtomicComponent<T> {
+ private T instance;
+ private List<ServiceContract> serviceContracts = new ArrayList<ServiceContract>();
+
+ public SystemSingletonAtomicComponent(URI name, JavaServiceContract<S> contract, T instance) {
+ super(name);
+ this.instance = instance;
+ this.serviceContracts.add(contract);
+ }
+
+ public SystemSingletonAtomicComponent(URI name, List<JavaServiceContract<?>> services, T instance) {
+ super(name);
+ this.instance = instance;
+ for (ServiceContract<?> contract : services) {
+ serviceContracts.add(contract);
+ }
+ }
+
+ public Scope getScope() {
+ return Scope.COMPOSITE;
+ }
+
+ public boolean isEagerInit() {
+ return false;
+ }
+
+ public int getInitLevel() {
+ return 0;
+ }
+
+ public long getMaxIdleTime() {
+ return -1;
+ }
+
+ public long getMaxAge() {
+ return -1;
+ }
+
+ public T getTargetInstance() throws TargetResolutionException {
+ return instance;
+ }
+
+ public Object createInstance() throws ObjectCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeInstance() {
+ throw new UnsupportedOperationException();
+ }
+
+ public InstanceWrapper<T> createInstanceWrapper() throws ObjectCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public ObjectFactory<T> createObjectFactory() {
+ return new SingletonObjectFactory<T>(instance);
+ }
+
+ public boolean isOptimizable() {
+ return true;
+ }
+
+ public void attachWire(Wire wire) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void attachWires(List<Wire> wires) {
+ throw new UnsupportedOperationException();
+ }
+
+ public List<Wire> getWires(String name) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void attachCallbackWire(Wire wire) {
+ throw new UnsupportedOperationException();
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, Operation operation) {
+ return null;
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, PhysicalOperationDefinition operation)
+ throws TargetInvokerCreationException {
+ return null;
+ }
+
+ public List<ServiceContract> getServiceContracts() {
+ return serviceContracts;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/WorkContextImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/WorkContextImpl.java
new file mode 100644
index 0000000000..3eb6e9d3eb
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/WorkContextImpl.java
@@ -0,0 +1,214 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.IdentityHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * An implementation of an {@link org.apache.tuscany.spi.component.WorkContext} that handles event-to-thread
+ * associations using an <code>InheritableThreadLocal</code>
+ *
+ * @version $Rev$ $Date$
+ */
+public class WorkContextImpl implements WorkContext {
+ private static final Object CORRELATION_ID = new Object();
+ private static final Object CALLBACK_URIS = new Object();
+ private static final Object CURRENT_ATOMIC = new Object();
+ private static final Object CURRENT_SERVICE_NAMES = new Object();
+ private static final Object CALLBACK_WIRES = new Object();
+
+ // [rfeng] We cannot use InheritableThreadLocal for message ids here since it's shared by parent and children
+ private ThreadLocal<Map<Object, Object>> workContext = new ThreadLocal<Map<Object, Object>>();
+
+ // [rfeng] Session id requires InheritableThreadLocal
+ private ThreadLocal<Map<Object, Object>> inheritableContext = new InheritableThreadLocal<Map<Object, Object>>();
+
+ public WorkContextImpl() {
+ super();
+ }
+
+ public Object getCorrelationId() {
+ Map<Object, Object> map = workContext.get();
+ if (map == null) {
+ return null;
+ }
+ return map.get(CORRELATION_ID);
+ }
+
+ public void setCorrelationId(Object id) {
+ Map<Object, Object> map = getWorkContextMap();
+ map.put(CORRELATION_ID, id);
+ }
+
+ public AtomicComponent getCurrentAtomicComponent() {
+ Map<Object, Object> map = workContext.get();
+ if (map == null) {
+ return null;
+ }
+ return (AtomicComponent) map.get(CURRENT_ATOMIC);
+ }
+
+ public void setCurrentAtomicComponent(AtomicComponent component) {
+ Map<Object, Object> map = getWorkContextMap();
+ map.put(CURRENT_ATOMIC, component);
+ }
+
+ @SuppressWarnings("unchecked")
+ public LinkedList<URI> getCallbackUris() {
+ Map<Object, Object> map = workContext.get();
+ if (map == null) {
+ return null;
+ }
+ return (LinkedList<URI>) map.get(CALLBACK_URIS);
+ }
+
+ public void setCallbackUris(LinkedList<URI> uris) {
+ Map<Object, Object> map = getWorkContextMap();
+ map.put(CALLBACK_URIS, uris);
+ }
+
+
+ @SuppressWarnings({"unchecked"})
+ public LinkedList<Wire> getCallbackWires() {
+ Map<Object, Object> map = workContext.get();
+ if (map == null) {
+ return null;
+ }
+ return (LinkedList<Wire>) map.get(CALLBACK_WIRES);
+ }
+
+ public void setCallbackWires(LinkedList<Wire> wires) {
+ Map<Object, Object> map = getWorkContextMap();
+ map.put(CALLBACK_WIRES, wires);
+ }
+
+
+ public Object getIdentifier(Object type) {
+ Map<Object, Object> map = inheritableContext.get();
+ if (map == null) {
+ return null;
+ }
+ Object currentId = map.get(type);
+ if (currentId instanceof ScopeIdentifier) {
+ currentId = ((ScopeIdentifier) currentId).getIdentifier();
+ // once we have accessed the id, replace the lazy wrapper
+ map.put(type, currentId);
+ }
+ return currentId;
+ }
+
+ public void setIdentifier(Object type, Object identifier) {
+ Map<Object, Object> map = inheritableContext.get();
+ if (map == null) {
+ map = new IdentityHashMap<Object, Object>();
+ inheritableContext.set(map);
+ }
+ map.put(type, identifier);
+ }
+
+ public void clearIdentifier(Object type) {
+ if (type == null) {
+ return;
+ }
+ Map map = inheritableContext.get();
+ if (map != null) {
+ map.remove(type);
+ }
+ }
+
+ public void clearIdentifiers() {
+ inheritableContext.remove();
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public String popServiceName() {
+ Map<Object, Object> map = inheritableContext.get();
+ if (map == null) {
+ return null;
+ }
+ List<String> stack = (List) map.get(CURRENT_SERVICE_NAMES);
+ if (stack == null || stack.size() < 1) {
+ return null;
+ }
+ String name = stack.remove(stack.size() - 1);
+ if (stack.size() == 0) {
+ // cleanup to avoid leaks
+ map.remove(CURRENT_SERVICE_NAMES);
+ }
+ return name;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public String getCurrentServiceName() {
+ Map<Object, Object> map = inheritableContext.get();
+ if (map == null) {
+ return null;
+ }
+ List<String> stack = (List) map.get(CURRENT_SERVICE_NAMES);
+ if (stack == null || stack.size() < 1) {
+ return null;
+ }
+ return stack.get(stack.size() - 1);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void pushServiceName(String name) {
+ Map<Object, Object> map = inheritableContext.get();
+ List<String> names;
+ if (map == null) {
+ map = new IdentityHashMap<Object, Object>();
+ inheritableContext.set(map);
+ names = new ArrayList<String>();
+ map.put(CURRENT_SERVICE_NAMES, names);
+ } else {
+ names = (List<String>) map.get(CURRENT_SERVICE_NAMES);
+ if (names == null) {
+ names = new ArrayList<String>();
+ map.put(CURRENT_SERVICE_NAMES, names);
+ }
+ }
+ names.add(name);
+ }
+
+ public void clearServiceNames() {
+ Map<Object, Object> map = inheritableContext.get();
+ if (map == null) {
+ return;
+ }
+ map.remove(CURRENT_SERVICE_NAMES);
+ }
+
+ private Map<Object, Object> getWorkContextMap() {
+ Map<Object, Object> map = workContext.get();
+ if (map == null) {
+ map = new IdentityHashMap<Object, Object>();
+ workContext.set(map);
+ }
+ return map;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/AbstractEvent.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/AbstractEvent.java
new file mode 100644
index 0000000000..6d026ca08c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/AbstractEvent.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.core.component.event;
+
+import org.apache.tuscany.spi.event.Event;
+
+/**
+ * A basic implementation of a runtime event
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public abstract class AbstractEvent implements Event {
+ protected Object source;
+
+ public AbstractEvent(Object source) {
+ assert source != null : "Source id was null";
+ this.source = source;
+ }
+
+ public Object getSource() {
+ return source;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/AbstractRequestEvent.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/AbstractRequestEvent.java
new file mode 100644
index 0000000000..762b917600
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/AbstractRequestEvent.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.core.component.event;
+
+/**
+ * Base implementation of a request event
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public abstract class AbstractRequestEvent extends AbstractEvent implements RequestEvent {
+
+ /**
+ * Creates a new event
+ *
+ * @param source the source of the event
+ */
+ public AbstractRequestEvent(Object source) {
+ super(source);
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ComponentEvent.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ComponentEvent.java
new file mode 100644
index 0000000000..7de32a56d0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ComponentEvent.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.core.component.event;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.event.Event;
+
+/**
+ * Implemented by runtime events associated with a component, e.g. lifecycle events
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public interface ComponentEvent extends Event {
+
+ URI getComponentUri();
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ComponentStart.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ComponentStart.java
new file mode 100644
index 0000000000..6be1c88d3f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ComponentStart.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.core.component.event;
+
+import java.net.URI;
+
+/**
+ * Propagated when a component starts
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class ComponentStart extends AbstractEvent implements ComponentEvent {
+
+ 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) {
+ super(source);
+ this.uri = componentURI;
+ }
+
+ public URI getComponentUri() {
+ return uri;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ComponentStop.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ComponentStop.java
new file mode 100644
index 0000000000..ac0a7fd5c0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ComponentStop.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.core.component.event;
+
+import java.net.URI;
+
+/**
+ * Propagated when a component stops
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class ComponentStop extends AbstractEvent implements ComponentEvent {
+
+ 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) {
+ super(source);
+ this.uri = componentUri;
+ }
+
+ public URI getComponentUri() {
+ return uri;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ConversationEnd.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ConversationEnd.java
new file mode 100644
index 0000000000..4a51d970c3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ConversationEnd.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.core.component.event;
+
+/**
+ * Propagated when a conversation session is expired
+ *
+ * @version $$Rev: 430937 $$ $$Date: 2006-08-11 21:17:56 -0400 (Fri, 11 Aug 2006) $$
+ */
+public class ConversationEnd extends ConversationalEvent {
+
+ public ConversationEnd(Object source, Object id) {
+ super(source, id);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ConversationStart.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ConversationStart.java
new file mode 100644
index 0000000000..5725369bf6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ConversationStart.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.core.component.event;
+
+/**
+ * Propagated when a conversation session has started
+ *
+ * @version $$Rev: 430937 $$ $$Date: 2006-08-11 21:17:56 -0400 (Fri, 11 Aug 2006) $$
+ */
+public class ConversationStart extends ConversationalEvent {
+
+ public ConversationStart(Object source, Object id) {
+ super(source, id);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ConversationalEvent.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ConversationalEvent.java
new file mode 100644
index 0000000000..a75086e745
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/ConversationalEvent.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.core.component.event;
+
+/**
+ * A base implementation of conversational session events in the runtime
+ *
+ * @version $$Rev: 430937 $$ $$Date: 2006-08-11 21:17:56 -0400 (Fri, 11 Aug 2006) $$
+ */
+public class ConversationalEvent extends AbstractEvent {
+
+ private Object id;
+
+ public ConversationalEvent(Object source, Object id) {
+ super(source);
+ assert id != null : "Conversation id was null";
+ this.id = id;
+ }
+
+ public Object getId() {
+ return id;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpRequestEnded.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpRequestEnded.java
new file mode 100644
index 0000000000..01bd769031
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpRequestEnded.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.core.component.event;
+
+/**
+ * Propagated when an HTTP-based request has ended.
+ *
+ * @version $$Rev: 430937 $$ $$Date: 2006-08-11 21:17:56 -0400 (Fri, 11 Aug 2006) $$
+ */
+public class HttpRequestEnded extends HttpSessionEvent {
+
+ /**
+ * Creates a new event
+ *
+ * @param source the source of the event
+ * @param id the id of the HTTP session being ended
+ */
+ public HttpRequestEnded(Object source, Object id) {
+ super(source, id);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpRequestStart.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpRequestStart.java
new file mode 100644
index 0000000000..9d0ff80dd7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpRequestStart.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.core.component.event;
+
+/**
+ * Propagated when an HTTP-based request has started
+ *
+ * @version $$Rev: 430937 $$ $$Date: 2006-08-11 21:17:56 -0400 (Fri, 11 Aug 2006) $$
+ */
+public class HttpRequestStart extends HttpSessionEvent {
+
+ /**
+ * Creates a new event
+ *
+ * @param source the source of the event
+ * @param id the id of the HTTP session being ended
+ */
+ public HttpRequestStart(Object source, Object id) {
+ super(source, id);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpSessionEnd.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpSessionEnd.java
new file mode 100644
index 0000000000..7f2bebe94a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpSessionEnd.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.core.component.event;
+
+/**
+ * Propagated when an HTTP-based session is expired
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class HttpSessionEnd extends HttpSessionEvent {
+
+ /**
+ * 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) {
+ super(source, id);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpSessionEvent.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpSessionEvent.java
new file mode 100644
index 0000000000..ed245d0930
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpSessionEvent.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.core.component.event;
+
+/**
+ * A base implementation of HTTP-based session events in the runtime
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public abstract class HttpSessionEvent extends AbstractEvent {
+
+ private Object id;
+
+ public HttpSessionEvent(Object source, Object id) {
+ super(source);
+ assert id != null : "Session id was null";
+ this.id = id;
+ }
+
+
+ public Object getSource() {
+ return source;
+ }
+
+ public Object getId() {
+ return id;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpSessionStart.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpSessionStart.java
new file mode 100644
index 0000000000..7f9c0fadea
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpSessionStart.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.core.component.event;
+
+/**
+ * Propagated when an HTTP-based session has started
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class HttpSessionStart extends HttpSessionEvent {
+
+ /**
+ * Creates a new event
+ *
+ * @param source the source of the event
+ * @param id the id of the HTTP session being ended
+ */
+ public HttpSessionStart(Object source, Object id) {
+ super(source, id);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/RequestEnd.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/RequestEnd.java
new file mode 100644
index 0000000000..25856e86f8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/RequestEnd.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.core.component.event;
+
+/**
+ * Propagated when a request completes or is ended
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class RequestEnd extends AbstractRequestEvent {
+
+ /**
+ * Creates a new event
+ *
+ * @param source the source of the event
+ */
+ public RequestEnd(Object source) {
+ super(source);
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/RequestEvent.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/RequestEvent.java
new file mode 100644
index 0000000000..9a6d767236
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/RequestEvent.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.core.component.event;
+
+/**
+ * Implemented by runtime events associated request
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public interface RequestEvent {
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/RequestStart.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/RequestStart.java
new file mode 100644
index 0000000000..466f52551a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/event/RequestStart.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.core.component.event;
+
+/**
+ * Propagated when a request is started in the runtime
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class RequestStart extends AbstractRequestEvent {
+
+ /**
+ * Creates a new event
+ *
+ * @param source the source of the event
+ */
+ public RequestStart(Object source) {
+ super(source);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/IFProviderBuilder.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/IFProviderBuilder.java
new file mode 100644
index 0000000000..1e264ba209
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/IFProviderBuilder.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.core.component.instancefactory;
+
+import org.apache.tuscany.core.component.InstanceFactoryProvider;
+import org.apache.tuscany.spi.model.physical.InstanceFactoryProviderDefinition;
+
+/**
+ * Interface for building instance factories.
+ *
+ * @version $Revision$ $Date$
+ */
+public interface IFProviderBuilder<IFP extends InstanceFactoryProvider,
+ IFPD extends InstanceFactoryProviderDefinition> {
+
+ /**
+ * Builds an instance factory provider from provider definition.
+ *
+ * @param ifpd Instance factory provider definition.
+ * @param cl Classloader to use.
+ * @return Instance factory provider.
+ */
+ IFP build(IFPD ifpd, ClassLoader cl) throws IFProviderBuilderException;
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/IFProviderBuilderException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/IFProviderBuilderException.java
new file mode 100644
index 0000000000..80e992b5b1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/IFProviderBuilderException.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.core.component.instancefactory;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+
+/**
+ * The builder exception for IF provider.
+ *
+ * @version $Revision$ $Date$
+ *
+ */
+@SuppressWarnings("serial")
+public class IFProviderBuilderException extends BuilderException {
+
+ /**
+ * Initializes the message.
+ * @param message Initializes the message.
+ */
+ public IFProviderBuilderException(String message) {
+ super(message);
+ }
+
+ /**
+ * Initializes the causer.
+ * @param cause Initializes the cause.
+ */
+ public IFProviderBuilderException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/IFProviderBuilderRegistry.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/IFProviderBuilderRegistry.java
new file mode 100644
index 0000000000..cb1e19d004
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/IFProviderBuilderRegistry.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.core.component.instancefactory;
+
+import org.apache.tuscany.core.component.InstanceFactoryProvider;
+import org.apache.tuscany.spi.model.physical.InstanceFactoryProviderDefinition;
+
+/**
+ * Registry for instance factory builders.
+ *
+ * @version $Revision$ $Date: 2007-03-12 22:26:18 +0000 (Mon, 12 Mar
+ * 2007) $
+ */
+public interface IFProviderBuilderRegistry {
+
+ /**
+ * Registers an instance factory provider builder.
+ *
+ * @param ifpdClass Instance factory provider definition class.
+ * @param builder Instance factory provider builder.
+ */
+ <IFPD extends InstanceFactoryProviderDefinition> void register(Class<IFPD> ifpdClass,
+ IFProviderBuilder<?, IFPD> builder);
+
+ /**
+ * Builds an instnace factory provider from a definition.
+ *
+ * @param providerDefinition Provider definition.
+ * @param cl Clasloader to use.
+ * @return Instance factory provider.
+ * @param <T> the type of instance the InstanceFactory creates
+ */
+ <T> InstanceFactoryProvider<T> build(InstanceFactoryProviderDefinition<T> providerDefinition, ClassLoader cl)
+ throws IFProviderBuilderException;
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/impl/AbstractIFProviderBuilder.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/impl/AbstractIFProviderBuilder.java
new file mode 100644
index 0000000000..e76f1e65e3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/impl/AbstractIFProviderBuilder.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.core.component.instancefactory.impl;
+
+import org.apache.tuscany.core.component.InstanceFactoryProvider;
+import org.apache.tuscany.core.component.instancefactory.IFProviderBuilder;
+import org.apache.tuscany.core.component.instancefactory.IFProviderBuilderRegistry;
+import org.apache.tuscany.spi.model.physical.InstanceFactoryProviderDefinition;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * Abstarct implementation that supportes registration.
+ *
+ * @version $Revision$ $Date$
+ */
+public abstract class AbstractIFProviderBuilder<IFP extends InstanceFactoryProvider, IFPD extends InstanceFactoryProviderDefinition>
+ implements IFProviderBuilder<IFP, IFPD> {
+
+ /**
+ * Returns the IFPD class.
+ * @return IFPD class.
+ */
+ protected abstract Class<IFPD> getIfpdClass();
+
+ /**
+ * Injects the builder registry.
+ * @param registry The builder registry.
+ */
+ @Reference
+ public void setBuilderRegistry(IFProviderBuilderRegistry registry) {
+ registry.register(getIfpdClass(), this);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/impl/DefaultIFProviderBuilderRegistry.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/impl/DefaultIFProviderBuilderRegistry.java
new file mode 100644
index 0000000000..7b8d4f2190
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/impl/DefaultIFProviderBuilderRegistry.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.core.component.instancefactory.impl;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.tuscany.core.component.InstanceFactoryProvider;
+import org.apache.tuscany.core.component.instancefactory.IFProviderBuilder;
+import org.apache.tuscany.core.component.instancefactory.IFProviderBuilderException;
+import org.apache.tuscany.core.component.instancefactory.IFProviderBuilderRegistry;
+import org.apache.tuscany.spi.model.physical.InstanceFactoryProviderDefinition;
+
+/**
+ * Default implementation of the registry.
+ *
+ * @version $Revison$ $Date$
+ */
+public class DefaultIFProviderBuilderRegistry implements IFProviderBuilderRegistry {
+
+ // Internal cache
+ private Map<Class<?>, IFProviderBuilder<? extends InstanceFactoryProvider, ? extends InstanceFactoryProviderDefinition>> registry =
+ new ConcurrentHashMap<Class<?>, IFProviderBuilder<? extends InstanceFactoryProvider, ? extends InstanceFactoryProviderDefinition>>();
+
+ /**
+ * Builds an instnace factory provider from a definition.
+ *
+ * @param providerDefinition Provider definition.
+ * @param cl Clasloader to use.
+ * @return Instance factory provider.
+ */
+ @SuppressWarnings("unchecked")
+ public InstanceFactoryProvider build(InstanceFactoryProviderDefinition providerDefinition, ClassLoader cl)
+ throws IFProviderBuilderException {
+
+ IFProviderBuilder builder = registry.get(providerDefinition.getClass());
+ if(builder == null) {
+ throw new IFProviderBuilderException("No registered builder for " + providerDefinition.getClass());
+ }
+ // TODO Auto-generated method stub
+ return builder.build(providerDefinition, cl);
+ }
+
+ /**
+ * Registers the builder.
+ */
+ public <IFPD extends InstanceFactoryProviderDefinition> void register(Class<IFPD> ifpdClass, IFProviderBuilder<?, IFPD> builder) {
+ registry.put(ifpdClass, builder);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/impl/ObjectFactoryUtil.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/impl/ObjectFactoryUtil.java
new file mode 100644
index 0000000000..22dea36c83
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/impl/ObjectFactoryUtil.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.core.component.instancefactory.impl;
+
+import java.beans.PropertyEditor;
+import java.beans.PropertyEditorManager;
+
+import org.apache.tuscany.core.injection.SingletonObjectFactory;
+import org.apache.tuscany.spi.ObjectFactory;
+
+/**
+ * Utility class for object factory.
+ *
+ * @version $Revision$ $Date$
+ */
+public class ObjectFactoryUtil {
+
+ private ObjectFactoryUtil() {
+ }
+
+ /**
+ * Create an object factory for the type.
+ *
+ * @param <T>
+ * @param text Property text.
+ * @param type Property type.
+ * @return Object factory.
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> ObjectFactory<T> create(String text, Class<T> type) {
+
+ T value = null;
+ if (String.class.equals(type)) {
+ value = type.cast(text);
+ }
+
+ PropertyEditor editor = PropertyEditorManager.findEditor(type);
+ if(editor != null) {
+ editor.setAsText(text);
+ value = (T) editor.getValue();
+ }
+ return new SingletonObjectFactory<T>(value);
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/impl/ReflectiveIFProviderBuilder.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/impl/ReflectiveIFProviderBuilder.java
new file mode 100644
index 0000000000..e48107b09b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/instancefactory/impl/ReflectiveIFProviderBuilder.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.component.instancefactory.impl;
+
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.annotation.ElementType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.osoa.sca.annotations.EagerInit;
+
+import org.apache.tuscany.core.component.ReflectiveInstanceFactoryProvider;
+import org.apache.tuscany.core.component.instancefactory.IFProviderBuilderException;
+import org.apache.tuscany.core.model.physical.instancefactory.InjectionSiteMapping;
+import org.apache.tuscany.core.model.physical.instancefactory.InjectionSource;
+import org.apache.tuscany.core.model.physical.instancefactory.MemberSite;
+import org.apache.tuscany.core.model.physical.instancefactory.ReflectiveIFProviderDefinition;
+import org.apache.tuscany.spi.ObjectFactory;
+
+/**
+ * IF provider builder for reflective IF provider.
+ *
+ * @version $Date$ $Revision$
+ */
+@EagerInit
+public class ReflectiveIFProviderBuilder<T> extends
+ AbstractIFProviderBuilder<ReflectiveInstanceFactoryProvider<T>, ReflectiveIFProviderDefinition> {
+
+ @Override
+ protected Class<ReflectiveIFProviderDefinition> getIfpdClass() {
+ return ReflectiveIFProviderDefinition.class;
+ }
+
+ @SuppressWarnings("unchecked")
+ public ReflectiveInstanceFactoryProvider<T> build(ReflectiveIFProviderDefinition ifpd, ClassLoader cl)
+ throws IFProviderBuilderException {
+
+ try {
+
+ Class implClass = cl.loadClass(ifpd.getImplementationClass());
+
+ Constructor ctr = getConstructor(ifpd, cl, implClass);
+
+ Method initMethod = getCallBackMethod(implClass, ifpd.getInitMethod());
+
+ Method destroyMethod = getCallBackMethod(implClass, ifpd.getDestroyMethod());
+
+ List<InjectionSource> ctrInjectSites = ifpd.getCdiSources();
+
+ Map<InjectionSource, Member> injectionSites = getInjectionSites(ifpd, implClass);
+ ReflectiveInstanceFactoryProvider<T> rifp = new ReflectiveInstanceFactoryProvider<T>(ctr,
+ ctrInjectSites,
+ injectionSites,
+ initMethod,
+ destroyMethod);
+
+ Map<InjectionSource, String> propertyValues = ifpd.getPropertyValues();
+ for(InjectionSource source : propertyValues.keySet()) {
+ Class<?> type = rifp.getMemberType(source);
+ String propertyValue = propertyValues.get(source);
+ ObjectFactory<?> factory = ObjectFactoryUtil.create(propertyValue, type);
+ rifp.setObjectFactory(source, factory);
+ }
+ return rifp;
+
+ } catch (ClassNotFoundException ex) {
+ throw new IFProviderBuilderException(ex);
+ } catch (NoSuchMethodException ex) {
+ throw new IFProviderBuilderException(ex);
+ } catch (NoSuchFieldException ex) {
+ throw new IFProviderBuilderException(ex);
+ } catch (IntrospectionException ex) {
+ throw new IFProviderBuilderException(ex);
+ }
+ }
+
+ /*
+ * Get injection sites.
+ */
+ private Map<InjectionSource, Member> getInjectionSites(ReflectiveIFProviderDefinition ifpd, Class implClass)
+ throws NoSuchFieldException, IntrospectionException, IFProviderBuilderException {
+
+ Map<InjectionSource, Member> injectionSites = new HashMap<InjectionSource, Member>();
+ for (InjectionSiteMapping injectionSite : ifpd.getInjectionSites()) {
+
+ InjectionSource source = injectionSite.getSource();
+ MemberSite memberSite = injectionSite.getSite();
+ ElementType elementType = memberSite.getElementType();
+ String name = memberSite.getName();
+
+ Member member = null;
+ if (memberSite.getElementType() == ElementType.FIELD) {
+ member = implClass.getDeclaredField(name);
+ } else if (elementType == ElementType.METHOD) {
+ // FIXME look up directly based on signature sent in RIFPD
+ Method[] methods = implClass.getMethods();
+ for (Method method : methods) {
+ if (name.equals(method.getName())) {
+ member = method;
+ break;
+ }
+ }
+ }
+ if (member == null) {
+ throw new IFProviderBuilderException("Unknown injection site " + name);
+ }
+ injectionSites.put(source, member);
+ }
+ return injectionSites;
+ }
+
+ private Method getCallBackMethod(Class<?> implClass, String name) throws NoSuchMethodException {
+ return name == null ? null : implClass.getMethod(name);
+ }
+
+ /*
+ * Gets the matching constructor.
+ */
+ private Constructor getConstructor(ReflectiveIFProviderDefinition ifpd, ClassLoader cl, Class implClass)
+ throws ClassNotFoundException, NoSuchMethodException {
+ List<String> argNames = ifpd.getConstructorArguments();
+ Class[] ctrArgs = new Class[argNames.size()];
+ for (int i = 0; i < ctrArgs.length; i++) {
+ ctrArgs[i] = cl.loadClass(argNames.get(i));
+ }
+ return implClass.getDeclaredConstructor(ctrArgs);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/AbstractScopeContainer.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/AbstractScopeContainer.java
new file mode 100644
index 0000000000..7fa8765426
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/AbstractScopeContainer.java
@@ -0,0 +1,265 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.AbstractLifecycle;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.GroupInitializationException;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.PersistenceException;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeContainerMonitor;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.component.TargetDestructionException;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.event.Event;
+import org.apache.tuscany.spi.model.Scope;
+
+/**
+ * Implements functionality common to scope contexts.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractScopeContainer<KEY> extends AbstractLifecycle
+ implements ScopeContainer<KEY> {
+
+ private static final Comparator<AtomicComponent<?>> COMPARATOR = new Comparator<AtomicComponent<?>>() {
+ public int compare(AtomicComponent<?> o1, AtomicComponent<?> o2) {
+ return o1.getInitLevel() - o2.getInitLevel();
+ }
+ };
+
+ private final Scope scope;
+ protected final ScopeContainerMonitor monitor;
+
+ protected final Map<AtomicComponent<?>, URI> componentGroups =
+ new ConcurrentHashMap<AtomicComponent<?>, URI>();
+
+ protected final Map<KEY, URI> contextGroups = new ConcurrentHashMap<KEY, URI>();
+
+ // the queue of components to eagerly initialize in each group
+ protected final Map<URI, List<AtomicComponent<?>>> initQueues =
+ new HashMap<URI, List<AtomicComponent<?>>>();
+
+ // the queue of instanceWrappers to destroy, in the order that their instances were created
+ protected final Map<KEY, List<InstanceWrapper<?>>> destroyQueues =
+ new ConcurrentHashMap<KEY, List<InstanceWrapper<?>>>();
+
+ public AbstractScopeContainer(Scope scope, ScopeContainerMonitor monitor) {
+ this.scope = scope;
+ this.monitor = monitor;
+ }
+
+ public Scope getScope() {
+ return scope;
+ }
+
+ @Reference
+ public void setScopeRegistry(ScopeRegistry scopeRegistry) {
+ scopeRegistry.register(this);
+ }
+
+ @Init
+ 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);
+ }
+
+ @Destroy
+ public synchronized void stop() {
+ int lifecycleState = getLifecycleState();
+ if (lifecycleState != RUNNING) {
+ throw new IllegalStateException("Scope in wrong state [" + lifecycleState + "]");
+ }
+ setLifecycleState(STOPPED);
+ componentGroups.clear();
+ contextGroups.clear();
+ synchronized (initQueues) {
+ initQueues.clear();
+ }
+ destroyQueues.clear();
+ }
+
+ protected void checkInit() {
+ if (getLifecycleState() != RUNNING) {
+ throw new IllegalStateException("Scope container not running [" + getLifecycleState() + "]");
+ }
+ }
+
+ public void onEvent(Event event) {
+ }
+
+ public <T> void register(AtomicComponent<T> component, URI groupId) {
+ checkInit();
+ if (component.isEagerInit()) {
+ componentGroups.put(component, groupId);
+ synchronized (initQueues) {
+ List<AtomicComponent<?>> initQueue = initQueues.get(groupId);
+ if (initQueue == null) {
+ initQueue = new ArrayList<AtomicComponent<?>>();
+ initQueues.put(groupId, initQueue);
+ }
+ // FIXME it would be more efficient to binary search and then insert
+ initQueue.add(component);
+ Collections.sort(initQueue, COMPARATOR);
+ }
+ }
+ }
+
+ public <T> void unregister(AtomicComponent<T> component) {
+ if (component.isEagerInit()) {
+ URI groupId = componentGroups.remove(component);
+ synchronized (initQueues) {
+ List<AtomicComponent<?>> initQueue = initQueues.get(groupId);
+ initQueue.remove(component);
+ if (initQueue.isEmpty()) {
+ initQueues.remove(groupId);
+ }
+ }
+ }
+ }
+
+ public void startContext(KEY contextId, URI groupId) throws GroupInitializationException {
+ assert !contextGroups.containsKey(contextId);
+ contextGroups.put(contextId, groupId);
+ destroyQueues.put(contextId, new ArrayList<InstanceWrapper<?>>());
+
+ // get and clone initialization queue
+ List<AtomicComponent<?>> initQueue;
+ synchronized (initQueues) {
+ initQueue = initQueues.get(groupId);
+ if (initQueue != null) {
+ initQueue = new ArrayList<AtomicComponent<?>>(initQueue);
+ }
+ }
+ if (initQueue != null) {
+ initializeComponents(contextId, initQueue);
+ }
+ }
+
+ public void stopContext(KEY contextId) {
+ assert contextGroups.containsKey(contextId);
+ shutdownComponents(destroyQueues.get(contextId));
+ contextGroups.remove(contextId);
+ destroyQueues.remove(contextId);
+ }
+
+ public <T> InstanceWrapper<T> getWrapper(AtomicComponent<T> component, KEY contextId)
+ throws TargetResolutionException {
+ return null;
+ }
+
+ public <T> InstanceWrapper<T> getAssociatedWrapper(AtomicComponent<T> component, KEY contextId)
+ throws TargetResolutionException {
+ return null;
+ }
+
+ public <T> void returnWrapper(AtomicComponent<T> component, InstanceWrapper<T> wrapper, KEY contextId)
+ throws TargetDestructionException {
+ }
+
+ public <T> void remove(AtomicComponent<T> component) throws PersistenceException {
+ throw new UnsupportedOperationException("Scope does not support persistence");
+ }
+
+ /**
+ * Initialise an ordered list of components.
+ * The list is traversed in order and the getWrapper() method called for each to
+ * associate an instance with the supplied context.
+ *
+ * @param contextId the contextId to associated with the component instances
+ * @param components the components to be initialized
+ * @throws GroupInitializationException if one or more components threw an exception during initialization
+ */
+ protected void initializeComponents(KEY contextId, List<AtomicComponent<?>> components)
+ throws GroupInitializationException {
+ List<Exception> causes = null;
+ for (AtomicComponent<?> component : components) {
+ try {
+ getWrapper(component, contextId);
+
+ } catch (Exception e) {
+ if (causes == null) {
+ causes = new ArrayList<Exception>();
+ }
+ causes.add(e);
+ }
+ }
+ if (causes != null) {
+ throw new GroupInitializationException(String.valueOf(contextId), causes);
+ }
+ }
+
+ /**
+ * Shut down an ordered list of instances.
+ * The list passed to this method is treated as a live, mutable list
+ * so any instances added to this list as shutdown is occuring will also be shut down.
+ *
+ * @param instances the list of instances to shutdown
+ */
+ protected void shutdownComponents(List<InstanceWrapper<?>> instances) {
+ while (true) {
+ InstanceWrapper<?> toDestroy;
+ synchronized (instances) {
+ if (instances.size() == 0) {
+ return;
+ }
+ toDestroy = instances.remove(instances.size() - 1);
+ }
+ try {
+ toDestroy.stop();
+ } catch (TargetDestructionException e) {
+ // log the error from destroy but continue
+ monitor.destructionError(e);
+ }
+ }
+ }
+
+ public String toString() {
+ return "In state [" + super.toString() + ']';
+ }
+
+ /**
+ * 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 <T> InstanceWrapper<T> createInstance(AtomicComponent<T> component) throws TargetResolutionException {
+ return component.createInstanceWrapper();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/CompositeScopeContainer.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/CompositeScopeContainer.java
new file mode 100644
index 0000000000..1a5dbcdcd4
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/CompositeScopeContainer.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.core.component.scope;
+
+import java.net.URI;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Service;
+
+import org.apache.tuscany.api.annotation.Monitor;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.ScopeContainerMonitor;
+import org.apache.tuscany.spi.component.TargetDestructionException;
+import org.apache.tuscany.spi.component.TargetInitializationException;
+import org.apache.tuscany.spi.component.TargetNotFoundException;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.model.Scope;
+
+/**
+ * A scope context which manages atomic component instances keyed by composite
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+@Service(ScopeContainer.class)
+public class CompositeScopeContainer<KEY> extends AbstractScopeContainer<KEY> {
+ private static final InstanceWrapper<Object> EMPTY = new InstanceWrapper<Object>() {
+ public Object getInstance() {
+ return null;
+ }
+
+ public boolean isStarted() {
+ return true;
+ }
+
+ public void start() throws TargetInitializationException {
+
+ }
+
+ public void stop() throws TargetDestructionException {
+
+ }
+ };
+
+ // there is one instance per component so we can index directly
+ private final Map<AtomicComponent<?>, InstanceWrapper<?>> instanceWrappers =
+ new ConcurrentHashMap<AtomicComponent<?>, InstanceWrapper<?>>();
+
+ public CompositeScopeContainer(@Monitor ScopeContainerMonitor monitor) {
+ super(Scope.COMPOSITE, monitor);
+ }
+
+ public <T> void register(AtomicComponent<T> component, URI groupId) {
+ super.register(component, groupId);
+ instanceWrappers.put(component, EMPTY);
+ }
+
+ public <T> void unregister(AtomicComponent<T> component) {
+ // FIXME should this component be destroyed already or do we need to stop it?
+ instanceWrappers.remove(component);
+ super.unregister(component);
+ }
+
+ public synchronized void stop() {
+ super.stop();
+ instanceWrappers.clear();
+ }
+
+ public <T> InstanceWrapper<T> getWrapper(AtomicComponent<T> component, KEY contextId)
+ throws TargetResolutionException {
+ assert instanceWrappers.containsKey(component);
+ @SuppressWarnings("unchecked")
+ InstanceWrapper<T> wrapper = (InstanceWrapper<T>) instanceWrappers.get(component);
+ if (wrapper == EMPTY) {
+ // FIXME is there a potential race condition here that may result in two instances being created
+ wrapper = createInstance(component);
+ instanceWrappers.put(component, wrapper);
+ wrapper.start();
+ destroyQueues.get(contextId).add(wrapper);
+ }
+ return wrapper;
+ }
+
+ public <T> InstanceWrapper<T> getAssociatedWrapper(AtomicComponent<T> component, KEY contextId)
+ throws TargetResolutionException {
+ assert instanceWrappers.containsKey(component);
+ @SuppressWarnings("unchecked")
+ InstanceWrapper<T> wrapper = (InstanceWrapper<T>) instanceWrappers.get(component);
+ if (wrapper == EMPTY) {
+ throw new TargetNotFoundException(component.getUri().toString());
+ }
+ return wrapper;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainer.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainer.java
new file mode 100644
index 0000000000..2d9d3d938c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainer.java
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.PersistenceException;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeContainerMonitor;
+import org.apache.tuscany.spi.component.TargetDestructionException;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.event.Event;
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.services.store.Store;
+import org.apache.tuscany.spi.services.store.StoreExpirationEvent;
+import org.apache.tuscany.spi.services.store.StoreReadException;
+import org.apache.tuscany.spi.services.store.StoreWriteException;
+
+/**
+ * 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 WorkContext workContext;
+ private final Store nonDurableStore;
+
+ public ConversationalScopeContainer(Store store, WorkContext workContext, final ScopeContainerMonitor monitor) {
+ super(Scope.CONVERSATION, monitor);
+ this.workContext = workContext;
+ this.nonDurableStore = store;
+ if (store != null) {
+ store.addListener(new ExpirationListener(monitor));
+ }
+ }
+
+ 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 register(AtomicComponent component, URI groupId) {
+ super.register(component, groupId);
+ component.addListener(this);
+ }
+
+ public void unregister(AtomicComponent component) {
+ // FIXME should all the instances associated with this component be remove already
+ component.removeListener(this);
+ super.unregister(component);
+ }
+
+ public void persistNew(AtomicComponent 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(AtomicComponent 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(AtomicComponent 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(AtomicComponent component, boolean create)
+ throws TargetResolutionException {
+ 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 = (String) workContext.getIdentifier(Scope.CONVERSATION);
+ assert conversationId != null;
+ return conversationId;
+ }
+
+ private long calculateExpiration(AtomicComponent 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 {
+ private final ScopeContainerMonitor monitor;
+
+ public ExpirationListener(ScopeContainerMonitor monitor) {
+ this.monitor = monitor;
+ }
+
+ 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/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/HttpSessionScopeContainer.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/HttpSessionScopeContainer.java
new file mode 100644
index 0000000000..5a398e921e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/HttpSessionScopeContainer.java
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainerMonitor;
+import org.apache.tuscany.spi.component.TargetDestructionException;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.event.Event;
+import org.apache.tuscany.spi.model.Scope;
+
+import org.apache.tuscany.core.component.event.HttpSessionEnd;
+
+/**
+ * A scope context which manages atomic component instances keyed on HTTP session
+ *
+ * @version $Rev$ $Date$
+ */
+public class HttpSessionScopeContainer extends AbstractScopeContainer {
+ private final WorkContext workContext;
+ private final Map<AtomicComponent, Map<Object, InstanceWrapper>> contexts;
+ private final Map<Object, List<InstanceWrapper>> destroyQueues;
+
+ public HttpSessionScopeContainer(WorkContext workContext, ScopeContainerMonitor monitor) {
+ super(Scope.SESSION, monitor);
+ this.workContext = workContext;
+ contexts = new ConcurrentHashMap<AtomicComponent, Map<Object, InstanceWrapper>>();
+ destroyQueues = new ConcurrentHashMap<Object, List<InstanceWrapper>>();
+ }
+
+ public void onEvent(Event event) {
+ checkInit();
+ if (event instanceof HttpSessionEnd) {
+ Object key = ((HttpSessionEnd) event).getId();
+ shutdownInstances(key);
+ workContext.clearIdentifier(key);
+ }
+ }
+
+ 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;
+ }
+
+ public void register(AtomicComponent component, Object groupId) {
+ contexts.put(component, new ConcurrentHashMap<Object, InstanceWrapper>());
+ component.addListener(this);
+ }
+
+ public void unregister(AtomicComponent component) {
+ // FIXME should all the instances associated with this component be destroyed already
+ contexts.remove(component);
+ component.removeListener(this);
+ super.unregister(component);
+ }
+
+ protected InstanceWrapper getInstanceWrapper(AtomicComponent component, boolean create)
+ throws TargetResolutionException {
+ Object key = workContext.getIdentifier(Scope.SESSION);
+ assert key != null : "HTTP session key not bound in work context";
+ return getInstance(component, key, create);
+ }
+
+ private InstanceWrapper getInstance(AtomicComponent component, Object key, boolean create)
+ throws TargetResolutionException {
+ Map<Object, InstanceWrapper> wrappers = contexts.get(component);
+ InstanceWrapper ctx = wrappers.get(key);
+ if (ctx == null && !create) {
+ return null;
+ }
+ if (ctx == null) {
+ ctx = component.createInstanceWrapper();
+ ctx.start();
+ wrappers.put(key, ctx);
+ List<InstanceWrapper> destroyQueue = destroyQueues.get(key);
+ if (destroyQueue == null) {
+ destroyQueue = new ArrayList<InstanceWrapper>();
+ destroyQueues.put(key, destroyQueue);
+ }
+ synchronized (destroyQueue) {
+ destroyQueue.add(ctx);
+ }
+ }
+ return ctx;
+
+ }
+
+ private void shutdownInstances(Object key) {
+ List<InstanceWrapper> destroyQueue = destroyQueues.remove(key);
+ if (destroyQueue != null) {
+ for (Map<Object, InstanceWrapper> map : contexts.values()) {
+ map.remove(key);
+ }
+ ListIterator<InstanceWrapper> iter = destroyQueue.listIterator(destroyQueue.size());
+ synchronized (destroyQueue) {
+ while (iter.hasPrevious()) {
+ try {
+ iter.previous().stop();
+ } catch (TargetDestructionException e) {
+ monitor.destructionError(e);
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/InstanceWrapperBase.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/InstanceWrapperBase.java
new file mode 100644
index 0000000000..def862fa7c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/InstanceWrapperBase.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.core.component.scope;
+
+import org.apache.tuscany.spi.component.TargetDestructionException;
+import org.apache.tuscany.spi.component.TargetInitializationException;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InstanceWrapperBase<T> implements InstanceWrapper<T> {
+ protected final T instance;
+ private boolean started;
+
+ public InstanceWrapperBase(T instance) {
+ assert instance != null;
+ this.instance = instance;
+ }
+
+ public T getInstance() {
+ assert started;
+ return instance;
+ }
+
+ public boolean isStarted() {
+ return started;
+ }
+
+ public void start() throws TargetInitializationException {
+ started = true;
+ }
+
+ public void stop() throws TargetDestructionException {
+ started = false;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/ReflectiveInstanceWrapper.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/ReflectiveInstanceWrapper.java
new file mode 100644
index 0000000000..d57f255fb9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/ReflectiveInstanceWrapper.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.core.component.scope;
+
+import org.apache.tuscany.spi.component.TargetInitializationException;
+import org.apache.tuscany.spi.component.TargetDestructionException;
+import org.apache.tuscany.core.injection.EventInvoker;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReflectiveInstanceWrapper<T> extends InstanceWrapperBase<T> {
+ private final EventInvoker<T> initInvoker;
+ private final EventInvoker<T> destroyInvoker;
+
+ public ReflectiveInstanceWrapper(T instance, EventInvoker<T> initInvoker, EventInvoker<T> destroyInvoker) {
+ super(instance);
+ this.initInvoker = initInvoker;
+ this.destroyInvoker = destroyInvoker;
+ }
+
+ public void start() throws TargetInitializationException {
+ if (initInvoker != null) {
+ initInvoker.invokeEvent(instance);
+ }
+ super.start();
+ }
+
+
+ public void stop() throws TargetDestructionException {
+ super.stop();
+ if (destroyInvoker != null) {
+ destroyInvoker.invokeEvent(instance);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/RequestScopeContainer.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/RequestScopeContainer.java
new file mode 100644
index 0000000000..d40277dc23
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/RequestScopeContainer.java
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainerMonitor;
+import org.apache.tuscany.spi.component.TargetDestructionException;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.event.Event;
+import org.apache.tuscany.spi.model.Scope;
+
+import org.apache.tuscany.core.component.event.RequestEnd;
+
+/**
+ * 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<AtomicComponent, Map<Thread, InstanceWrapper>> contexts;
+ private final Map<Thread, List<InstanceWrapper>> destroyQueues;
+
+ public RequestScopeContainer(ScopeContainerMonitor monitor) {
+ super(Scope.REQUEST, monitor);
+ contexts = new ConcurrentHashMap<AtomicComponent, Map<Thread, InstanceWrapper>>();
+ destroyQueues = new ConcurrentHashMap<Thread, List<InstanceWrapper>>();
+ }
+
+ 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;
+ }
+
+ public void register(AtomicComponent component, URI groupId) {
+ super.register(component, groupId);
+ contexts.put(component, new ConcurrentHashMap<Thread, InstanceWrapper>());
+ }
+
+ public void unregister(AtomicComponent component) {
+ // FIXME should all the instances associated with this component be destroyed already
+ contexts.remove(component);
+ super.unregister(component);
+ }
+
+ protected InstanceWrapper getInstanceWrapper(AtomicComponent component, boolean create)
+ throws TargetResolutionException {
+ Map<Thread, InstanceWrapper> instanceContextMap = contexts.get(component);
+ assert instanceContextMap != null : "Atomic component not registered";
+ InstanceWrapper ctx = instanceContextMap.get(Thread.currentThread());
+ if (ctx == null && !create) {
+ return null;
+ }
+ if (ctx == null) {
+ ctx = component.createInstanceWrapper();
+ ctx.start();
+ instanceContextMap.put(Thread.currentThread(), ctx);
+ List<InstanceWrapper> destroyQueue = destroyQueues.get(Thread.currentThread());
+ if (destroyQueue == null) {
+ destroyQueue = new ArrayList<InstanceWrapper>();
+ destroyQueues.put(Thread.currentThread(), destroyQueue);
+ }
+ synchronized (destroyQueue) {
+ destroyQueue.add(ctx);
+ }
+ }
+ return ctx;
+ }
+
+ private void shutdownInstances(Thread key) {
+ List<InstanceWrapper> destroyQueue = destroyQueues.remove(key);
+ if (destroyQueue != null && destroyQueue.size() > 0) {
+ Thread thread = Thread.currentThread();
+ for (Map<Thread, InstanceWrapper> map : contexts.values()) {
+ map.remove(thread);
+ }
+ ListIterator<InstanceWrapper> iter = destroyQueue.listIterator(destroyQueue.size());
+ synchronized (destroyQueue) {
+ while (iter.hasPrevious()) {
+ try {
+ iter.previous().stop();
+ } catch (TargetDestructionException e) {
+ monitor.destructionError(e);
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/ScopeRegistryImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/ScopeRegistryImpl.java
new file mode 100644
index 0000000000..bcf05982eb
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/ScopeRegistryImpl.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.core.component.scope;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.model.Scope;
+
+/**
+ * The default implementation of a scope registry
+ *
+ * @version $Rev$ $Date$
+ */
+public class ScopeRegistryImpl implements ScopeRegistry {
+ private final Map<Scope, ScopeContainer> scopeCache =
+ new ConcurrentHashMap<Scope, ScopeContainer>();
+ private final Map<Scope, ObjectFactory<? extends ScopeContainer>> factoryCache =
+ new ConcurrentHashMap<Scope, ObjectFactory<? extends ScopeContainer>>();
+
+ public void register(ScopeContainer container) {
+ scopeCache.put(container.getScope(), container);
+ }
+
+ public ScopeContainer getScopeContainer(Scope scope) {
+ return scopeCache.get(scope);
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/StatelessScopeContainer.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/StatelessScopeContainer.java
new file mode 100644
index 0000000000..0e1d5cab6a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/component/scope/StatelessScopeContainer.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.core.component.scope;
+
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Service;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.ScopeContainerMonitor;
+import org.apache.tuscany.spi.component.TargetDestructionException;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.api.annotation.Monitor;
+
+/**
+ * A scope context which manages stateless atomic component instances in a non-pooled fashion.
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+@Service(ScopeContainer.class)
+public class StatelessScopeContainer<KEY> extends AbstractScopeContainer<KEY> {
+
+ public StatelessScopeContainer(@Monitor ScopeContainerMonitor monitor) {
+ super(Scope.STATELESS, monitor);
+ }
+
+ public <T> InstanceWrapper<T> getWrapper(AtomicComponent<T> component, KEY contextId)
+ throws TargetResolutionException {
+ InstanceWrapper<T> ctx = createInstance(component);
+ ctx.start();
+ return ctx;
+ }
+
+ public <T> InstanceWrapper<T> getAssociatedWrapper(AtomicComponent<T> component, KEY contextId)
+ throws TargetResolutionException {
+ throw new UnsupportedOperationException();
+ }
+
+ public <T> void returnWrapper(AtomicComponent<T> component, InstanceWrapper<T> wrapper, KEY contextId)
+ throws TargetDestructionException {
+ wrapper.stop();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingInteceptor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingInteceptor.java
new file mode 100644
index 0000000000..7eef28f786
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingInteceptor.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.core.databinding.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.databinding.Mediator;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * An interceptor to transform data accross databindings on the wire
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataBindingInteceptor implements Interceptor {
+ private Interceptor next;
+
+ private Operation<?> sourceOperation;
+
+ private Operation<?> targetOperation;
+
+ private Mediator mediator;
+
+ public DataBindingInteceptor(Wire sourceWire, Operation<?> sourceOperation, Operation<?> targetOperation) {
+ super();
+ // this.sourceWire = sourceWire;
+ this.sourceOperation = sourceOperation;
+ // this.targetWire = targetWire;
+ this.targetOperation = targetOperation;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.wire.Interceptor#getNext()
+ */
+ public Interceptor getNext() {
+ return next;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.wire.Interceptor#invoke(org.apache.tuscany.spi.wire.Message)
+ */
+ public Message invoke(Message msg) {
+ Object input = transform(msg.getBody(), sourceOperation.getInputType(), targetOperation.getInputType());
+ msg.setBody(input);
+ Message resultMsg = next.invoke(msg);
+ Object result = resultMsg.getBody();
+ // FIXME: How to deal with faults?
+ if (resultMsg.isFault()) {
+ // We need to figure out what fault type it is and then transform it back the source fault type
+ // throw new InvocationRuntimeException((Throwable) result);
+ return resultMsg;
+ } else {
+ if (sourceOperation.isNonBlocking()) {
+ // Not to reset the message body
+ return resultMsg;
+ }
+ // FIXME: Should we fix the Operation model so that getOutputType returns DataType<DataType<T>>?
+ DataType<DataType> targetType =
+ new DataType<DataType>("idl:output", Object.class, targetOperation.getOutputType());
+
+ targetType.setOperation(targetOperation.getOutputType().getOperation());
+ DataType<DataType> sourceType =
+ new DataType<DataType>("idl:output", Object.class, sourceOperation.getOutputType());
+ sourceType.setOperation(sourceOperation.getOutputType().getOperation());
+
+ Object newResult = transform(result, targetType, sourceType);
+ if (newResult != result) {
+ resultMsg.setBody(newResult);
+ }
+ }
+ return resultMsg;
+ }
+
+ private Object transform(Object source, DataType sourceType, DataType targetType) {
+ if (sourceType == targetType || (sourceType != null && sourceType.equals(targetType))) {
+ return source;
+ }
+ Map<Class<?>, Object> metadata = new HashMap<Class<?>, Object>();
+ return mediator.mediate(source, sourceType, targetType, metadata);
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.wire.Interceptor#isOptimizable()
+ */
+ public boolean isOptimizable() {
+ return false;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.wire.Interceptor#setNext(org.apache.tuscany.spi.wire.Interceptor)
+ */
+ public void setNext(Interceptor next) {
+ this.next = next;
+ }
+
+ /**
+ * @param mediator the mediator to set
+ */
+ public void setMediator(Mediator mediator) {
+ this.mediator = mediator;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingJavaInterfaceProcessor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingJavaInterfaceProcessor.java
new file mode 100644
index 0000000000..0da1ff90c1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingJavaInterfaceProcessor.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.core.databinding.impl;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import javax.xml.datatype.Duration;
+import javax.xml.datatype.XMLGregorianCalendar;
+
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorExtension;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+
+import org.apache.tuscany.api.annotation.DataContext;
+import org.apache.tuscany.api.annotation.DataType;
+
+/**
+ * The databinding annotation processor for java interfaces
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataBindingJavaInterfaceProcessor extends JavaInterfaceProcessorExtension {
+
+ private static final String SIMPLE_JAVA_OBJECTS = "java.lang.Object";
+
+ private static final Class[] SIMPLE_JAVA_TYPES =
+ {Byte.class, Character.class, Short.class, Integer.class, Long.class, Float.class, Double.class, Date.class,
+ Calendar.class, GregorianCalendar.class, Duration.class, XMLGregorianCalendar.class, BigInteger.class,
+ BigDecimal.class};
+
+ private static final Set<Class> SIMPLE_TYPE_SET = new HashSet<Class>(Arrays.asList(SIMPLE_JAVA_TYPES));
+
+ public void visitInterface(Class<?> clazz, Class<?> callbackClass, JavaServiceContract contract)
+ throws InvalidServiceContractException {
+ Map<String, Operation<Type>> operations = contract.getOperations();
+ processInterface(clazz, contract, operations);
+ if (callbackClass != null) {
+ Map<String, Operation<Type>> callbackOperations = contract.getCallbackOperations();
+ processInterface(callbackClass, contract, callbackOperations);
+ }
+ }
+
+ private void processInterface(Class<?> clazz,
+ JavaServiceContract contract,
+ Map<String, Operation<Type>> operations) {
+ DataType interfaceDataType = clazz.getAnnotation(DataType.class);
+ if (interfaceDataType != null) {
+ contract.setDataBinding(interfaceDataType.name());
+ // FIXME: [rfeng] Keep data context as metadata?
+ for (DataContext c : interfaceDataType.context()) {
+ contract.setMetaData(c.key(), c.value());
+ }
+ }
+ for (Method method : clazz.getMethods()) {
+ Operation<?> operation = operations.get(method.getName());
+ DataType operationDataType = method.getAnnotation(DataType.class);
+
+ if (operationDataType != null) {
+ operation.setDataBinding(operationDataType.name());
+ // FIXME: [rfeng] Keep data context as metadata?
+ for (DataContext c : operationDataType.context()) {
+ operation.setMetaData(c.key(), c.value());
+ }
+ }
+
+ String dataBinding = operation.getDataBinding();
+
+ // FIXME: We need a better way to identify simple java types
+ for (org.apache.tuscany.spi.model.DataType<?> d : operation.getInputType().getLogical()) {
+ adjustSimpleType(d, dataBinding);
+ }
+ if (operation.getOutputType() != null) {
+ adjustSimpleType(operation.getOutputType(), dataBinding);
+ }
+ for (org.apache.tuscany.spi.model.DataType<?> d : operation.getFaultTypes()) {
+ adjustSimpleType(d, dataBinding);
+ }
+ }
+ }
+
+ private void adjustSimpleType(org.apache.tuscany.spi.model.DataType<?> dataType, String dataBinding) {
+ Type type = dataType.getPhysical();
+ if (!(type instanceof Class)) {
+ return;
+ }
+ Class cls = (Class) dataType.getPhysical();
+ if (cls.isPrimitive() || SIMPLE_TYPE_SET.contains(cls)) {
+ dataType.setDataBinding(SIMPLE_JAVA_OBJECTS);
+ } else if (cls == String.class && (dataBinding == null || !dataBinding.equals(String.class.getName()))) {
+ // Identify the String as a simple type
+ dataType.setDataBinding(SIMPLE_JAVA_OBJECTS);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingRegistryImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingRegistryImpl.java
new file mode 100644
index 0000000000..3880d0ed12
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingRegistryImpl.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.core.databinding.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.osoa.sca.annotations.EagerInit;
+
+import org.apache.tuscany.core.databinding.javabeans.JavaBeansDataBinding;
+import org.apache.tuscany.spi.databinding.DataBinding;
+import org.apache.tuscany.spi.databinding.DataBindingRegistry;
+import org.apache.tuscany.spi.model.DataType;
+
+/**
+ * The default implementation of a data binding registry
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+public class DataBindingRegistryImpl implements DataBindingRegistry {
+ private final Map<String, DataBinding> bindings = new HashMap<String, DataBinding>();
+
+ public DataBinding getDataBinding(String id) {
+ if (id == null) {
+ return null;
+ }
+ return bindings.get(id.toLowerCase());
+ }
+
+ public void register(DataBinding dataBinding) {
+ bindings.put(dataBinding.getName().toLowerCase(), dataBinding);
+ }
+
+ public DataBinding unregister(String id) {
+ if (id == null) {
+ return null;
+ }
+ return bindings.remove(id.toLowerCase());
+ }
+
+ public DataType introspectType(Class<?> javaType) {
+ DataType dataType = null;
+ for (DataBinding binding : bindings.values()) {
+ //don't introspect for JavaBeansDatabinding as all javatypes will anyways match to its basetype
+ //which is java.lang.Object. Default to this only if no databinding results
+ if (!binding.getName().equals(JavaBeansDataBinding.NAME)) {
+ dataType = binding.introspect(javaType);
+ }
+
+ if (dataType != null) {
+ return dataType;
+ }
+ }
+ return new DataType<Class>(JavaBeansDataBinding.NAME, Object.class, javaType);
+ }
+
+ public DataType introspectType(Object value) {
+ DataType dataType = null;
+ for (DataBinding binding : bindings.values()) {
+ //don't introspect for JavaBeansDatabinding as all javatypes will anyways match to its basetype
+ //which is java.lang.Object. Default to this only if no databinding results
+ if (!binding.getName().equals(JavaBeansDataBinding.NAME)) {
+ dataType = binding.introspect(value);
+ }
+ if (dataType != null) {
+ return dataType;
+ }
+ }
+ return new DataType<Class>(JavaBeansDataBinding.NAME, Object.class, value.getClass());
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessor.java
new file mode 100644
index 0000000000..8bd1b810d4
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessor.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.core.databinding.impl;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.databinding.Mediator;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.WirePostProcessorExtension;
+
+/**
+ * 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 DataBindingWirePostProcessor extends WirePostProcessorExtension {
+ private Mediator mediator;
+
+ @Constructor({"mediator"})
+ public DataBindingWirePostProcessor(@Reference Mediator mediator) {
+ super();
+ this.mediator = mediator;
+ }
+
+ public void process(Wire wire) {
+ Map<Operation<?>, InvocationChain> chains = wire.getInvocationChains();
+ for (Map.Entry<Operation<?>, InvocationChain> entry : chains.entrySet()) {
+ Operation<?> sourceOperation = entry.getKey();
+ ServiceContract<?> serviceContract = wire.getTargetContract();
+ if (serviceContract == null) {
+ continue;
+ }
+ Collection<? extends Operation<?>> operations = serviceContract.getOperations().values();
+ Operation<?> targetOperation = getTargetOperation(operations, sourceOperation.getName());
+ String sourceDataBinding = sourceOperation.getDataBinding();
+ String targetDataBinding = targetOperation.getDataBinding();
+ if (sourceDataBinding == null && targetDataBinding == null) {
+ continue;
+ }
+ if (sourceDataBinding == null || targetDataBinding == null
+ || !sourceDataBinding.equals(targetDataBinding)) {
+ // Add the interceptor to the source side because multiple
+ // references can be wired
+ // to the same service
+ DataBindingInteceptor interceptor =
+ new DataBindingInteceptor(wire, sourceOperation, targetOperation);
+ interceptor.setMediator(mediator);
+ entry.getValue().addInterceptor(0, interceptor);
+ }
+ }
+
+ // Check if there's a callback
+ Map callbackOperations = wire.getSourceContract().getCallbackOperations();
+ if (callbackOperations == null || callbackOperations.isEmpty()) {
+ return;
+ }
+ //Object targetAddress = UriHelper.getBaseName(source.getUri());
+ Map<Operation<?>, InvocationChain> callbackChains = wire.getCallbackInvocationChains();
+ if (callbackChains == null) {
+ // callback chains could be null
+ return;
+ }
+ for (Map.Entry<Operation<?>, InvocationChain> entry : callbackChains.entrySet()) {
+ Operation<?> sourceOperation = entry.getKey();
+ Operation<?> targetOperation =
+ getTargetOperation(wire.getCallbackInvocationChains().keySet(), sourceOperation
+ .getName());
+ String sourceDataBinding = sourceOperation.getDataBinding();
+ String targetDataBinding = targetOperation.getDataBinding();
+ if (sourceDataBinding == null && targetDataBinding == null) {
+ continue;
+ }
+ if (sourceDataBinding == null || targetDataBinding == null
+ || !sourceDataBinding.equals(targetDataBinding)) {
+ // Add the interceptor to the source side because multiple
+ // references can be wired
+ // to the same service
+ DataBindingInteceptor interceptor =
+ new DataBindingInteceptor(wire, sourceOperation, targetOperation);
+ interceptor.setMediator(mediator);
+ entry.getValue().addInterceptor(0, interceptor);
+ }
+ }
+ }
+
+
+ private Operation getTargetOperation(Collection<? extends Operation<?>> operations, String operationName) {
+ for (Operation<?> op : operations) {
+ if (op.getName().equals(operationName)) {
+ return op;
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataTypeLoader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataTypeLoader.java
new file mode 100644
index 0000000000..4f7d52b1cf
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DataTypeLoader.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.core.databinding.impl;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.InvalidValueException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.LoaderUtil;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * The StAX loader for data type
+ */
+public class DataTypeLoader extends LoaderExtension<DataType> {
+ public static final QName DATA_BINDING =
+ new QName("http://tuscany.apache.org/xmlns/sca/databinding/1.0", "databinding");
+
+ @Constructor({"registry"})
+ public DataTypeLoader(@Reference LoaderRegistry registry) {
+ super(registry);
+ }
+
+ @Override
+ public QName getXMLType() {
+ return DATA_BINDING;
+ }
+
+ public DataType load(
+ ModelObject object, XMLStreamReader reader,
+ DeploymentContext deploymentContext) throws XMLStreamException, LoaderException {
+ assert DATA_BINDING.equals(reader.getName());
+ String name = reader.getAttributeValue(null, "name");
+ LoaderUtil.skipToEndElement(reader);
+ if (name == null) {
+ throw new InvalidValueException("The 'name' attrbiute is required");
+ }
+ DataType dataType = new DataType<Class>(name, Object.class, Object.class);
+ return dataType;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DirectedGraph.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/DirectedGraph.java
new file mode 100755
index 0000000000..02adf5860c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/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.core.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 <V> The type of vertex object
+ * @param <E> The type of edge object
+ */
+public class DirectedGraph<V, E> {
+ private final Map<V, Vertex> vertices = new HashMap<V, Vertex>();
+
+ /**
+ * 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<VertexPair, Path> paths = new HashMap<VertexPair, Path>();
+
+ /**
+ * Vertex of a graph
+ */
+ public final class Vertex {
+ private V value;
+
+ // TODO: Do we want to support multiple edges for a vertex pair? If so,
+ // we should use a List instead of Map
+ private Map<Vertex, Edge> outEdges = new HashMap<Vertex, Edge>();
+
+ private Vertex(V value) {
+ this.value = value;
+ }
+
+ public String toString() {
+ return "(" + value + ")";
+ }
+
+ public V getValue() {
+ return value;
+ }
+
+ public Map<Vertex, Edge> 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<Node> {
+
+ 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<Vertex, Node> nodes = new HashMap<Vertex, Node>();
+ for (Vertex v : vertices.values()) {
+ Node node = new Node(v);
+ if (v == source) {
+ node.distance = 0;
+ }
+ nodes.put(v, node);
+ }
+
+ Set<Node> otherNodes = new HashSet<Node>(nodes.values());
+ Set<Node> nodesOnPath = new HashSet<Node>();
+ 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<Node> nodes) {
+ Node node = Collections.min(nodes);
+ nodes.remove(node);
+ return node;
+ }
+
+ /**
+ * The path between two vertices
+ */
+ public final class Path {
+ private List<Edge> edges = new LinkedList<Edge>();
+
+ private int weight;
+
+ public int getWeight() {
+ return weight;
+ }
+
+ public List<Edge> 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<V, Vertex> getVertices() {
+ return vertices;
+ }
+
+ public void addGraph(DirectedGraph<V, E> otherGraph) {
+ for (Vertex v : otherGraph.vertices.values()) {
+ for (Edge e : v.outEdges.values()) {
+ addEdge(e.sourceVertex.value, e.targetVertex.value, e.value, e.weight);
+ }
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/Input2InputTransformer.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/Input2InputTransformer.java
new file mode 100644
index 0000000000..0d87e13f85
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/Input2InputTransformer.java
@@ -0,0 +1,216 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.impl;
+
+import java.util.List;
+import javax.xml.namespace.QName;
+
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Service;
+
+import org.apache.tuscany.spi.databinding.DataBinding;
+import org.apache.tuscany.spi.databinding.DataBindingRegistry;
+import org.apache.tuscany.spi.databinding.Mediator;
+import org.apache.tuscany.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.WrapperHandler;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.apache.tuscany.spi.model.ElementInfo;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.WrapperInfo;
+import org.apache.tuscany.spi.model.XMLType;
+
+/**
+ * This is a special transformer to transform the input from one IDL to the other one
+ */
+@Service(Transformer.class)
+public class Input2InputTransformer extends TransformerExtension<Object[], Object[]> implements
+ PullTransformer<Object[], Object[]> {
+
+ private static final String IDL_INPUT = "idl:input";
+
+ protected DataBindingRegistry dataBindingRegistry;
+
+ protected Mediator mediator;
+
+ public Input2InputTransformer() {
+ super();
+ }
+
+ @Override
+ public String getSourceDataBinding() {
+ return IDL_INPUT;
+ }
+
+ @Override
+ public String getTargetDataBinding() {
+ return IDL_INPUT;
+ }
+
+ /**
+ * @param mediator the mediator to set
+ */
+ @Reference
+ public void setMediator(Mediator mediator) {
+ this.mediator = mediator;
+ }
+
+ /**
+ * @param dataBindingRegistry the dataBindingRegistry to set
+ */
+ @Reference
+ public void setDataBindingRegistry(DataBindingRegistry dataBindingRegistry) {
+ this.dataBindingRegistry = dataBindingRegistry;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.extension.TransformerExtension#getSourceType()
+ */
+ @Override
+ protected Class getSourceType() {
+ return Object[].class;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.extension.TransformerExtension#getTargetType()
+ */
+ @Override
+ protected Class getTargetType() {
+ return Object[].class;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.Transformer#getWeight()
+ */
+ public int getWeight() {
+ return 10000;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object[] transform(Object[] source, TransformationContext context) {
+ DataType<List<DataType<?>>> sourceType = context.getSourceDataType();
+ Operation<?> sourceOp = (Operation<?>) sourceType.getOperation();
+ boolean sourceWrapped = sourceOp != null && sourceOp.isWrapperStyle();
+
+ WrapperHandler sourceWrapperHandler = null;
+ if (sourceWrapped) {
+ sourceWrapperHandler = getWapperHandler(sourceType.getOperation().getDataBinding(), true);
+ }
+
+ DataType<List<DataType<QName>>> targetType = context.getTargetDataType();
+ Operation<?> targetOp = (Operation<?>) targetType.getOperation();
+ boolean targetWrapped = targetOp != null && targetOp.isWrapperStyle();
+ WrapperHandler targetWrapperHandler = null;
+ if (targetWrapped) {
+ targetWrapperHandler = getWapperHandler(targetType.getOperation().getDataBinding(), 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<DataType<XMLType>> argTypes = wrapper.getUnwrappedInputType().getLogical();
+
+ for (int i = 0; i < source.length; i++) {
+ ElementInfo argElement = wrapper.getInputChildElements().get(i);
+ DataType<XMLType> 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<ElementInfo> childElements = sourceOp.getWrapper().getInputChildElements();
+ Object[] target = new Object[childElements.size()];
+
+ targetWrapperHandler = getWapperHandler(targetType.getOperation().getDataBinding(), false);
+ if (targetWrapperHandler != null) {
+ ElementInfo wrapperElement = sourceOp.getWrapper().getInputWrapperElement();
+ // Object targetWrapper =
+ // targetWrapperHandler.create(wrapperElement, context);
+ DataType<QName> targetWrapperType =
+ new DataType<QName>(targetType.getOperation().getDataBinding(), Object.class,
+ wrapperElement.getQName());
+ Object targetWrapper =
+ mediator.mediate(sourceWrapper,
+ sourceType.getLogical().get(0),
+ targetWrapperType,
+ context.getMetadata());
+ for (int i = 0; i < childElements.size(); i++) {
+ ElementInfo childElement = childElements.get(i);
+ target[i] = targetWrapperHandler.getChild(targetWrapper, i, childElement);
+ }
+ } else {
+ for (int i = 0; i < childElements.size(); i++) {
+ ElementInfo childElement = childElements.get(i);
+ Object child = sourceWrapperHandler.getChild(sourceWrapper, i, childElement);
+ DataType<XMLType> childType =
+ sourceOp.getWrapper().getUnwrappedInputType().getLogical().get(i);
+ target[i] =
+ mediator.mediate(child, 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 getWapperHandler(String dataBindingId, boolean required) {
+ DataBinding dataBinding = dataBindingRegistry.getDataBinding(dataBindingId);
+ WrapperHandler wrapperHandler = dataBinding == null ? null : dataBinding.getWrapperHandler();
+ if (wrapperHandler == null && required) {
+ throw new TransformationException(
+ "No wrapper handler is provided for databinding: " + dataBindingId);
+ }
+ return wrapperHandler;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/MediatorImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/MediatorImpl.java
new file mode 100644
index 0000000000..589a96ed71
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/MediatorImpl.java
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.databinding.impl;
+
+import java.util.List;
+import java.util.Map;
+
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Scope;
+
+import org.apache.tuscany.spi.databinding.DataBindingRegistry;
+import org.apache.tuscany.spi.databinding.DataPipe;
+import org.apache.tuscany.spi.databinding.Mediator;
+import org.apache.tuscany.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.PushTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.TransformerRegistry;
+import org.apache.tuscany.spi.model.DataType;
+
+/**
+ * Default Mediator implementation
+ */
+@Scope("COMPOSITE")
+public class MediatorImpl implements Mediator {
+
+ private DataBindingRegistry dataBindingRegistry;
+
+ private TransformerRegistry transformerRegistry;
+
+ @Reference
+ public void setTransformerRegistry(TransformerRegistry transformerRegistry) {
+ this.transformerRegistry = transformerRegistry;
+ }
+
+ /**
+ * @param dataBindingRegistry the dataBindingRegistry to set
+ */
+ @Reference
+ public void setDataBindingRegistry(DataBindingRegistry dataBindingRegistry) {
+ this.dataBindingRegistry = dataBindingRegistry;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.Mediator#mediate(java.lang.Object,org.apache.tuscany.spi.model.DataType,
+ *org.apache.tuscany.spi.model.DataType,Map)
+ */
+ @SuppressWarnings("unchecked")
+ public Object mediate(Object source,
+ DataType sourceDataType,
+ DataType targetDataType,
+ Map<Class<?>, Object> metadata) {
+ if (sourceDataType == null) {
+ sourceDataType = dataBindingRegistry.introspectType(source);
+ }
+ if (sourceDataType == null) {
+ return source;
+ } else if (sourceDataType.equals(targetDataType)) {
+ return source;
+ }
+
+ List<Transformer> 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<Class<?>, Object> metadata) {
+ DataType sourceType =
+ (index == 0) ? sourceDataType : new DataType<Object>(transformer.getSourceDataBinding(),
+ Object.class, null);
+ DataType targetType =
+ (index == size - 1) ? targetDataType : new DataType<Object>(transformer.getTargetDataBinding(),
+ Object.class, null);
+ 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<Class<?>, Object> metadata) {
+ if (source == null) {
+ // Shortcut for null value
+ return;
+ }
+ if (sourceDataType == null) {
+ sourceDataType = dataBindingRegistry.introspectType(source);
+ }
+ if (sourceDataType == null) {
+ return;
+ } else if (sourceDataType.equals(targetDataType)) {
+ return;
+ }
+
+ List<Transformer> 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<Transformer> getTransformerChain(DataType sourceDataType, DataType targetDataType) {
+ String sourceId = sourceDataType.getDataBinding();
+ String targetId = targetDataType.getDataBinding();
+ List<Transformer> path = transformerRegistry.getTransformerChain(sourceId, targetId);
+ if (path == null) {
+ throw new TransformationException("No path found for the transformation");
+ }
+ return path;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/Output2OutputTransformer.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/Output2OutputTransformer.java
new file mode 100644
index 0000000000..e471dd3c5e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/Output2OutputTransformer.java
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.databinding.impl;
+
+import java.util.List;
+import javax.xml.namespace.QName;
+
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Service;
+
+import org.apache.tuscany.spi.databinding.DataBinding;
+import org.apache.tuscany.spi.databinding.DataBindingRegistry;
+import org.apache.tuscany.spi.databinding.Mediator;
+import org.apache.tuscany.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.WrapperHandler;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.apache.tuscany.spi.model.ElementInfo;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.WrapperInfo;
+import org.apache.tuscany.spi.model.XMLType;
+
+/**
+ * This is a special transformer to transform the output from one IDL to the other one
+ */
+@Service(Transformer.class)
+public class Output2OutputTransformer extends TransformerExtension<Object, Object> implements
+ PullTransformer<Object, Object> {
+ private static final String IDL_OUTPUT = "idl:output";
+
+ protected DataBindingRegistry dataBindingRegistry;
+
+ protected Mediator mediator;
+
+ /**
+ *
+ */
+ public Output2OutputTransformer() {
+ super();
+ }
+
+ /**
+ * @param mediator the mediator to set
+ */
+ @Reference
+ public void setMediator(Mediator mediator) {
+ this.mediator = mediator;
+ }
+
+ /**
+ * @param dataBindingRegistry the dataBindingRegistry to set
+ */
+ @Reference
+ public void setDataBindingRegistry(DataBindingRegistry dataBindingRegistry) {
+ this.dataBindingRegistry = dataBindingRegistry;
+ }
+
+ @Override
+ public String getSourceDataBinding() {
+ return IDL_OUTPUT;
+ }
+
+ @Override
+ public String getTargetDataBinding() {
+ return IDL_OUTPUT;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.extension.TransformerExtension#getSourceType()
+ */
+ @Override
+ protected Class getSourceType() {
+ return Object.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.extension.TransformerExtension#getTargetType()
+ */
+ @Override
+ protected Class getTargetType() {
+ return Object.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.Transformer#getWeight()
+ */
+ public int getWeight() {
+ return 10;
+ }
+
+ private WrapperHandler getWapperHandler(Operation<?> operation) {
+ String dataBindingId;
+ dataBindingId = operation.getDataBinding();
+ DataBinding dataBinding = dataBindingRegistry.getDataBinding(dataBindingId);
+ WrapperHandler wrapperHandler = dataBinding == null ? null : dataBinding.getWrapperHandler();
+ if (wrapperHandler == null) {
+ throw new TransformationException(
+ "No wrapper handler is provided for databinding: " + dataBindingId);
+ }
+ return wrapperHandler;
+ }
+
+ private WrapperHandler getWapperHandler(String dataBindingId) {
+ DataBinding dataBinding = dataBindingRegistry.getDataBinding(dataBindingId);
+ return dataBinding == null ? null : dataBinding.getWrapperHandler();
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object transform(Object response, TransformationContext context) {
+ try {
+ DataType<DataType> sourceType = context.getSourceDataType();
+ Operation<?> sourceOp = (Operation<?>) sourceType.getOperation();
+ boolean sourceWrapped = sourceOp != null && sourceOp.isWrapperStyle();
+ WrapperHandler sourceWrapperHandler = null;
+ if (sourceWrapped) {
+ sourceWrapperHandler = getWapperHandler(sourceOp);
+ }
+
+ DataType<DataType> targetType = context.getTargetDataType();
+ Operation<?> targetOp = (Operation<?>) targetType.getOperation();
+ boolean targetWrapped = targetOp != null && targetOp.isWrapperStyle();
+ WrapperHandler targetWrapperHandler = null;
+ if (targetWrapped) {
+ targetWrapperHandler = getWapperHandler(targetOp);
+ }
+
+ if ((!sourceWrapped) && targetWrapped) {
+ // Unwrapped --> Wrapped
+ WrapperInfo wrapper = targetOp.getWrapper();
+ Object targetWrapper =
+ targetWrapperHandler.create(wrapper.getOutputWrapperElement(), context);
+
+ List<ElementInfo> childElements = wrapper.getOutputChildElements();
+ if (childElements.isEmpty()) {
+ // void output
+ return targetWrapper;
+ }
+ ElementInfo argElement = childElements.get(0);
+ DataType<XMLType> 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<ElementInfo> childElements = sourceOp.getWrapper().getOutputChildElements();
+ if (childElements.isEmpty()) {
+ // The void output
+ return null;
+ }
+ ElementInfo childElement = childElements.get(0);
+
+ targetWrapperHandler = getWapperHandler(targetType.getLogical().getDataBinding());
+ if (targetWrapperHandler != null) {
+ ElementInfo wrapperElement = sourceOp.getWrapper().getInputWrapperElement();
+ // Object targetWrapper =
+ // targetWrapperHandler.create(wrapperElement, context);
+ DataType<QName> targetWrapperType =
+ new DataType<QName>(targetType.getLogical().getDataBinding(), Object.class,
+ wrapperElement.getQName());
+ Object targetWrapper =
+ mediator.mediate(sourceWrapper, sourceType.getLogical(), targetWrapperType, context
+ .getMetadata());
+ return targetWrapperHandler.getChild(targetWrapper, 0, childElement);
+ } else {
+ Object child = sourceWrapperHandler.getChild(sourceWrapper, 0, childElement);
+ DataType<?> childType = sourceOp.getWrapper().getUnwrappedOutputType();
+ return mediator.mediate(child, childType, targetType.getLogical(), context.getMetadata());
+ }
+ } else {
+ // FIXME: Do we want to handle wrapped to wrapped?
+ return mediator.mediate(response, sourceType.getLogical(), targetType.getLogical(), context
+ .getMetadata());
+ }
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/PassByValueInterceptor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/PassByValueInterceptor.java
new file mode 100644
index 0000000000..1252885244
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/PassByValueInterceptor.java
@@ -0,0 +1,244 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.databinding.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.util.IdentityHashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.databinding.DataBinding;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+
+import org.apache.tuscany.core.util.JavaIntrospectionHelper;
+
+/**
+ * An interceptor to enforce pass-by-value semantics for remotable interfaces
+ *
+ * @version $Rev$ $Date$
+ */
+public class PassByValueInterceptor implements Interceptor {
+ private DataBinding[] argsDataBindings;
+ private DataBinding resultDataBinding;
+
+ private DataBinding dataBinding;
+
+ private Interceptor next;
+
+ public Interceptor getNext() {
+ return next;
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+
+ public void setNext(Interceptor next) {
+ this.next = next;
+ }
+
+ public Message invoke(Message msg) {
+ Object obj = msg.getBody();
+ msg.setBody(copy((Object[]) obj));
+ Message result = getNext().invoke(msg);
+
+ if (!result.isFault()) {
+ result.setBody(copy(result.getBody(), getResultDataBinding()));
+ }
+ return result;
+ }
+
+
+ public Object[] copy(Object[] args) {
+ if (args == null) {
+ return null;
+ }
+ Object[] copiedArgs = new Object[args.length];
+ Map<Object, Object> map = new IdentityHashMap<Object, Object>();
+ for (int i = 0; i < args.length; i++) {
+ if (args[i] == null) {
+ copiedArgs[i] = null;
+ } else {
+ Object copiedArg = map.get(args[i]);
+ if (copiedArg != null) {
+ copiedArgs[i] = copiedArg;
+ } else {
+ DataBinding dataBinding =
+ (getArgsDataBindings() != null) ? getArgsDataBindings()[i] : null;
+ copiedArg = copy(args[i], dataBinding);
+ map.put(args[i], copiedArg);
+ copiedArgs[i] = copiedArg;
+ }
+ }
+ }
+ return copiedArgs;
+ }
+
+ public Object copy(Object arg, DataBinding argDataBinding) {
+ if (arg == null) {
+ return null;
+ }
+ Object copiedArg;
+ if (dataBinding != null) {
+ copiedArg = dataBinding.copy(arg);
+ } else {
+ if (argDataBinding != null) {
+ copiedArg = argDataBinding.copy(arg);
+ } else {
+ final Class clazz = arg.getClass();
+ if (JavaIntrospectionHelper.isImmutable(clazz)) {
+ // Immutable classes
+ return arg;
+ }
+ copiedArg = copyJavaObject(arg);
+ }
+ }
+ return copiedArg;
+ }
+
+ private Object copyJavaObject(Object arg) {
+ try {
+ return deserializeJavaObject(serializeJavaObject(arg));
+ } catch (IllegalArgumentException e) {
+ throw e;
+ //System.out.println("Problem serializing...");
+ //return arg;
+ }
+ }
+
+ public byte[] serializeJavaObject(Object arg) throws IllegalArgumentException {
+ if (arg == null) {
+ return null;
+ }
+
+ ByteArrayOutputStream bos = null;
+ ObjectOutputStream oos = null;
+
+ try {
+ if (arg instanceof Serializable) {
+ bos = new ByteArrayOutputStream();
+ oos = getObjectOutputStream(bos);
+ oos.writeObject(arg);
+
+ return bos.toByteArray();
+ } else {
+ throw new IllegalArgumentException("Unable to serialize using Java Serialization");
+ }
+ } catch (IOException e) {
+ throw new IllegalArgumentException("Exception while serializing argument ", e);
+ } finally {
+ try {
+ if (oos != null) {
+ oos.close();
+ }
+ if (bos != null) {
+ bos.close();
+ }
+ } catch (IOException e) {
+ throw new IllegalArgumentException("Exception while serializing argument ", e);
+ }
+ }
+ }
+
+ public Object deserializeJavaObject(byte[] arg) {
+ if (arg == null) {
+ return null;
+ }
+ final Class clazz = arg.getClass();
+ if (JavaIntrospectionHelper.isImmutable(clazz)) {
+ // Immutable classes
+ return arg;
+ }
+
+ ByteArrayInputStream bis = null;
+ ObjectInputStream ois = null;
+
+ try {
+ bis = new ByteArrayInputStream(arg);
+ ois = getObjectInputStream(bis, clazz.getClassLoader());
+
+ return ois.readObject();
+ } catch (IOException e) {
+ throw new IllegalArgumentException("Exception when attempting to Java Deserialization of object ", e);
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException("Exception when attempting to Java Deserialization of object ", e);
+ } finally {
+ try {
+ if (ois != null) {
+ ois.close();
+ }
+ assert bis != null;
+ bis.close();
+ } catch (IOException e) {
+ throw new IllegalArgumentException("Exception when attempting to Java Deserialization of object ", e);
+ }
+ }
+ }
+
+ protected ObjectOutputStream getObjectOutputStream(OutputStream os) throws IOException {
+ return new ObjectOutputStream(os);
+ }
+
+ protected ObjectInputStream getObjectInputStream(InputStream is, final ClassLoader cl) throws IOException {
+ return 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);
+ }
+ }
+
+ };
+ }
+
+ public DataBinding getDataBinding() {
+ return dataBinding;
+ }
+
+ public void setDataBinding(DataBinding dataBinding) {
+ this.dataBinding = dataBinding;
+ }
+
+ public DataBinding[] getArgsDataBindings() {
+ return argsDataBindings;
+ }
+
+ public void setArgsDataBindings(DataBinding[] argsDataBindings) {
+ this.argsDataBindings = argsDataBindings;
+ }
+
+ public DataBinding getResultDataBinding() {
+ return resultDataBinding;
+ }
+
+ public void setResultDataBinding(DataBinding retDataBinding) {
+ this.resultDataBinding = retDataBinding;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessor.java
new file mode 100644
index 0000000000..ad4598f063
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessor.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.core.databinding.impl;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.databinding.DataBindingRegistry;
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.WirePostProcessorExtension;
+
+/**
+ * This processor is responsible for enforcing the pass-by-value semantics required of Remotable interfaces. This is
+ * done by adding a pass-by-value interceptor to the inbound invocation chain of a target if the target interface is
+ * Remotable.
+ *
+ * @version $Rev$ $Date$
+ */
+public class PassByValueWirePostProcessor extends WirePostProcessorExtension {
+ //private DataBindingRegistry dataBindingRegistry;
+
+ public PassByValueWirePostProcessor() {
+ super();
+
+ }
+
+ /**
+ * @param dataBindingRegistry the dataBindingRegistry to set
+ */
+ @Reference
+ public void setDataBindingRegistry(DataBindingRegistry dataBindingRegistry) {
+ // this.dataBindingRegistry = dataBindingRegistry;
+ }
+
+ public void process(Wire wire) {
+
+ }
+
+// public void process(SCAObject source, OutboundWire sourceWire, SCAObject target, InboundWire targetWire) {
+// Interceptor tailInterceptor;
+// PassByValueInterceptor passByValueInterceptor;
+// Operation<?> targetOperation;
+// Operation<?> sourceOperation;
+// DataBinding[] argsDataBindings;
+// DataBinding resultDataBinding;
+//
+// boolean allowsPassByReference = false;
+// // JFM this needs to be fixed
+// if (target instanceof AtomicComponentExtension) {
+// allowsPassByReference =
+// ((AtomicComponentExtension) target).isAllowsPassByReference();
+// }
+// if (targetWire.getSourceContract().isRemotable()
+// && !allowsPassByReference) {
+// Map<Operation<?>, InboundInvocationChain> chains = targetWire.getInboundInvocationChains();
+// for (Map.Entry<Operation<?>, InboundInvocationChain> entry : chains.entrySet()) {
+// targetOperation = entry.getKey();
+// sourceOperation =
+// getSourceOperation(sourceWire.getOutboundInvocationChains().keySet(), targetOperation.getName());
+//
+//
+// if (null != sourceOperation) {
+// argsDataBindings = resolveArgsDataBindings(targetOperation);
+// resultDataBinding = resolveResultDataBinding(targetOperation);
+// passByValueInterceptor = new PassByValueInterceptor();
+// passByValueInterceptor.setDataBinding(getDataBinding(targetOperation));
+// passByValueInterceptor.setArgsDataBindings(argsDataBindings);
+// passByValueInterceptor.setResultDataBinding(resultDataBinding);
+// entry.getValue().addInterceptor(0, passByValueInterceptor);
+// tailInterceptor =
+// sourceWire.getOutboundInvocationChains().get(sourceOperation).getTailInterceptor();
+// if (tailInterceptor != null) {
+// tailInterceptor.setNext(passByValueInterceptor);
+// }
+// }
+// }
+// }
+//
+// // Check if there's a callback
+// Map callbackOperations = sourceWire.getSourceContract().getCallbackOperations();
+// allowsPassByReference = false;
+// if (source instanceof AtomicComponentExtension) {
+// allowsPassByReference =
+// ((AtomicComponentExtension) source).isAllowsPassByReference();
+// }
+//
+// if (sourceWire.getSourceContract().isRemotable()
+// && !allowsPassByReference
+// && callbackOperations != null
+// && !callbackOperations.isEmpty()) {
+// //URI targetAddress = UriHelper.getBaseName(source.getUri());
+// Map<Operation<?>, InboundInvocationChain> callbackChains = sourceWire.getTargetCallbackInvocationChains();
+// for (Map.Entry<Operation<?>, InboundInvocationChain> entry : callbackChains.entrySet()) {
+// targetOperation = entry.getKey();
+// sourceOperation =
+// getSourceOperation(targetWire.getSourceCallbackInvocationChains(
+// sourceWire.getSourceUri()).keySet(),
+// targetOperation.getName());
+//
+// argsDataBindings = resolveArgsDataBindings(targetOperation);
+// resultDataBinding = resolveResultDataBinding(targetOperation);
+//
+// passByValueInterceptor = new PassByValueInterceptor();
+// passByValueInterceptor.setDataBinding(getDataBinding(targetOperation));
+// passByValueInterceptor.setArgsDataBindings(argsDataBindings);
+// passByValueInterceptor.setResultDataBinding(resultDataBinding);
+//
+// entry.getValue().addInterceptor(0, passByValueInterceptor);
+// tailInterceptor =
+// targetWire.getSourceCallbackInvocationChains(sourceWire.getSourceUri()).get(sourceOperation)
+// .getTailInterceptor();
+// if (tailInterceptor != null) {
+// tailInterceptor.setNext(passByValueInterceptor);
+// }
+// }
+// }
+// }
+
+// private Operation getSourceOperation(Set<Operation<?>> operations, String operationName) {
+// for (Operation<?> op : operations) {
+// if (op.getName().equals(operationName)) {
+// return op;
+// }
+// }
+// return null;
+// }
+//
+// private DataBinding getDataBinding(Operation<?> operation) {
+// String dataBinding = operation.getDataBinding();
+// if (dataBinding == null) {
+// ServiceContract<?> serviceContract = operation.getServiceContract();
+// dataBinding = serviceContract.getDataBinding();
+// }
+// return dataBindingRegistry.getDataBinding(dataBinding);
+//
+// }
+
+// @SuppressWarnings("unchecked")
+// private DataBinding[] resolveArgsDataBindings(Operation operation) {
+// List<DataType<?>> argumentTypes = (List<DataType<?>>) operation.getInputType().getLogical();
+// DataBinding[] argDataBindings = new DataBinding[argumentTypes.size()];
+// int count = 0;
+// for (DataType argType : argumentTypes) {
+// argDataBindings[count] = null;
+// if (argType != null) {
+// if (argType.getLogical() instanceof Class) {
+// argDataBindings[count] =
+// dataBindingRegistry.getDataBinding(((Class) argType.getLogical()).getName());
+// }
+// }
+// ++count;
+// }
+// return argDataBindings;
+// }
+//
+// private DataBinding resolveResultDataBinding(Operation operation) {
+// DataType<?> resultType = (DataType<?>) operation.getOutputType();
+// DataBinding resultBinding = null;
+// if (resultType != null && resultType.getLogical() instanceof Class) {
+// Class<?> logical = (Class<?>) resultType.getLogical();
+// resultBinding = dataBindingRegistry.getDataBinding(logical.getName());
+// }
+// return resultBinding;
+// }
+//
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/PipedTransformer.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/PipedTransformer.java
new file mode 100755
index 0000000000..388ea710a7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/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.core.databinding.impl;
+
+import org.apache.tuscany.spi.databinding.DataPipe;
+import org.apache.tuscany.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.PushTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+
+/**
+ * A utility class to connect PushTransformer and DataPipe to create a
+ * PullTransformer
+ *
+ * @param <S> Source type
+ * @param <I> Intermidate type
+ * @param <R> Result type
+ */
+public class PipedTransformer<S, I, R> implements PullTransformer<S, R> {
+ private PushTransformer<S, I> pusher;
+
+ private DataPipe<I, R> pipe;
+
+ /**
+ * @param pumper
+ * @param pipe
+ */
+ public PipedTransformer(PushTransformer<S, I> pumper, DataPipe<I, R> 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/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/SimpleDataBinding.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/SimpleDataBinding.java
new file mode 100644
index 0000000000..b1550c9f0a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/SimpleDataBinding.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.core.databinding.impl;
+
+import org.osoa.sca.annotations.Property;
+
+import org.apache.tuscany.spi.databinding.extension.DataBindingExtension;
+import org.apache.tuscany.spi.loader.MissingResourceException;
+
+/**
+ * Simple databinding represented by a base java type. A SCDL property className is used to customize this component.
+ * <p/>
+ * The following illustrates how a simple data binding can be registered as a SCA component.
+ * <p/>
+ * <pre>
+ * &lt;component name="databinding.MyDataBinding"&gt;<br>
+ * &nbsp;&nbsp;&lt;system:implementation.java
+ * class="org.apache.tuscany.databinding.impl.SimpleDataBinding"/&gt;<br>
+ * &nbsp;&nbsp;&lt;property name="className"&gt;my.Type&lt;/property&gt;<br>
+ * &lt/component&gt;
+ * </pre>
+ *
+ * @version $Rv$ $Date$
+ */
+public class SimpleDataBinding extends DataBindingExtension {
+
+ public SimpleDataBinding(@Property(name = "className")String className) throws MissingResourceException {
+ super(resolve(className));
+ }
+
+ private static Class<?> resolve(String className) throws MissingResourceException {
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ return Class.forName(className, false, classLoader);
+ } catch (ClassNotFoundException e) {
+ classLoader = SimpleDataBinding.class.getClassLoader();
+ try {
+ return Class.forName(className, false, classLoader);
+ } catch (ClassNotFoundException e1) {
+ throw new MissingResourceException(className, e1);
+ }
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/TransformationContextImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/TransformationContextImpl.java
new file mode 100755
index 0000000000..47f340097b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/TransformationContextImpl.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.impl;
+
+import java.lang.ref.WeakReference;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.model.DataType;
+
+public class TransformationContextImpl implements TransformationContext {
+ private DataType sourceDataType;
+
+ private DataType targetDataType;
+
+ private final Map<Class<?>, Object> metadata = new HashMap<Class<?>, Object>();
+
+ private WeakReference<ClassLoader> classLoaderRef;
+
+ public TransformationContextImpl() {
+ super();
+ setClassLoader(Thread.currentThread().getContextClassLoader());
+ }
+
+ public TransformationContextImpl(DataType sourceDataType,
+ DataType targetDataType,
+ ClassLoader classLoader,
+ Map<Class<?>, Object> 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>(classLoader);
+ }
+
+ public ClassLoader getClassLoader() {
+ return classLoaderRef.get();
+ }
+
+ public Map<Class<?>, Object> getMetadata() {
+ return metadata;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/TransformerRegistryImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/TransformerRegistryImpl.java
new file mode 100755
index 0000000000..c8bfa1cc8c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/TransformerRegistryImpl.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.core.databinding.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.osoa.sca.annotations.EagerInit;
+
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.TransformerRegistry;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+public class TransformerRegistryImpl implements TransformerRegistry {
+
+ private final DirectedGraph<Object, Transformer> graph = new DirectedGraph<Object, Transformer>();
+
+ public void registerTransformer(String sourceType, String resultType, int weight, Transformer transformer) {
+ graph.addEdge(sourceType, resultType, transformer, weight);
+ }
+
+ public void registerTransformer(Transformer transformer) {
+ graph.addEdge(transformer.getSourceDataBinding(),
+ transformer.getTargetDataBinding(),
+ transformer,
+ transformer.getWeight());
+ }
+
+ public boolean unregisterTransformer(String sourceType, String resultType) {
+ return graph.removeEdge(sourceType, resultType);
+ }
+
+ public Transformer getTransformer(String sourceType, String resultType) {
+ DirectedGraph<Object, Transformer>.Edge edge = graph.getEdge(sourceType, resultType);
+ return (edge == null) ? null : edge.getValue();
+ }
+
+ public List<Transformer> getTransformerChain(String sourceType, String resultType) {
+ List<Transformer> transformers = new ArrayList<Transformer>();
+ DirectedGraph<Object, Transformer>.Path path = graph.getShortestPath(sourceType, resultType);
+ if (path == null) {
+ return null;
+ }
+ for (DirectedGraph<Object, Transformer>.Edge edge : path.getEdges()) {
+ transformers.add(edge.getValue());
+ }
+ return transformers;
+ }
+
+ public String toString() {
+ return graph.toString();
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformer.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformer.java
new file mode 100644
index 0000000000..38f02cdc28
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformer.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.core.databinding.javabeans;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.osoa.sca.annotations.Service;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Transformer to convert data from DOM Node to JavaBean
+ */
+@Service(Transformer.class)
+public class DOMNode2JavaBeanTransformer extends XML2JavaBeanTransformer<Node> {
+
+ @Override
+ public List<Node> getChildElements(Node parent) throws XML2JavaMapperException {
+ NodeList nodeList = parent.getChildNodes();
+ List<Node> nodeArrayList = new ArrayList<Node>(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.getNodeName();
+ }
+
+ @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/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/Java2XMLMapperException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/Java2XMLMapperException.java
new file mode 100644
index 0000000000..3f88a4ee89
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/Java2XMLMapperException.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.databinding.javabeans;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * This exception is used to encapsulate and rethrow exceptions that arise out
+ * of converting JavaBean objects to XML
+ */
+public class Java2XMLMapperException extends TuscanyRuntimeException {
+ private static final long serialVersionUID = 6811924384399578686L;
+
+ private QName xmlElementName;
+ private String javaFieldName;
+ private Class javaType;
+
+ public Java2XMLMapperException(String message) {
+ super(message);
+ }
+
+ public Java2XMLMapperException(Throwable cause) {
+ super(cause);
+ }
+
+ public String getJavaFieldName() {
+ return javaFieldName;
+ }
+
+ public void setJavaFieldName(String javaFieldName) {
+ this.javaFieldName = javaFieldName;
+ }
+
+ public Class getJavaType() {
+ return javaType;
+ }
+
+ public void setJavaType(Class javaType) {
+ this.javaType = javaType;
+ }
+
+ public QName getXmlElementName() {
+ return xmlElementName;
+ }
+
+ public void setXmlElementName(QName xmlElementName) {
+ this.xmlElementName = xmlElementName;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformer.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformer.java
new file mode 100644
index 0000000000..5925e87b69
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformer.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.core.databinding.javabeans;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.DOMHelper;
+import org.osoa.sca.annotations.Service;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * Transformer to convert data from a JavaBean object to DOM Node
+ */
+@Service(Transformer.class)
+public class JavaBean2DOMNodeTransformer extends JavaBean2XMLTransformer<Node> {
+
+ 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/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2XMLTransformer.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2XMLTransformer.java
new file mode 100644
index 0000000000..5d4b69ffbb
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2XMLTransformer.java
@@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.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.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.SimpleTypeMapperExtension;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * Transformer to convert data from a JavaBean object to xml
+ */
+@Service(Transformer.class)
+public abstract class JavaBean2XMLTransformer<T> extends TransformerExtension<Object, T> implements
+ PullTransformer<Object, T> {
+
+ 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 SimpleTypeMapperExtension mapper;
+
+ public JavaBean2XMLTransformer() {
+ this.mapper = new SimpleTypeMapperExtension();
+ }
+
+ public T transform(Object source, TransformationContext context) {
+ QName rootElementName = (QName)context.getTargetDataType().getMetadata("RootElementName");
+ if (rootElementName == null) {
+ 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++;
+ }
+
+ public abstract T createElement(QName qName) throws Java2XMLMapperException;
+ public abstract T createText(String textData) throws Java2XMLMapperException;
+ public abstract void appendChild(T parentElement, T childElement) throws Java2XMLMapperException;
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/JavaBeansDataBinding.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/JavaBeansDataBinding.java
new file mode 100644
index 0000000000..a944706918
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/JavaBeansDataBinding.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.core.databinding.javabeans;
+
+import org.apache.tuscany.spi.databinding.DataBinding;
+import org.apache.tuscany.spi.databinding.extension.DataBindingExtension;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * DataBinding for JavaBeans
+ */
+@Service(DataBinding.class)
+public class JavaBeansDataBinding extends DataBindingExtension {
+
+ public static final String NAME = Object.class.getName();
+
+ public JavaBeansDataBinding() {
+ super(Object.class);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/XML2JavaBeanTransformer.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/XML2JavaBeanTransformer.java
new file mode 100644
index 0000000000..7f9753259c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/XML2JavaBeanTransformer.java
@@ -0,0 +1,299 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.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 org.apache.tuscany.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.SimpleTypeMapperExtension;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.apache.tuscany.spi.model.ElementInfo;
+import org.apache.tuscany.spi.model.TypeInfo;
+
+import org.osoa.sca.annotations.Service;
+
+/**
+ * Transformer to convert data from XML to JavaBean
+ */
+@Service(Transformer.class)
+public abstract class XML2JavaBeanTransformer<T> extends TransformerExtension<T, Object> implements
+ PullTransformer<T, Object> {
+
+ public static final String SET = "set";
+
+ protected SimpleTypeMapperExtension mapper;
+
+ public XML2JavaBeanTransformer() {
+ this.mapper = new SimpleTypeMapperExtension();
+ }
+
+ public Object transform(T source, TransformationContext context) {
+ TypeInfo xmlType =
+ (TypeInfo) context.getSourceDataType().getMetadata(TypeInfo.class.getName());
+ if (xmlType == null) {
+ ElementInfo element =
+ (ElementInfo) context.getSourceDataType()
+ .getMetadata(ElementInfo.class.getName());
+ xmlType = (TypeInfo) element.getType();
+ }
+
+ return toJavaObject(xmlType, source, context);
+ }
+
+ public Object toJavaObject(TypeInfo xmlType, T xmlElement, TransformationContext context) {
+ if (xmlType.isSimpleType()) {
+ return mapper.toJavaObject(xmlType, getText(xmlElement), context);
+ } else {
+ Class<?> javaType = (Class<?>) context.getTargetDataType().getLogical();
+ return createJavaObject(xmlElement, javaType, context);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private <L> L createJavaObject(T element, Class<L> javaType, TransformationContext context)
+ throws XML2JavaMapperException {
+ List<T> childElements = getChildElements(element);
+ if (childElements.size() == 1 && isTextElement(childElements.get(0))) {
+ return (L) mapper.toJavaObject(mapper.getXMLType(javaType),
+ getText(childElements.get(0)),
+ context);
+ } else {
+ String fieldName = null;
+ try {
+ L javaInstance = javaType.newInstance();
+ Map<Field, List<Object>> arrayFields = new Hashtable<Field, List<Object>>();
+ Map<Method, List<Object>> arraySetters = new Hashtable<Method, List<Object>>();
+ 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<Field, List<Object>> arrayFields,
+ TransformationContext context) throws IllegalAccessException {
+ Class<?> javaFieldType = (Class<?>) javaField.getType();
+
+ if (javaFieldType.isArray()) {
+ Class<?> componentType = javaFieldType.getComponentType();
+ List<Object> fldValueArray = arrayFields.get(javaField);
+ if (fldValueArray == null) {
+ fldValueArray = new ArrayList<Object>();
+ 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<Method, List<Object>> 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<Object> setterValueArray = arraySetters.get(aMethod);
+ if (setterValueArray == null) {
+ setterValueArray = new ArrayList<Object>();
+ 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<Field, List<Object>> arrayFields,
+ Map<Method, List<Object>> 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<T> getChildElements(T parent) throws XML2JavaMapperException;
+
+ public abstract String getElementName(T element) throws XML2JavaMapperException;
+
+ public abstract boolean isTextElement(T element) throws XML2JavaMapperException;
+
+ public Class getTargetType() {
+ return Object.class;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/XML2JavaMapperException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/XML2JavaMapperException.java
new file mode 100644
index 0000000000..f2910e6946
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/javabeans/XML2JavaMapperException.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.core.databinding.javabeans;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * This exception is used to encapsulate and rethrow exceptions that arise out of converting XML Data to Java Objects.
+ *
+ * @version $Rev$ $Date$
+ */
+public class XML2JavaMapperException extends TuscanyRuntimeException {
+ 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;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/DOMDataBinding.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/DOMDataBinding.java
new file mode 100644
index 0000000000..d2df8cf888
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/DOMDataBinding.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.core.databinding.xml;
+
+
+import org.w3c.dom.Node;
+
+import org.apache.tuscany.spi.databinding.WrapperHandler;
+import org.apache.tuscany.spi.databinding.extension.DataBindingExtension;
+
+/**
+ * DOM DataBinding
+ *
+ * @version $Rev$ $Date$
+ */
+public class DOMDataBinding extends DataBindingExtension {
+ public static final String NAME = Node.class.getName();
+
+ public DOMDataBinding() {
+ super(Node.class);
+ }
+
+ @Override
+ public WrapperHandler getWrapperHandler() {
+ return new DOMWrapperHandler();
+ }
+
+ public Object copy(Object source) {
+ if (Node.class.isAssignableFrom(source.getClass())) {
+ Node nodeSource = (Node) source;
+ Node2String strTransformer = new Node2String();
+ String stringCopy = strTransformer.transform(nodeSource, null);
+
+ String2Node nodeTransformer = new String2Node();
+ return nodeTransformer.transform(stringCopy, null);
+ }
+
+ return super.copy(source);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/DOMWrapperHandler.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/DOMWrapperHandler.java
new file mode 100644
index 0000000000..4ef0af6701
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/DOMWrapperHandler.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.core.databinding.xml;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.WrapperHandler;
+import org.apache.tuscany.spi.databinding.extension.DOMHelper;
+import org.apache.tuscany.spi.model.ElementInfo;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class DOMWrapperHandler implements WrapperHandler<Node> {
+
+ 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 Object getChild(Node wrapper, int i, ElementInfo element) {
+ int index = 0;
+ NodeList nodes = wrapper.getChildNodes();
+ for (int j = 0; j < nodes.getLength(); j++) {
+ Node node = nodes.item(j);
+ if (node.getNodeType() != Node.ELEMENT_NODE) {
+ continue;
+ }
+ if (index != i) {
+ index++;
+ } else {
+ QName name = DOMHelper.getQName(node);
+ if (name.equals(element.getQName())) {
+ return node;
+ }
+ }
+ }
+ return null;
+ }
+
+ 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));
+ }
+} \ No newline at end of file
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/DOMXMLStreamReader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/DOMXMLStreamReader.java
new file mode 100644
index 0000000000..f94ddd545f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/DOMXMLStreamReader.java
@@ -0,0 +1,1415 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.xml;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import javax.xml.XMLConstants;
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
+
+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;
+
+import org.apache.tuscany.core.databinding.xml.StAXHelper.XMLFragmentStreamReader;
+
+public class DOMXMLStreamReader implements XMLFragmentStreamReader {
+ protected static class DelegatingNamespaceContext implements NamespaceContext {
+ private int counter;
+
+ private NamespaceContext parent;
+
+ private Map<String, String> prefixToNamespaceMapping = new HashMap<String, String>();
+
+ public DelegatingNamespaceContext(NamespaceContext parent) {
+ super();
+ this.parent = parent;
+
+ 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);
+ }
+ 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 if (parent != null) {
+ return parent.getNamespaceURI(prefix);
+ } else {
+ return null;
+ }
+ }
+
+ public String getPrefix(String nsURI) {
+ if (nsURI == null) {
+ throw new IllegalArgumentException("Namespace is null");
+ }
+ for (Map.Entry<String, String> entry1 : prefixToNamespaceMapping.entrySet()) {
+ Map.Entry entry = entry1;
+ if (entry.getValue().equals(nsURI)) {
+ return (String) entry.getKey();
+ }
+ }
+ if (parent != null) {
+ return parent.getPrefix(nsURI);
+ } else {
+ return null;
+ }
+ }
+
+ public Iterator getPrefixes(String nsURI) {
+ List<String> prefixList = new ArrayList<String>();
+ for (Map.Entry<String, String> entry : prefixToNamespaceMapping.entrySet()) {
+ if (entry.getValue().equals(nsURI)) {
+ prefixList.add(entry.getKey());
+ }
+ }
+ if (parent != null) {
+ for (Iterator i = parent.getPrefixes(nsURI); i.hasNext();) {
+ prefixList.add((String) i.next());
+ }
+ }
+ return prefixList.iterator();
+ }
+
+ public void registerMapping(String prefix, String nsURI) {
+ prefixToNamespaceMapping.put(prefix, nsURI);
+ }
+
+ public void removeMapping(String prefix) {
+ prefixToNamespaceMapping.remove(prefix);
+ }
+
+ public void setParent(NamespaceContext parent) {
+ this.parent = parent;
+ }
+ }
+
+ 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;
+ }
+
+ }
+
+ protected static class SimpleElementStreamReader implements XMLFragmentStreamReader {
+
+ private static final int END_ELEMENT_STATE = 2;
+
+ private static final int START_ELEMENT_STATE = 0;
+
+ private static final int START_ELEMENT_STATE_WITH_NULL = 3;
+
+ private static final int TEXT_STATE = 1;
+
+ private static final QName XSI_NIL_QNAME =
+ new QName("http://www.w3.org/2001/XMLSchema-instance", "nil", "xsi");
+
+ private QName name;
+
+ private DelegatingNamespaceContext namespaceContext = new DelegatingNamespaceContext(null);
+
+ private int state = START_ELEMENT_STATE;
+
+ private String value;
+
+ public SimpleElementStreamReader(QName name, String value) {
+ this.name = name;
+ this.value = value;
+ if (value == null) {
+ state = START_ELEMENT_STATE_WITH_NULL;
+ }
+ }
+
+ public void close() throws XMLStreamException {
+ // Do nothing - we've nothing to free here
+ }
+
+ public int getAttributeCount() {
+ if (state == START_ELEMENT_STATE_WITH_NULL) {
+ return 1;
+ }
+ if (state == START_ELEMENT_STATE) {
+ return 0;
+ } else {
+ throw new IllegalStateException();
+ }
+
+ }
+
+ public String getAttributeLocalName(int i) {
+ if (state == START_ELEMENT_STATE_WITH_NULL && i == 0) {
+ return XSI_NIL_QNAME.getLocalPart();
+ }
+ if (state == START_ELEMENT_STATE) {
+ return null;
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public QName getAttributeName(int i) {
+ if (state == START_ELEMENT_STATE_WITH_NULL && i == 0) {
+ return XSI_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 XSI_NIL_QNAME.getNamespaceURI();
+ }
+ 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 XSI_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 "true";
+ }
+ if (state == START_ELEMENT_STATE) {
+ return null;
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeValue(String string, String string1) {
+ if (state == TEXT_STATE) {
+ // todo something
+ return null;
+ } else {
+ return null;
+ }
+
+ }
+
+ public String getCharacterEncodingScheme() {
+ return null;
+ }
+
+ 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 String getEncoding() {
+ return "UTF-8";
+ }
+
+ public int getEventType() {
+ switch (state) {
+ case START_ELEMENT_STATE:
+ case START_ELEMENT_STATE_WITH_NULL:
+ 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 getLocalName() {
+ if (state != TEXT_STATE) {
+ return name.getLocalPart();
+ } else {
+ return null;
+ }
+ }
+
+ 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() {
+ if (state != TEXT_STATE) {
+ return name;
+ } else {
+ return null;
+ }
+ }
+
+ public NamespaceContext getNamespaceContext() {
+ return this.namespaceContext;
+ }
+
+ 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 XSI_NIL_QNAME.getPrefix();
+ } else {
+ return null;
+ }
+ }
+
+ public String getNamespaceURI() {
+ if (state != TEXT_STATE) {
+ return name.getNamespaceURI();
+ } else {
+ return null;
+ }
+
+ }
+
+ public String getNamespaceURI(int i) {
+ if (state == START_ELEMENT_STATE_WITH_NULL && isXsiNamespacePresent() && i == 0) {
+ return XSI_NIL_QNAME.getNamespaceURI();
+ } else {
+ return null;
+ }
+ }
+
+ public String getNamespaceURI(String prefix) {
+ return namespaceContext.getNamespaceURI(prefix);
+ }
+
+ public String getPIData() {
+ return null;
+ }
+
+ public String getPITarget() {
+ return null;
+ }
+
+ public String getPrefix() {
+ if (state != TEXT_STATE) {
+ return name.getPrefix();
+ } else {
+ return null;
+ }
+ }
+
+ public Object getProperty(String key) throws IllegalArgumentException {
+ return null;
+ }
+
+ 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 getTextLength() {
+ if (state == TEXT_STATE) {
+ return value.length();
+ } else {
+ throw new IllegalStateException();
+ }
+
+ }
+
+ public int getTextStart() {
+ if (state == TEXT_STATE) {
+ return 0;
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getVersion() {
+ return null; // todo 1.0 ?
+ }
+
+ public boolean hasName() {
+ return state != TEXT_STATE;
+
+ }
+
+ public boolean hasNext() throws XMLStreamException {
+ return state != END_ELEMENT_STATE;
+ }
+
+ public boolean hasText() {
+ return state == TEXT_STATE;
+ }
+
+ public void init() {
+ // just add the current elements namespace and prefix to the this
+ // elements nscontext
+ registerNamespace(name.getPrefix(), name.getNamespaceURI());
+
+ }
+
+ public boolean isAttributeSpecified(int i) {
+ return false; // no attribs here
+ }
+
+ public boolean isCharacters() {
+ return state == TEXT_STATE;
+ }
+
+ public boolean isEndElement() {
+ return state == END_ELEMENT_STATE;
+ }
+
+ public boolean isEndOfFragment() {
+ return state == END_ELEMENT_STATE;
+ }
+
+ public boolean isStandalone() {
+ return false;
+ }
+
+ public boolean isStartElement() {
+ return state == START_ELEMENT_STATE || state == START_ELEMENT_STATE_WITH_NULL;
+ }
+
+ public boolean isWhiteSpace() {
+ return false; // no whitespaces here
+ }
+
+ /**
+ * Test whether the xsi namespace is present
+ *
+ * @return
+ */
+ private boolean isXsiNamespacePresent() {
+ return namespaceContext.getNamespaceURI(XSI_NIL_QNAME.getPrefix()) != null;
+ }
+
+ public int next() throws XMLStreamException {
+ switch (state) {
+ case START_ELEMENT_STATE:
+ state = TEXT_STATE;
+ return CHARACTERS;
+ case START_ELEMENT_STATE_WITH_NULL:
+ state = END_ELEMENT_STATE;
+ return END_ELEMENT;
+ 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 int nextTag() throws XMLStreamException {
+ return 0; // todo
+ }
+
+ /**
+ * @param prefix
+ * @param uri
+ */
+ private void registerNamespace(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.registerMapping(prefix, uri);
+ }
+ }
+
+ public void require(int i, String string, String string1) throws XMLStreamException {
+ // not implemented
+ }
+
+ public void setParentNamespaceContext(NamespaceContext nsContext) {
+ this.namespaceContext.setParent(nsContext);
+ }
+
+ public boolean standaloneSet() {
+ return false;
+ }
+
+ }
+
+ private static final int DELEGATED_STATE = 2;
+
+ private static final int END_ELEMENT_STATE = 1;
+
+ // states for this pullparser - it can only have three states
+ private static final int START_ELEMENT_STATE = 0;
+
+ private static final int TEXT_STATE = 3;
+
+ private Map.Entry[] attributes;
+
+ // reference to the child reader
+ private XMLFragmentStreamReader childReader;
+
+ // current property index
+ private int currentPropertyIndex;
+
+ private Map<String, String> declaredNamespaceMap = new HashMap<String, String>();
+
+ private QName elementQName;
+
+ // we always create a new namespace context
+ private DelegatingNamespaceContext namespaceContext = new DelegatingNamespaceContext(null);
+
+ private Map.Entry[] properties;
+
+ private Element rootElement;
+
+ private String rootElementName;
+
+ private String rootElementURI;
+
+ // integer field that keeps the state of this
+ // parser.
+ private int state = START_ELEMENT_STATE;
+
+ public DOMXMLStreamReader(Node node) {
+ 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");
+ }
+ this.rootElementName = rootElement.getLocalName();
+ this.rootElementURI = rootElement.getNamespaceURI();
+
+ declaredNamespaceMap.put("xml", "http://www.w3.org/XML/1998/namespace");
+ declaredNamespaceMap.put("xmlns", "http://www.w3.org/2000/xmlns/");
+ declaredNamespaceMap.put("xsi", "http://www.w3.org/2001/XMLSchema-instance");
+
+ populateProperties();
+ }
+
+ /*
+ * we need to pass in a namespace context since when delegated, we've no
+ * idea of the current namespace context. So it needs to be passed on here!
+ */
+ protected DOMXMLStreamReader(QName elementQName, Map.Entry[] properties, Map.Entry[] attributes) {
+ // validate the lengths, since both the arrays are supposed
+ // to have
+ this.properties = properties;
+ this.elementQName = elementQName;
+ this.attributes = attributes;
+
+ }
+
+ public void close() throws XMLStreamException {
+ // do nothing here - we have no resources to free
+ }
+
+ public int getAttributeCount() {
+ return (state == DELEGATED_STATE) ? childReader.getAttributeCount()
+ : ((attributes != null) && (state == START_ELEMENT_STATE) ? attributes.length : 0);
+ }
+
+ public String getAttributeLocalName(int i) {
+ if (state == DELEGATED_STATE) {
+ return childReader.getAttributeLocalName(i);
+ } else if (state == START_ELEMENT_STATE) {
+ QName name = getAttributeName(i);
+ if (name == null) {
+ return null;
+ } else {
+ return name.getLocalPart();
+ }
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ /**
+ * @param i
+ * @return
+ */
+ public QName getAttributeName(int i) {
+ if (state == DELEGATED_STATE) {
+ return childReader.getAttributeName(i);
+ } else if (state == START_ELEMENT_STATE) {
+ if (attributes == null) {
+ return null;
+ } else {
+ if ((i >= (attributes.length)) || i < 0) { // out of range
+ return null;
+ } else {
+ // get the attribute pointer
+ Object attribPointer = attributes[i].getKey();
+ // case one - attrib name is null
+ // this should be the pointer to the OMAttribute then
+ if (attribPointer instanceof String) {
+ return new QName((String) attribPointer);
+ } else if (attribPointer instanceof QName) {
+ return (QName) attribPointer;
+ } else {
+ return null;
+ }
+ }
+ }
+ } else {
+ throw new IllegalStateException(); // as per the api contract
+ }
+
+ }
+
+ public String getAttributeNamespace(int i) {
+ if (state == DELEGATED_STATE) {
+ return childReader.getAttributeNamespace(i);
+ } else if (state == START_ELEMENT_STATE) {
+ QName name = getAttributeName(i);
+ if (name == null) {
+ return null;
+ } else {
+ return name.getNamespaceURI();
+ }
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributePrefix(int i) {
+ if (state == DELEGATED_STATE) {
+ return childReader.getAttributePrefix(i);
+ } else if (state == START_ELEMENT_STATE) {
+ QName name = getAttributeName(i);
+ if (name == null) {
+ return null;
+ } else {
+ return name.getPrefix();
+ }
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeType(int i) {
+ return null; // not supported
+ }
+
+ public String getAttributeValue(int i) {
+ if (state == DELEGATED_STATE) {
+ return childReader.getAttributeValue(i);
+ } else if (state == START_ELEMENT_STATE) {
+ if (attributes == null) {
+ return null;
+ } else {
+ if ((i >= (attributes.length)) || i < 0) { // out of range
+ return null;
+ } else {
+ // get the attribute pointer
+ Object attribPointer = attributes[i].getKey();
+ Object omAttribObj = attributes[i].getValue();
+ // case one - attrib name is null
+ // this should be the pointer to the OMAttribute then
+ if (attribPointer instanceof String) {
+ return (String) omAttribObj;
+ } else if (attribPointer instanceof QName) {
+ return (String) omAttribObj;
+ } else {
+ return null;
+ }
+ }
+ }
+ } else {
+ throw new IllegalStateException();
+ }
+
+ }
+
+ public String getAttributeValue(String nsUri, String localName) {
+
+ int attribCount = getAttributeCount();
+ String returnValue = null;
+ QName attribQualifiedName;
+ for (int i = 0; i < attribCount; i++) {
+ attribQualifiedName = getAttributeName(i);
+ if (nsUri == null) {
+ if (localName.equals(attribQualifiedName.getLocalPart())) {
+ returnValue = getAttributeValue(i);
+ break;
+ }
+ } else {
+ if (localName.equals(attribQualifiedName.getLocalPart()) && nsUri.equals(attribQualifiedName
+ .getNamespaceURI())) {
+ returnValue = getAttributeValue(i);
+ break;
+ }
+ }
+
+ }
+
+ return returnValue;
+ }
+
+ public String getCharacterEncodingScheme() {
+ return null; // todo - should we return something for this ?
+ }
+
+ /**
+ * todo implement the right contract for this
+ *
+ * @return
+ * @throws XMLStreamException
+ */
+ public String getElementText() throws XMLStreamException {
+ if (state == DELEGATED_STATE) {
+ return childReader.getElementText();
+ } else {
+ return null;
+ }
+
+ }
+
+ public String getEncoding() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getEncoding();
+ } else {
+ // we've no idea what the encoding is going to be in this case
+ // perhaps we ought to return some constant here, which the user
+ // might
+ // have access to change!
+ return null;
+ }
+ }
+
+ // /////////////////////////////////////////////////////////////////////////
+ // / attribute handling
+ // /////////////////////////////////////////////////////////////////////////
+
+ public int getEventType() {
+ if (state == START_ELEMENT_STATE) {
+ return START_ELEMENT;
+ } else if (state == END_ELEMENT_STATE) {
+ return END_ELEMENT;
+ } else { // this is the delegated state
+ return childReader.getEventType();
+ }
+
+ }
+
+ public String getLocalName() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getLocalName();
+ } else if (state != TEXT_STATE) {
+ return elementQName.getLocalPart();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ /**
+ * @return
+ */
+ public Location getLocation() {
+ // return a default location
+ 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() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getName();
+ } else if (state != TEXT_STATE) {
+ return elementQName;
+ } else {
+ throw new IllegalStateException();
+ }
+
+ }
+
+ public NamespaceContext getNamespaceContext() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getNamespaceContext();
+ } else {
+ return namespaceContext;
+ }
+
+ }
+
+ public int getNamespaceCount() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getNamespaceCount();
+ } else {
+ return declaredNamespaceMap.size();
+ }
+ }
+
+ /**
+ * @param i
+ * @return
+ */
+ public String getNamespacePrefix(int i) {
+ if (state == DELEGATED_STATE) {
+ return childReader.getNamespacePrefix(i);
+ } else if (state != TEXT_STATE) {
+ // order the prefixes
+ String[] prefixes = makePrefixArray();
+ if ((i >= prefixes.length) || (i < 0)) {
+ return null;
+ } else {
+ return prefixes[i];
+ }
+
+ } else {
+ throw new IllegalStateException();
+ }
+
+ }
+
+ public String getNamespaceURI() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getNamespaceURI();
+ } else if (state == TEXT_STATE) {
+ return null;
+ } else {
+ return elementQName.getNamespaceURI();
+ }
+ }
+
+ public String getNamespaceURI(int i) {
+ if (state == DELEGATED_STATE) {
+ return childReader.getNamespaceURI(i);
+ } else if (state != TEXT_STATE) {
+ String namespacePrefix = getNamespacePrefix(i);
+ return namespacePrefix == null ? null : (String) declaredNamespaceMap.get(namespacePrefix);
+ } else {
+ throw new IllegalStateException();
+ }
+
+ }
+
+ // /////////////////////////////////////////////////////////////////////////
+ // //////////// end of attribute handling
+ // /////////////////////////////////////////////////////////////////////////
+
+ // //////////////////////////////////////////////////////////////////////////
+ // //////////// namespace handling
+ // //////////////////////////////////////////////////////////////////////////
+
+ public String getNamespaceURI(String prefix) {
+ return namespaceContext.getNamespaceURI(prefix);
+ }
+
+ public String getPIData() {
+ throw new UnsupportedOperationException("Yet to be implemented !!");
+ }
+
+ public String getPITarget() {
+ throw new UnsupportedOperationException("Yet to be implemented !!");
+ }
+
+ public String getPrefix() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getPrefix();
+ } else if (state == TEXT_STATE) {
+ return null;
+ } else {
+ return elementQName.getPrefix();
+ }
+ }
+
+ /**
+ * @param key
+ * @return
+ * @throws IllegalArgumentException
+ */
+ public Object getProperty(String key) throws IllegalArgumentException {
+ if (state == START_ELEMENT_STATE || state == END_ELEMENT_STATE) {
+ return null;
+ } else if (state == TEXT_STATE) {
+ return null;
+ } else if (state == DELEGATED_STATE) {
+ return childReader.getProperty(key);
+ } else {
+ return null;
+ }
+
+ }
+
+ // /////////////////////////////////////////////////////////////////////////
+ // /////// end of namespace handling
+ // /////////////////////////////////////////////////////////////////////////
+
+ public String getText() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getText();
+ } else if (state == TEXT_STATE) {
+ return (String) properties[currentPropertyIndex - 1].getValue();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public char[] getTextCharacters() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getTextCharacters();
+ } else if (state == TEXT_STATE) {
+ return properties[currentPropertyIndex - 1].getValue() == null ? new char[0]
+ : ((String) properties[currentPropertyIndex - 1].getValue()).toCharArray();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public int getTextCharacters(int i, char[] chars, int i1, int i2) throws XMLStreamException {
+ if (state == DELEGATED_STATE) {
+ return childReader.getTextCharacters(i, chars, i1, i2);
+ } else if (state == TEXT_STATE) {
+ // todo - implement this
+ return 0;
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public int getTextLength() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getTextLength();
+ } else if (state == TEXT_STATE) {
+ return 0; // assume text always starts at 0
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public int getTextStart() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getTextStart();
+ } else if (state == TEXT_STATE) {
+ return 0; // assume text always starts at 0
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getVersion() {
+ return null;
+ }
+
+ public boolean hasName() {
+ // since this parser always has a name, the hasname
+ // has to return true if we are still navigating this element
+ // if not we should ask the child reader for it.
+ if (state == DELEGATED_STATE) {
+ return childReader.hasName();
+ } else {
+ return state != TEXT_STATE;
+ }
+ }
+
+ /**
+ * @return
+ * @throws XMLStreamException
+ */
+ public boolean hasNext() throws XMLStreamException {
+ if (state == DELEGATED_STATE) {
+ if (childReader.isEndOfFragment()) {
+ // the child reader is done. We shouldn't be getting the
+ // hasnext result from the child pullparser then
+ return true;
+ } else {
+ return childReader.hasNext();
+ }
+ } else {
+ return state == START_ELEMENT_STATE || state == TEXT_STATE;
+
+ }
+ }
+
+ /**
+ * check the validity of this implementation
+ *
+ * @return
+ */
+ public boolean hasText() {
+ if (state == DELEGATED_STATE) {
+ return childReader.hasText();
+ } else {
+ return state == TEXT_STATE;
+ }
+ }
+
+ /**
+ * we need to split out the calling to the populate namespaces seperately since this needs to be done *after*
+ * setting the parent namespace context. We cannot assume it will happen at construction!
+ */
+ public void init() {
+ // here we have an extra issue to attend to. we need to look at the
+ // prefixes and uris (the combination) and populate a hashmap of
+ // namespaces. The hashmap of namespaces will be used to serve the
+ // namespace context
+
+ populateNamespaceContext();
+ }
+
+ public boolean isAttributeSpecified(int i) {
+ return false; // not supported
+ }
+
+ public boolean isCharacters() {
+ if (state == START_ELEMENT_STATE || state == END_ELEMENT_STATE) {
+ return false;
+ }
+ return childReader.isCharacters();
+ }
+
+ public boolean isEndElement() {
+ if (state == START_ELEMENT_STATE) {
+ return false;
+ } else if (state == END_ELEMENT_STATE) {
+ return true;
+ }
+ return childReader.isEndElement();
+ }
+
+ /**
+ * are we done ?
+ *
+ * @return
+ */
+ public boolean isEndOfFragment() {
+ return state == END_ELEMENT_STATE;
+ }
+
+ public boolean isStandalone() {
+ return true;
+ }
+
+ public boolean isStartElement() {
+ if (state == START_ELEMENT_STATE) {
+ return true;
+ } else if (state == END_ELEMENT_STATE) {
+ return false;
+ }
+ return childReader.isStartElement();
+ }
+
+ public boolean isWhiteSpace() {
+ if (state == START_ELEMENT_STATE || state == END_ELEMENT_STATE) {
+ return false;
+ }
+ return childReader.isWhiteSpace();
+ }
+
+ /**
+ * Get the prefix list from the hastable and take that into an array
+ *
+ * @return
+ */
+ private String[] makePrefixArray() {
+ String[] prefixes =
+ (String[]) declaredNamespaceMap.keySet().toArray(new String[declaredNamespaceMap.size()]);
+ Arrays.sort(prefixes);
+ return prefixes;
+ }
+
+ public int next() throws XMLStreamException {
+ return updateStatus();
+ }
+
+ /**
+ * todo implement this
+ *
+ * @return
+ * @throws XMLStreamException
+ */
+ public int nextTag() throws XMLStreamException {
+ return 0;
+ }
+
+ // /////////////////////////////////////////////////////////////////////////
+ // / Other utility methods
+ // ////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Populates a namespace context
+ */
+ private void populateNamespaceContext() {
+
+ // first add the current element namespace to the namespace context
+ // declare it if not found
+ registerNamespace(elementQName.getPrefix(), elementQName.getNamespaceURI());
+
+ // traverse through the attributes and populate the namespace context
+ // the attrib list can be of many combinations
+ // the valid combinations are
+ // String - String
+ // QName - QName
+ // null - OMAttribute
+
+ if (attributes != null) {
+ for (int i = 0; i < attributes.length; i++) { // jump in two
+ Object attribName = attributes[i].getKey();
+ if (attribName instanceof String) {
+ // ignore this case - Nothing to do
+ } else if (attribName instanceof QName) {
+ QName attribQName = (QName) attribName;
+ registerNamespace(attribQName.getPrefix(), attribQName.getNamespaceURI());
+
+ }
+ }
+ }
+
+ }
+
+ public final void populateProperties() {
+ if (properties != null) {
+ return;
+ }
+ if (elementQName == null) {
+ elementQName = namespaceContext.createQName(this.rootElementURI, this.rootElementName);
+ } else {
+ elementQName =
+ namespaceContext.createQName(elementQName.getNamespaceURI(), elementQName.getLocalPart());
+ }
+
+ List<Object> elementList = new ArrayList<Object>();
+ List<Object> attributeList = new ArrayList<Object>();
+ NamedNodeMap nodeMap = rootElement.getAttributes();
+ for (int i = 0; i < nodeMap.getLength(); i++) {
+ Attr attr = (Attr) nodeMap.item(i);
+ if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(attr.getNamespaceURI())) {
+ // Skip xmlns:xxx
+ if (!attr.getName().equals(attr.getLocalName())) {
+ // Skip xmlns="..."
+ registerNamespace(attr.getLocalName(), attr.getValue());
+ } else {
+ registerNamespace(XMLConstants.DEFAULT_NS_PREFIX, attr.getValue());
+ }
+ continue;
+ }
+ QName attrName = new QName(attr.getNamespaceURI(), attr.getLocalName());
+ NameValuePair pair = new NameValuePair(attrName, attr.getValue());
+ attributeList.add(pair);
+ }
+ 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:
+ NameValuePair pair = new NameValuePair(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 NameValuePair(elementName, new DOMXMLStreamReader(element));
+ elementList.add(pair);
+ break;
+ }
+ }
+ properties = elementList.toArray(new Map.Entry[elementList.size()]);
+ attributes = attributeList.toArray(new Map.Entry[attributeList.size()]);
+ }
+
+ /**
+ * A convenient method to reuse the properties
+ *
+ * @return event to be thrown
+ * @throws XMLStreamException
+ */
+ private int processProperties() throws XMLStreamException {
+ // move to the next property depending on the current property
+ // index
+ Object propPointer = properties[currentPropertyIndex].getKey();
+ QName propertyQName = null;
+ boolean textFound = false;
+ if (propPointer == null) {
+ throw new XMLStreamException("property key cannot be null!");
+ } else if (propPointer instanceof String) {
+ // propPointer being a String has a special case
+ // that is it can be a the special constant ELEMENT_TEXT that
+ // says this text event
+ if (ELEMENT_TEXT.equals(propPointer)) {
+ textFound = true;
+ } else {
+ propertyQName = new QName((String) propPointer);
+ }
+ } else if (propPointer instanceof QName) {
+ propertyQName = (QName) propPointer;
+ } else {
+ // oops - we've no idea what kind of key this is
+ throw new XMLStreamException("unidentified property key!!!" + propPointer);
+ }
+
+ // ok! we got the key. Now look at the value
+ Object propertyValue = properties[currentPropertyIndex].getValue();
+ // cater for the special case now
+ if (textFound) {
+ // no delegation here - make the parser null and immediately
+ // return with the event characters
+ childReader = null;
+ state = TEXT_STATE;
+ currentPropertyIndex++;
+ return CHARACTERS;
+ } else if (propertyValue == null || propertyValue instanceof String) {
+ // strings are handled by the NameValuePairStreamReader
+ childReader = new SimpleElementStreamReader(propertyQName, (String) propertyValue);
+ childReader.setParentNamespaceContext(this.namespaceContext);
+ childReader.init();
+ } else if (propertyValue instanceof DOMXMLStreamReader) {
+ // ADBbean has it's own method to get a reader
+ XMLFragmentStreamReader reader = (DOMXMLStreamReader) propertyValue;
+ // we know for sure that this is an ADB XMLStreamreader.
+ // However we need to make sure that it is compatible
+ childReader = reader;
+ childReader.setParentNamespaceContext(this.namespaceContext);
+ childReader.init();
+ } else {
+ // all special possiblilities has been tried! Let's treat
+ // the thing as a bean and try generating events from it
+ throw new UnsupportedOperationException("Not supported");
+ // childReader = new
+ // WrappingXMLStreamReader(BeanUtil.getPullParser(propertyValue,
+ // propertyQName));
+ // we cannot register the namespace context here
+ }
+
+ // set the state here
+ state = DELEGATED_STATE;
+ // we are done with the delegation
+ // increment the property index
+ currentPropertyIndex++;
+ return childReader.getEventType();
+ }
+
+ /**
+ * @param prefix
+ * @param uri
+ */
+ private void registerNamespace(String prefix, String uri) {
+ if (!uri.equals(namespaceContext.getNamespaceURI(prefix))) {
+ namespaceContext.registerMapping(prefix, uri);
+ declaredNamespaceMap.put(prefix, uri);
+ }
+ }
+
+ public void require(int i, String string, String string1) throws XMLStreamException {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * add the namespace context
+ */
+
+ public void setParentNamespaceContext(NamespaceContext nsContext) {
+ // register the namespace context passed in to this
+ this.namespaceContext.setParent(nsContext);
+
+ }
+
+ public boolean standaloneSet() {
+ return true;
+ }
+
+ /**
+ * By far this should be the most important method in this class this method changes the state of the parser
+ * according to the change in the
+ */
+ private int updateStatus() throws XMLStreamException {
+ int returnEvent = -1; // invalid state is the default state
+ switch (state) {
+ case START_ELEMENT_STATE:
+ // current element is start element. We should be looking at the
+ // property list and making a pullparser for the property value
+ if (properties == null || properties.length == 0) {
+ // no properties - move to the end element state
+ // straightaway
+ state = END_ELEMENT_STATE;
+ returnEvent = END_ELEMENT;
+ } else {
+ // there are properties. now we should delegate this task to
+ // a
+ // child reader depending on the property type
+ returnEvent = processProperties();
+
+ }
+ break;
+ case END_ELEMENT_STATE:
+ // we've reached the end element already. If the user tries to
+ // push
+ // further ahead then it is an exception
+ throw new XMLStreamException("Trying to go beyond the end of the pullparser");
+
+ case DELEGATED_STATE:
+ if (childReader.isEndOfFragment()) {
+ // we've reached the end!
+ if (currentPropertyIndex > (properties.length - 1)) {
+ state = END_ELEMENT_STATE;
+ returnEvent = END_ELEMENT;
+ } else {
+ returnEvent = processProperties();
+ }
+ } else {
+ returnEvent = childReader.next();
+ }
+ break;
+
+ case TEXT_STATE:
+ // if there are any more event we should be delegating to
+ // processProperties. if not we just return an end element
+ if (currentPropertyIndex > (properties.length - 1)) {
+ state = END_ELEMENT_STATE;
+ returnEvent = END_ELEMENT;
+ } else {
+ returnEvent = processProperties();
+ }
+ break;
+ }
+ return returnEvent;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/InputSource2Node.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/InputSource2Node.java
new file mode 100644
index 0000000000..e9757fa13c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/InputSource2Node.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.databinding.xml;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.tuscany.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.osoa.sca.annotations.Service;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+
+/**
+ * Push DOM InputSource to Node
+ */
+@Service(Transformer.class)
+public class InputSource2Node extends TransformerExtension<InputSource, Node> implements
+ PullTransformer<InputSource, Node> {
+ 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/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/InputSource2SAX.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/InputSource2SAX.java
new file mode 100644
index 0000000000..be78a07ede
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/InputSource2SAX.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.databinding.xml;
+
+import org.apache.tuscany.spi.databinding.PushTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.osoa.sca.annotations.Service;
+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
+ */
+@Service(Transformer.class)
+public class InputSource2SAX extends TransformerExtension<InputSource, ContentHandler> implements
+ PushTransformer<InputSource, ContentHandler> {
+
+ 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/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/InputStream2Node.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/InputStream2Node.java
new file mode 100644
index 0000000000..e103c82b33
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/InputStream2Node.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.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.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.osoa.sca.annotations.Service;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+
+/**
+ * Push DOM InputSource to Node
+ */
+@Service(Transformer.class)
+public class InputStream2Node extends TransformerExtension<InputStream, Node> implements
+ PullTransformer<InputStream, Node> {
+ 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/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/InputStream2SAX.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/InputStream2SAX.java
new file mode 100644
index 0000000000..d74863ea95
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/InputStream2SAX.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.databinding.xml;
+
+import java.io.InputStream;
+
+import org.apache.tuscany.spi.databinding.PushTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.osoa.sca.annotations.Service;
+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
+ */
+@Service(Transformer.class)
+public class InputStream2SAX extends TransformerExtension<InputStream, ContentHandler> implements
+ PushTransformer<InputStream, ContentHandler> {
+ 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/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Node2OutputStream.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Node2OutputStream.java
new file mode 100644
index 0000000000..34fbdf8c6f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Node2OutputStream.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.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.spi.databinding.PushTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.osoa.sca.annotations.Service;
+import org.w3c.dom.Node;
+
+/**
+ * Push DOM Node to OutputStream
+ */
+@Service(Transformer.class)
+public class Node2OutputStream extends TransformerExtension<Node, OutputStream> implements
+ PushTransformer<Node, OutputStream> {
+ 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/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Node2String.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Node2String.java
new file mode 100755
index 0000000000..92378e96a3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Node2String.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.core.databinding.xml;
+
+import java.io.StringWriter;
+
+import org.apache.tuscany.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.osoa.sca.annotations.Service;
+import org.w3c.dom.Node;
+
+/**
+ * Transform DOM Node to XML String
+ */
+@Service(org.apache.tuscany.spi.databinding.Transformer.class)
+public class Node2String extends TransformerExtension<Node, String> implements PullTransformer<Node, String> {
+ 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/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Node2Writer.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Node2Writer.java
new file mode 100644
index 0000000000..96328fdd2f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Node2Writer.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.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.spi.databinding.PushTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.osoa.sca.annotations.Service;
+import org.w3c.dom.Node;
+
+/**
+ * Push DOM Node to Writer
+ */
+@Service(Transformer.class)
+public class Node2Writer extends TransformerExtension<Node, Writer> implements PushTransformer<Node, Writer> {
+ 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/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Node2XMLStreamReader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Node2XMLStreamReader.java
new file mode 100644
index 0000000000..bff9051e01
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Node2XMLStreamReader.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.core.databinding.xml;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.core.databinding.xml.StAXHelper.XMLDocumentStreamReader;
+import org.apache.tuscany.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.osoa.sca.annotations.Service;
+import org.w3c.dom.Node;
+
+/**
+ * Transform DOM Node to XML XMLStreamReader
+ */
+@Service(Transformer.class)
+public class Node2XMLStreamReader extends TransformerExtension<Node, XMLStreamReader> implements
+ PullTransformer<Node, XMLStreamReader> {
+
+ 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/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Reader2Node.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Reader2Node.java
new file mode 100644
index 0000000000..02de055c35
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Reader2Node.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.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.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.osoa.sca.annotations.Service;
+import org.w3c.dom.Node;
+
+/**
+ * Push DOM Reader to Node
+ */
+@Service(Transformer.class)
+public class Reader2Node extends TransformerExtension<Reader, Node> implements PullTransformer<Reader, Node> {
+ 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/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Reader2SAX.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Reader2SAX.java
new file mode 100644
index 0000000000..0a4504b3de
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Reader2SAX.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.databinding.xml;
+
+import java.io.Reader;
+
+import org.apache.tuscany.spi.databinding.PushTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.osoa.sca.annotations.Service;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+
+/**
+ * Transform XML string to SAX
+ */
+@Service(Transformer.class)
+public class Reader2SAX extends TransformerExtension<Reader, ContentHandler> implements
+ PushTransformer<Reader, ContentHandler> {
+ 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/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/SAX2DOM.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/SAX2DOM.java
new file mode 100644
index 0000000000..8f8f0f952e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/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.core.databinding.xml;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Stack;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.tuscany.spi.databinding.extension.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<Node> nodeStk = new Stack<Node>();
+
+ private List<String> 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<String>(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/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/SAX2DOMPipe.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/SAX2DOMPipe.java
new file mode 100644
index 0000000000..79118b4a2c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/SAX2DOMPipe.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.core.databinding.xml;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.tuscany.spi.databinding.DataPipe;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.osoa.sca.annotations.Service;
+import org.w3c.dom.Node;
+import org.xml.sax.ContentHandler;
+
+@Service(Transformer.class)
+public class SAX2DOMPipe extends TransformerExtension<ContentHandler, Node> implements
+ DataPipe<ContentHandler, Node> {
+ 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/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Source2ResultTransformer.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Source2ResultTransformer.java
new file mode 100755
index 0000000000..7db14efb39
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Source2ResultTransformer.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.core.databinding.xml;
+
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerFactory;
+
+import org.apache.tuscany.spi.databinding.PushTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * Transform TrAX Source to Result
+ */
+@Service(org.apache.tuscany.spi.databinding.Transformer.class)
+public class Source2ResultTransformer extends TransformerExtension<Source, Result> implements
+ PushTransformer<Source, Result> {
+ 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/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/StAX2SAXAdapter.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/StAX2SAXAdapter.java
new file mode 100644
index 0000000000..63fa53edb4
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/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.core.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:
+ * <ul>
+ * <li>ignorableWhitespace</li>
+ * <li>skippedEntity</li>
+ * <ul>
+ * Also the following StAX events are not mapped:
+ * <ul>
+ * <li>CDATA</li>
+ * <li>COMMENT</li>
+ * <li>DTD</li>
+ * <li>ENTITY_DECLARATION</li>
+ * <li>ENTITY_REFERENCE</li>
+ * <li>NOTATION_DECLARATION</li>
+ * <li>SPACE</li>
+ * </ul>
+ * StAX ATTRIBUTE events are ignored but the equivalent attributes (derived from
+ * the START_ELEMENT event) are supplied in the SAX startElement event's
+ * Attributes parameter. If the adaptor is configured to pass namespace prefixes
+ * then namespace information will also be included in the Attributes; StAX
+ * NAMESPACE events are ignored. <p/> Another issue is namespace processing. If
+ * the reader is positioned at a sub-node, we cannot capture all the in-scope
+ * namespace bindings. Therefore we cannot re-create a proper SAX event stream
+ * from a StAX parser. <p/> For example <p/> &lt;a:root xmlns:a="foo"
+ * xmlns:b="bar"&gt;&lt;b:sub&gt;a:foo&lt;/b:sub&gt;&lt;/a:root&gt; <p/> And if
+ * you are handed a parser at &lt;b:sub&gt;, then your SAX events should look
+ * like: <p/> &lt;b:sub xmlns:a="foo" xmlns:b="bar"&gt;a:foo&lt;/b:sub&gt; <p/>
+ * not: <p/> &lt;b:sub&gt;a:foo&lt;/b:sub&gt; <p/> <p/> Proposal: we change the
+ * receiver of SAX events (SDOXMLResourceImpl) so that it uses NamespaceContext
+ * to resolve prefix (as opposed to record start/endPrefixMappings and use it
+ * for resolution.)
+ *
+ * @version $Rev$ $Date$
+ */
+public class StAX2SAXAdapter {
+ private final boolean namespacePrefixes;
+
+ /**
+ * Construct a new StAX to SAX adapter that will convert a StAX event stream
+ * into a SAX event stream.
+ *
+ * @param namespacePrefixes whether xmlns attributes should be included in
+ * startElement events;
+ */
+ public StAX2SAXAdapter(boolean namespacePrefixes) {
+ this.namespacePrefixes = namespacePrefixes;
+ }
+
+ /**
+ * Pull events from the StAX stream and dispatch to the SAX ContentHandler.
+ * The StAX stream would typically be located on a START_DOCUMENT or
+ * START_ELEMENT event and when this method returns it will be located on
+ * the associated END_DOCUMENT or END_ELEMENT event. Behaviour with other
+ * start events is undefined.
+ *
+ * @param reader StAX event source to read
+ * @param handler SAX ContentHandler for processing events
+ * @throws XMLStreamException if there was a problem reading the stream
+ * @throws SAXException passed through from the ContentHandler
+ */
+ public void parse(XMLStreamReader reader, ContentHandler handler) throws XMLStreamException, SAXException {
+ handler.setDocumentLocator(new LocatorAdaptor(reader.getLocation()));
+
+ // remembers the nest level of elements to know when we are done
+ int level = 0;
+ int event = reader.getEventType();
+ while (true) {
+ switch (event) {
+ case XMLStreamConstants.START_DOCUMENT:
+ level++;
+ handler.startDocument();
+ break;
+ case XMLStreamConstants.START_ELEMENT:
+ level++;
+ handleStartElement(reader, handler);
+ break;
+ case XMLStreamConstants.PROCESSING_INSTRUCTION:
+ handler.processingInstruction(reader.getPITarget(), reader.getPIData());
+ break;
+ case XMLStreamConstants.CHARACTERS:
+ handler.characters(reader.getTextCharacters(), reader.getTextStart(), reader
+ .getTextLength());
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ handleEndElement(reader, handler);
+ level--;
+ if (level == 0) {
+ return;
+ }
+ break;
+ case XMLStreamConstants.END_DOCUMENT:
+ handler.endDocument();
+ return;
+ /*
+ * uncomment to handle all events rather than just mapped
+ * ones // StAX events that are not mapped to SAX case
+ * XMLStreamConstants.COMMENT: case
+ * XMLStreamConstants.SPACE: case
+ * XMLStreamConstants.ENTITY_REFERENCE: case
+ * XMLStreamConstants.DTD: case XMLStreamConstants.CDATA:
+ * case XMLStreamConstants.NOTATION_DECLARATION: case
+ * XMLStreamConstants.ENTITY_DECLARATION: break; // StAX
+ * events handled in START_ELEMENT case
+ * XMLStreamConstants.ATTRIBUTE: case
+ * XMLStreamConstants.NAMESPACE: break; default: throw new
+ * AssertionError("Unknown StAX event: " + event);
+ */
+ }
+ event = reader.next();
+ }
+ }
+
+ private void handleStartElement(XMLStreamReader reader, ContentHandler handler) throws SAXException {
+ // send startPrefixMapping events immediately before startElement event
+ int nsCount = reader.getNamespaceCount();
+ for (int i = 0; i < nsCount; i++) {
+ String prefix = reader.getNamespacePrefix(i);
+ if (prefix == null) { // true for default namespace
+ prefix = "";
+ }
+ handler.startPrefixMapping(prefix, reader.getNamespaceURI(i));
+ }
+
+ // fire startElement
+ QName qname = reader.getName();
+ String prefix = qname.getPrefix();
+ String rawname;
+ if (prefix == null || prefix.length() == 0) {
+ rawname = qname.getLocalPart();
+ } else {
+ rawname = prefix + ':' + qname.getLocalPart();
+ }
+ Attributes attrs = getAttributes(reader);
+ handler.startElement(qname.getNamespaceURI(), qname.getLocalPart(), rawname, attrs);
+ }
+
+ private static void handleEndElement(XMLStreamReader reader, ContentHandler handler) throws SAXException {
+ // fire endElement
+ QName qname = reader.getName();
+ handler.endElement(qname.getNamespaceURI(), qname.getLocalPart(), qname.toString());
+
+ // send endPrefixMapping events immediately after endElement event
+ // we send them in the opposite order to that returned but this is not
+ // actually required by SAX
+ int nsCount = reader.getNamespaceCount();
+ for (int i = nsCount - 1; i >= 0; i--) {
+ String prefix = reader.getNamespacePrefix(i);
+ if (prefix == null) { // true for default namespace
+ prefix = "";
+ }
+ handler.endPrefixMapping(prefix);
+ }
+ }
+
+ /**
+ * Get the attributes associated with the current START_ELEMENT event.
+ *
+ * @return the StAX attributes converted to org.xml.sax.Attributes
+ */
+ private Attributes getAttributes(XMLStreamReader reader) {
+ assert reader.getEventType() == XMLStreamConstants.START_ELEMENT;
+
+ AttributesImpl attrs = new AttributesImpl();
+
+ // add namespace declarations if required
+ if (namespacePrefixes) {
+ for (int i = 0; i < reader.getNamespaceCount(); i++) {
+ String prefix = reader.getNamespacePrefix(i);
+ String uri = reader.getNamespaceURI(i);
+ attrs.addAttribute(null, prefix, "xmlns:" + prefix, "CDATA", uri);
+ }
+ }
+
+ // Regular attributes
+ for (int i = 0; i < reader.getAttributeCount(); i++) {
+ String uri = reader.getAttributeNamespace(i);
+ if (uri == null) {
+ uri = "";
+ }
+ String localName = reader.getAttributeLocalName(i);
+ String prefix = reader.getAttributePrefix(i);
+ String qname;
+ if (prefix == null || prefix.length() == 0) {
+ qname = localName;
+ } else {
+ qname = prefix + ':' + localName;
+ }
+ String type = reader.getAttributeType(i);
+ String value = reader.getAttributeValue(i);
+
+ attrs.addAttribute(uri, localName, qname, type, value);
+ }
+
+ return attrs;
+ }
+
+ /**
+ * Adaptor for mapping Locator information.
+ */
+ private static final class LocatorAdaptor implements Locator {
+ private final Location location;
+
+ private LocatorAdaptor(Location location) {
+ this.location = location;
+ }
+
+ public int getColumnNumber() {
+ return location == null ? 0 : location.getColumnNumber();
+ }
+
+ public int getLineNumber() {
+ return location == null ? 0 : location.getLineNumber();
+ }
+
+ public String getPublicId() {
+ return location == null ? "" : location.getPublicId();
+ }
+
+ public String getSystemId() {
+ return location == null ? "" : location.getSystemId();
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/StAXHelper.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/StAXHelper.java
new file mode 100755
index 0000000000..5426384961
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/StAXHelper.java
@@ -0,0 +1,806 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.xml;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.NoSuchElementException;
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Source;
+
+public final class StAXHelper {
+ private static final XMLInputFactory INPUT_FACTORY = XMLInputFactory.newInstance();
+ private static final XMLOutputFactory OUTPUT_FACTORY = XMLOutputFactory.newInstance();
+
+ private StAXHelper() {
+ }
+
+ /**
+ * This class is derived from Apache Axis2 class org.apache.axis2.util.StreamWrapper</a>. It's used wrap a
+ * XMLStreamReader to create a XMLStreamReader representing a document and it will produce START_DOCUMENT,
+ * END_DOCUMENT events.
+ */
+ public static class XMLDocumentStreamReader implements XMLStreamReader {
+ private static final int STATE_COMPLETE_AT_NEXT = 2; // The wrapper
+ // will produce
+ // END_DOCUMENT
+
+ private static final int STATE_COMPLETED = 3; // Done
+
+ private static final int STATE_INIT = 0; // The wrapper will produce
+ // START_DOCUMENT
+
+ private static final int STATE_SWITCHED = 1; // The real reader will
+ // produce events
+
+ private XMLStreamReader realReader;
+
+ private int state = STATE_INIT;
+
+ public XMLDocumentStreamReader(XMLStreamReader realReader) {
+ if (realReader == null) {
+ throw new UnsupportedOperationException("Reader cannot be null");
+ }
+
+ this.realReader = realReader;
+
+ // If the real reader is positioned at START_DOCUMENT, always use
+ // the real reader
+ if (realReader.getEventType() == START_DOCUMENT) {
+ state = STATE_SWITCHED;
+ }
+ }
+
+ public void close() throws XMLStreamException {
+ realReader.close();
+ }
+
+ public int getAttributeCount() {
+ if (isDelegating()) {
+ return realReader.getAttributeCount();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeLocalName(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributeLocalName(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public QName getAttributeName(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributeName(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeNamespace(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributeNamespace(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributePrefix(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributePrefix(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeType(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributeType(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeValue(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributeValue(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeValue(String s, String s1) {
+ if (isDelegating()) {
+ return realReader.getAttributeValue(s, s1);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getCharacterEncodingScheme() {
+ return realReader.getCharacterEncodingScheme();
+ }
+
+ public String getElementText() throws XMLStreamException {
+ if (isDelegating()) {
+ return realReader.getElementText();
+ } else {
+ throw new XMLStreamException();
+ }
+ }
+
+ public String getEncoding() {
+ return realReader.getEncoding();
+ }
+
+ public int getEventType() {
+ int event = -1;
+ switch (state) {
+ case STATE_SWITCHED:
+ case STATE_COMPLETE_AT_NEXT:
+ event = realReader.getEventType();
+ break;
+ case STATE_INIT:
+ event = START_DOCUMENT;
+ break;
+ case STATE_COMPLETED:
+ event = END_DOCUMENT;
+ break;
+ }
+ return event;
+ }
+
+ public String getLocalName() {
+ if (isDelegating()) {
+ return realReader.getLocalName();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public Location getLocation() {
+ if (isDelegating()) {
+ return realReader.getLocation();
+ } else {
+ return null;
+ }
+ }
+
+ public QName getName() {
+ if (isDelegating()) {
+ return realReader.getName();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public NamespaceContext getNamespaceContext() {
+ return realReader.getNamespaceContext();
+ }
+
+ public int getNamespaceCount() {
+ if (isDelegating()) {
+ return realReader.getNamespaceCount();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getNamespacePrefix(int i) {
+ if (isDelegating()) {
+ return realReader.getNamespacePrefix(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getNamespaceURI() {
+ if (isDelegating()) {
+ return realReader.getNamespaceURI();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getNamespaceURI(int i) {
+ if (isDelegating()) {
+ return realReader.getNamespaceURI(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getNamespaceURI(String s) {
+ if (isDelegating()) {
+ return realReader.getNamespaceURI(s);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getPIData() {
+ if (isDelegating()) {
+ return realReader.getPIData();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getPITarget() {
+ if (isDelegating()) {
+ return realReader.getPITarget();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getPrefix() {
+ if (isDelegating()) {
+ return realReader.getPrefix();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public Object getProperty(String s) throws IllegalArgumentException {
+ if (isDelegating()) {
+ return realReader.getProperty(s);
+ } else {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ public String getText() {
+ if (isDelegating()) {
+ return realReader.getText();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public char[] getTextCharacters() {
+ if (isDelegating()) {
+ return realReader.getTextCharacters();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public int getTextCharacters(int i, char[] chars, int i1, int i2) throws XMLStreamException {
+ if (isDelegating()) {
+ return realReader.getTextCharacters(i, chars, i1, i2);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public int getTextLength() {
+ if (isDelegating()) {
+ return realReader.getTextLength();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public int getTextStart() {
+ if (isDelegating()) {
+ return realReader.getTextStart();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getVersion() {
+ if (isDelegating()) {
+ return realReader.getVersion();
+ } else {
+ return null;
+ }
+ }
+
+ public boolean hasName() {
+ if (isDelegating()) {
+ return realReader.hasName();
+ } else {
+ return false;
+ }
+ }
+
+ public boolean hasNext() throws XMLStreamException {
+ if (state == STATE_COMPLETE_AT_NEXT) {
+ return true;
+ } else if (state == STATE_COMPLETED) {
+ return false;
+ } else if (state == STATE_SWITCHED) {
+ return realReader.hasNext();
+ } else {
+ return true;
+ }
+ }
+
+ public boolean hasText() {
+ if (isDelegating()) {
+ return realReader.hasText();
+ } else {
+ return false;
+ }
+ }
+
+ public boolean isAttributeSpecified(int i) {
+ if (isDelegating()) {
+ return realReader.isAttributeSpecified(i);
+ } else {
+ return false;
+ }
+ }
+
+ public boolean isCharacters() {
+ if (isDelegating()) {
+ return realReader.isCharacters();
+ } else {
+ return false;
+ }
+ }
+
+ private boolean isDelegating() {
+ return state == STATE_SWITCHED || state == STATE_COMPLETE_AT_NEXT;
+ }
+
+ public boolean isEndElement() {
+ if (isDelegating()) {
+ return realReader.isEndElement();
+ } else {
+ return false;
+ }
+ }
+
+ public boolean isStandalone() {
+ if (isDelegating()) {
+ return realReader.isStandalone();
+ } else {
+ return false;
+ }
+ }
+
+ public boolean isStartElement() {
+ if (isDelegating()) {
+ return realReader.isStartElement();
+ } else {
+ return false;
+ }
+ }
+
+ public boolean isWhiteSpace() {
+ if (isDelegating()) {
+ return realReader.isWhiteSpace();
+ } else {
+ return false;
+ }
+ }
+
+ public int next() throws XMLStreamException {
+ int returnEvent;
+
+ switch (state) {
+ case STATE_SWITCHED:
+ returnEvent = realReader.next();
+ if (returnEvent == END_DOCUMENT) {
+ state = STATE_COMPLETED;
+ } else if (!realReader.hasNext()) {
+ state = STATE_COMPLETE_AT_NEXT;
+ }
+ break;
+ case STATE_INIT:
+ state = STATE_SWITCHED;
+ returnEvent = realReader.getEventType();
+ break;
+ case STATE_COMPLETE_AT_NEXT:
+ state = STATE_COMPLETED;
+ returnEvent = END_DOCUMENT;
+ break;
+ case STATE_COMPLETED:
+ // oops - no way we can go beyond this
+ throw new NoSuchElementException("End of stream has reached.");
+ default:
+ throw new UnsupportedOperationException();
+ }
+
+ return returnEvent;
+ }
+
+ public int nextTag() throws XMLStreamException {
+ if (isDelegating()) {
+ return realReader.nextTag();
+ } else {
+ throw new XMLStreamException();
+ }
+ }
+
+ public void require(int i, String s, String s1) throws XMLStreamException {
+ if (isDelegating()) {
+ realReader.require(i, s, s1);
+ }
+ }
+
+ public boolean standaloneSet() {
+ if (isDelegating()) {
+ return realReader.standaloneSet();
+ } else {
+ return false;
+ }
+ }
+ }
+
+ public static interface XMLFragmentStreamReader extends XMLStreamReader {
+
+ // this will help to handle Text within the current element.
+ // user should pass the element text to the property list as this
+ // ELEMENT_TEXT as the key. This key deliberately has a space in it
+ // so that it is not a valid XML name
+ String ELEMENT_TEXT = "Element Text";
+
+ /**
+ * Initiate the parser - this will do whatever the needed tasks to initiate the parser and must be called before
+ * attempting any specific parsing using this parser
+ */
+ void init();
+
+ /**
+ * Extra method to query the state of the pullparser
+ */
+ boolean isEndOfFragment();
+
+ /**
+ * add the parent namespace context to this parser
+ */
+ void setParentNamespaceContext(NamespaceContext nsContext);
+ }
+
+ /**
+ * The XMLStreamSerializer pulls events from the XMLStreamReader and dumps into the XMLStreamWriter
+ */
+ public static class XMLStreamSerializer implements XMLStreamConstants {
+ public static final String NAMESPACE_PREFIX = "ns";
+ private static int namespaceSuffix;
+
+ /*
+ * The behavior of the serializer is such that it returns when it
+ * encounters the starting element for the second time. The depth
+ * variable tracks the depth of the serilizer and tells it when to
+ * return. Note that it is assumed that this serialization starts on an
+ * Element.
+ */
+
+ /**
+ * Field depth
+ */
+ private int depth;
+
+ /**
+ * Generates a unique namespace prefix that is not in the scope of the NamespaceContext
+ *
+ * @param nsCtxt
+ * @return string
+ */
+ private String generateUniquePrefix(NamespaceContext nsCtxt) {
+ String prefix = NAMESPACE_PREFIX + namespaceSuffix++;
+ // null should be returned if the prefix is not bound!
+ while (nsCtxt.getNamespaceURI(prefix) != null) {
+ prefix = NAMESPACE_PREFIX + namespaceSuffix++;
+ }
+
+ return prefix;
+ }
+
+ /**
+ * Method serialize.
+ *
+ * @param node
+ * @param writer
+ * @throws XMLStreamException
+ */
+ public void serialize(XMLStreamReader node, XMLStreamWriter writer) throws XMLStreamException {
+ serializeNode(node, writer);
+ }
+
+ /**
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeAttributes(XMLStreamReader reader, XMLStreamWriter writer)
+ throws XMLStreamException {
+ int count = reader.getAttributeCount();
+ String prefix;
+ String namespaceName;
+ String writerPrefix;
+ for (int i = 0; i < count; i++) {
+ prefix = reader.getAttributePrefix(i);
+ namespaceName = reader.getAttributeNamespace(i);
+ /*
+ * Due to parser implementations returning null as the namespace
+ * URI (for the empty namespace) we need to make sure that we
+ * deal with a namespace name that is not null. The best way to
+ * work around this issue is to set the namespace uri to "" if
+ * it is null
+ */
+ if (namespaceName == null) {
+ namespaceName = "";
+ }
+
+ writerPrefix = writer.getNamespaceContext().getPrefix(namespaceName);
+
+ if (!"".equals(namespaceName)) {
+ // prefix has already being declared but this particular
+ // attrib has a
+ // no prefix attached. So use the prefix provided by the
+ // writer
+ if (writerPrefix != null && (prefix == null || prefix.equals(""))) {
+ writer.writeAttribute(writerPrefix,
+ namespaceName,
+ reader.getAttributeLocalName(i),
+ reader.getAttributeValue(i));
+
+ // writer prefix is available but different from the
+ // current
+ // prefix of the attrib. We should be decalring the new
+ // prefix
+ // as a namespace declaration
+ } else if (prefix != null && !"".equals(prefix) && !prefix.equals(writerPrefix)) {
+ writer.writeNamespace(prefix, namespaceName);
+ writer.writeAttribute(prefix, namespaceName, reader.getAttributeLocalName(i), reader
+ .getAttributeValue(i));
+
+ // prefix is null (or empty), but the namespace name is
+ // valid! it has not
+ // being written previously also. So we need to generate
+ // a prefix
+ // here
+ } else if (prefix == null || prefix.equals("")) {
+ prefix = generateUniquePrefix(writer.getNamespaceContext());
+ writer.writeNamespace(prefix, namespaceName);
+ writer.writeAttribute(prefix, namespaceName, reader.getAttributeLocalName(i), reader
+ .getAttributeValue(i));
+ } else {
+ writer.writeAttribute(prefix, namespaceName, reader.getAttributeLocalName(i), reader
+ .getAttributeValue(i));
+ }
+ } else {
+ // empty namespace is equal to no namespace!
+ writer.writeAttribute(reader.getAttributeLocalName(i), reader.getAttributeValue(i));
+ }
+
+ }
+ }
+
+ /**
+ * Method serializeCData.
+ *
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeCData(XMLStreamReader reader, XMLStreamWriter writer)
+ throws XMLStreamException {
+ writer.writeCData(reader.getText());
+ }
+
+ /**
+ * Method serializeComment.
+ *
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeComment(XMLStreamReader reader, XMLStreamWriter writer)
+ throws XMLStreamException {
+ writer.writeComment(reader.getText());
+ }
+
+ /**
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeElement(XMLStreamReader reader, XMLStreamWriter writer)
+ throws XMLStreamException {
+ String prefix = reader.getPrefix();
+ String nameSpaceName = reader.getNamespaceURI();
+ if (nameSpaceName != null) {
+ String writerPrefix = writer.getPrefix(nameSpaceName);
+ if (writerPrefix != null) {
+ writer.writeStartElement(nameSpaceName, reader.getLocalName());
+ } else {
+ if (prefix != null) {
+ writer.writeStartElement(prefix, reader.getLocalName(), nameSpaceName);
+ writer.writeNamespace(prefix, nameSpaceName);
+ writer.setPrefix(prefix, nameSpaceName);
+ } else {
+ writer.writeStartElement(nameSpaceName, reader.getLocalName());
+ writer.writeDefaultNamespace(nameSpaceName);
+ writer.setDefaultNamespace(nameSpaceName);
+ }
+ }
+ } else {
+ writer.writeStartElement(reader.getLocalName());
+ }
+
+ // add the namespaces
+ int count = reader.getNamespaceCount();
+ String namespacePrefix;
+ for (int i = 0; i < count; i++) {
+ namespacePrefix = reader.getNamespacePrefix(i);
+ if (namespacePrefix != null && namespacePrefix.length() == 0) {
+ continue;
+ }
+
+ serializeNamespace(namespacePrefix, reader.getNamespaceURI(i), writer);
+ }
+
+ // add attributes
+ serializeAttributes(reader, writer);
+
+ }
+
+ /**
+ * Method serializeEndElement.
+ *
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeEndElement(XMLStreamWriter writer) throws XMLStreamException {
+ writer.writeEndElement();
+ }
+
+ /**
+ * Method serializeNamespace.
+ *
+ * @param prefix
+ * @param uri
+ * @param writer
+ * @throws XMLStreamException
+ */
+ private void serializeNamespace(String prefix, String uri, XMLStreamWriter writer)
+ throws XMLStreamException {
+ String prefix1 = writer.getPrefix(uri);
+ if (prefix1 == null) {
+ writer.writeNamespace(prefix, uri);
+ writer.setPrefix(prefix, uri);
+ }
+ }
+
+ /**
+ * Method serializeNode.
+ *
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeNode(XMLStreamReader reader, XMLStreamWriter writer)
+ throws XMLStreamException {
+ // TODO We get the StAXWriter at this point and uses it hereafter
+ // assuming that this is the only entry point
+ // to this class.
+ // If there can be other classes calling methodes of this we might
+ // need to change methode signatures to
+ // OMOutputer
+ while (reader.hasNext()) {
+ int event = reader.next();
+ if (event == START_ELEMENT) {
+ serializeElement(reader, writer);
+ depth++;
+ } else if (event == ATTRIBUTE) {
+ serializeAttributes(reader, writer);
+ } else if (event == CHARACTERS) {
+ serializeText(reader, writer);
+ } else if (event == COMMENT) {
+ serializeComment(reader, writer);
+ } else if (event == CDATA) {
+ serializeCData(reader, writer);
+ } else if (event == END_ELEMENT) {
+ serializeEndElement(writer);
+ depth--;
+ } else if (event == START_DOCUMENT) {
+ depth++; // if a start document is found then increment
+ // the depth
+ } else if (event == END_DOCUMENT) {
+ if (depth != 0) {
+ depth--; // for the end document - reduce the depth
+ }
+ try {
+ serializeEndElement(writer);
+ } catch (Exception e) {
+ // TODO: log exceptions
+ }
+ }
+ if (depth == 0) {
+ break;
+ }
+ }
+ }
+
+ /**
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeText(XMLStreamReader reader, XMLStreamWriter writer)
+ throws XMLStreamException {
+ writer.writeCharacters(reader.getText());
+ }
+ }
+
+ public static XMLStreamReader createXMLStreamReader(InputStream inputStream) throws XMLStreamException {
+ return INPUT_FACTORY.createXMLStreamReader(inputStream);
+ }
+
+ public static XMLStreamReader createXMLStreamReader(Reader reader) throws XMLStreamException {
+ return INPUT_FACTORY.createXMLStreamReader(reader);
+ }
+
+ public static XMLStreamReader createXMLStreamReader(Source source) throws XMLStreamException {
+ return INPUT_FACTORY.createXMLStreamReader(source);
+ }
+
+ public static XMLStreamReader createXMLStreamReader(String string) throws XMLStreamException {
+ StringReader reader = new StringReader(string);
+ return createXMLStreamReader(reader);
+ }
+
+ public static String save(XMLStreamReader reader) throws XMLStreamException {
+ StringWriter writer = new StringWriter();
+ save(reader, writer);
+ return writer.toString();
+ }
+
+ public static void save(XMLStreamReader reader, OutputStream outputStream) throws XMLStreamException {
+ XMLStreamSerializer serializer = new XMLStreamSerializer();
+ XMLStreamWriter streamWriter = OUTPUT_FACTORY.createXMLStreamWriter(outputStream);
+ serializer.serialize(reader, streamWriter);
+ streamWriter.flush();
+ }
+
+ public static void save(XMLStreamReader reader, Writer writer) throws XMLStreamException {
+ XMLStreamSerializer serializer = new XMLStreamSerializer();
+ XMLStreamWriter streamWriter = OUTPUT_FACTORY.createXMLStreamWriter(writer);
+ serializer.serialize(reader, streamWriter);
+ streamWriter.flush();
+ }
+
+ public static void save(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
+ XMLStreamSerializer serializer = new XMLStreamSerializer();
+ serializer.serialize(reader, writer);
+ writer.flush();
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/StreamDataPipe.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/StreamDataPipe.java
new file mode 100755
index 0000000000..d0b6ce07f2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/StreamDataPipe.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.core.databinding.xml;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.tuscany.spi.databinding.DataPipe;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.osoa.sca.annotations.Service;
+
+@Service(Transformer.class)
+public class StreamDataPipe extends TransformerExtension<OutputStream, InputStream> implements
+ DataPipe<OutputStream, InputStream> {
+
+ private ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+
+ public InputStream getResult() {
+ return new ByteArrayInputStream(outputStream.toByteArray());
+ }
+
+ public Class getTargetType() {
+ return InputStream.class;
+ }
+
+ public int getWeight() {
+ return 50;
+ }
+
+ public OutputStream getSink() {
+ return outputStream;
+ }
+
+ public Class getSourceType() {
+ return OutputStream.class;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/String2Node.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/String2Node.java
new file mode 100755
index 0000000000..3f878a07b9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/String2Node.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.core.databinding.xml;
+
+import java.io.StringReader;
+
+import javax.xml.parsers.DocumentBuilder;
+
+import org.apache.tuscany.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.DOMHelper;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.osoa.sca.annotations.Service;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+
+@Service(Transformer.class)
+public class String2Node extends TransformerExtension<String, Node> implements PullTransformer<String, Node> {
+
+ public Node transform(String source, TransformationContext context) {
+ try {
+ DocumentBuilder builder = DOMHelper.newDocumentBuilder();
+ InputSource inputSource = new InputSource(new StringReader(source));
+ return builder.parse(inputSource);
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ public Class getSourceType() {
+ return String.class;
+ }
+
+ public Class getTargetType() {
+ return Node.class;
+ }
+
+ public int getWeight() {
+ return 50;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/String2SAX.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/String2SAX.java
new file mode 100644
index 0000000000..50ea110b17
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/String2SAX.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.core.databinding.xml;
+
+import java.io.StringReader;
+
+import org.apache.tuscany.spi.databinding.PushTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.osoa.sca.annotations.Service;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+
+/**
+ * Transform XML string to SAX
+ */
+@Service(Transformer.class)
+public class String2SAX extends TransformerExtension<String, ContentHandler> implements
+ PushTransformer<String, ContentHandler> {
+
+ public void transform(String source, ContentHandler target, TransformationContext context) {
+ try {
+ new InputSource2SAX().transform(new InputSource(new StringReader(source)), target, context);
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ public Class getSourceType() {
+ return String.class;
+ }
+
+ public Class getTargetType() {
+ return ContentHandler.class;
+ }
+
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/String2XMLStreamReader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/String2XMLStreamReader.java
new file mode 100755
index 0000000000..9793cc3f7e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/String2XMLStreamReader.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.core.databinding.xml;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.osoa.sca.annotations.Service;
+
+@Service(Transformer.class)
+public class String2XMLStreamReader extends TransformerExtension<String, XMLStreamReader> implements
+ PullTransformer<String, XMLStreamReader> {
+
+ public XMLStreamReader transform(String source, TransformationContext context) {
+ try {
+ return StAXHelper.createXMLStreamReader(source);
+ } catch (XMLStreamException e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ public Class getSourceType() {
+ return String.class;
+ }
+
+ public Class getTargetType() {
+ return XMLStreamReader.class;
+ }
+
+ public int getWeight() {
+ return 50;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Writer2ReaderDataPipe.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Writer2ReaderDataPipe.java
new file mode 100755
index 0000000000..c66d0fd934
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/Writer2ReaderDataPipe.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.core.databinding.xml;
+
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import org.apache.tuscany.spi.databinding.DataPipe;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.osoa.sca.annotations.Service;
+
+@Service(Transformer.class)
+public class Writer2ReaderDataPipe extends TransformerExtension<Writer, Reader> implements DataPipe<Writer, Reader> {
+
+ private StringWriter writer = new StringWriter();
+
+ public Reader getResult() {
+ return new StringReader(writer.toString());
+ }
+
+ public Class getTargetType() {
+ return Reader.class;
+ }
+
+ public int getWeight() {
+ return 50;
+ }
+
+ public Writer getSink() {
+ return writer;
+ }
+
+ public Class getSourceType() {
+ return Writer.class;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/XMLStreamReader2Node.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/XMLStreamReader2Node.java
new file mode 100644
index 0000000000..6ecaa85be4
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/XMLStreamReader2Node.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.core.databinding.xml;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.osoa.sca.annotations.Service;
+import org.w3c.dom.Node;
+
+/**
+ * Transform DOM Node to XML XMLStreamReader
+ */
+@Service(Transformer.class)
+public class XMLStreamReader2Node extends TransformerExtension<XMLStreamReader, Node> implements
+ PullTransformer<XMLStreamReader, Node> {
+ private SAX2DOMPipe pipe = new SAX2DOMPipe();
+
+ private XMLStreamReader2SAX stax2sax = new XMLStreamReader2SAX();
+
+ public Node transform(XMLStreamReader source, TransformationContext context) {
+ try {
+ stax2sax.transform(source, pipe.getSink(), context);
+ return pipe.getResult();
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ public Class getSourceType() {
+ return XMLStreamReader.class;
+ }
+
+ public Class getTargetType() {
+ return Node.class;
+ }
+
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/XMLStreamReader2SAX.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/XMLStreamReader2SAX.java
new file mode 100644
index 0000000000..0c6f0b8df7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/XMLStreamReader2SAX.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.core.databinding.xml;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.databinding.PushTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.osoa.sca.annotations.Service;
+import org.xml.sax.ContentHandler;
+
+/**
+ * XMLStreamReader to SAX events
+ */
+@Service(Transformer.class)
+public class XMLStreamReader2SAX extends TransformerExtension<XMLStreamReader, ContentHandler> implements
+ PushTransformer<XMLStreamReader, ContentHandler> {
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.PushTransformer#getSourceType()
+ */
+ public Class getTargetType() {
+ return ContentHandler.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.PushTransformer#getSourceType()
+ */
+ public Class getSourceType() {
+ return XMLStreamReader.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.PushTransformer#getWeight()
+ */
+ public int getWeight() {
+ return 20;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.PushTransformer#transform(java.lang.Object,
+ * java.lang.Object,
+ * org.apache.tuscany.spi.databinding.TransformationContext)
+ */
+ public void transform(XMLStreamReader source, ContentHandler sink, TransformationContext context) {
+ StAX2SAXAdapter adapter = new StAX2SAXAdapter(false);
+ try {
+ adapter.parse(source, sink);
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/XMLStreamReader2String.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/XMLStreamReader2String.java
new file mode 100755
index 0000000000..85ac7b5af6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/XMLStreamReader2String.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.core.databinding.xml;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.osoa.sca.annotations.Service;
+
+@Service(Transformer.class)
+public class XMLStreamReader2String extends TransformerExtension<XMLStreamReader, String> implements
+ PullTransformer<XMLStreamReader, String> {
+
+ public String transform(XMLStreamReader source, TransformationContext context) {
+ try {
+ return StAXHelper.save(source);
+ } catch (XMLStreamException e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ public Class getSourceType() {
+ return XMLStreamReader.class;
+ }
+
+ public Class getTargetType() {
+ return String.class;
+ }
+
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/XMLStringDataBinding.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/XMLStringDataBinding.java
new file mode 100644
index 0000000000..39e9362524
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/XMLStringDataBinding.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.core.databinding.xml;
+
+import org.apache.tuscany.spi.databinding.extension.DataBindingExtension;
+
+/**
+ * A DataBinding for the XML string
+ */
+public class XMLStringDataBinding extends DataBindingExtension {
+ public static final String NAME = String.class.getName();
+
+ public XMLStringDataBinding() {
+ super(NAME, String.class);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/deployer/AbstractDeploymentContext.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/deployer/AbstractDeploymentContext.java
new file mode 100644
index 0000000000..8d24047781
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/deployer/AbstractDeploymentContext.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.core.deployer;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+
+/**
+ * Base class for DeploymentContext implementations.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractDeploymentContext implements DeploymentContext {
+ private final URI componentId;
+ private boolean autowire;
+ private final ClassLoader classLoader;
+ private final URL scdlLocation;
+ private final Map<URI, Component> components = new HashMap<URI, Component>();
+
+ /**
+ * Constructor defining properties of this context.
+ *
+ * @param classLoader the classloader for loading application resources
+ * @param scdlLocation the location of the SCDL defining this composite
+ * @param componentId the id of the component being deployed
+ * @param autowire if autowire is enabled
+ */
+ protected AbstractDeploymentContext(ClassLoader classLoader, URL scdlLocation, URI componentId, boolean autowire) {
+ this.classLoader = classLoader;
+ this.scdlLocation = scdlLocation;
+ this.componentId = componentId;
+ this.autowire = autowire;
+ }
+
+ public ClassLoader getClassLoader() {
+ return classLoader;
+ }
+
+ public URL getScdlLocation() {
+ return scdlLocation;
+ }
+
+ public URI getComponentId() {
+ return componentId;
+ }
+
+ public boolean isAutowire() {
+ return autowire;
+ }
+
+ public void setAutowire(boolean autowire) {
+ this.autowire = autowire;
+ }
+
+ @Deprecated
+ public Map<URI, Component> getComponents() {
+ return components;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/deployer/ChildDeploymentContext.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/deployer/ChildDeploymentContext.java
new file mode 100644
index 0000000000..c2f8ae07fc
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/deployer/ChildDeploymentContext.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.core.deployer;
+
+import java.net.URI;
+import java.net.URL;
+import javax.xml.stream.XMLInputFactory;
+
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+
+/**
+ * An holder that can be used during the load process to store information that is not part of the logical assembly
+ * model. This should be regarded as transient and references to this context should not be stored inside the model.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ChildDeploymentContext extends AbstractDeploymentContext {
+ private final DeploymentContext parent;
+
+ /**
+ * Constructor defining properties of this context.
+ *
+ * @param parent the parent of this context
+ * @param classLoader the classloader for loading application resources
+ * @param scdlLocation the location of the SCDL defining this composite
+ * @param componentId the id of the component being deployed
+ * @param autowire if autowire is enabled
+ */
+ public ChildDeploymentContext(DeploymentContext parent,
+ ClassLoader classLoader,
+ URL scdlLocation,
+ URI componentId,
+ boolean autowire) {
+ super(classLoader, scdlLocation, componentId, autowire);
+ assert parent != null;
+ this.parent = parent;
+ }
+
+ public DeploymentContext getParent() {
+ return parent;
+ }
+
+ public XMLInputFactory getXmlFactory() {
+ return parent.getXmlFactory();
+ }
+
+ public ScopeContainer getCompositeScope() {
+ return parent.getCompositeScope();
+ }
+
+ public URI getGroupId() {
+ return parent.getGroupId();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/deployer/DeployerImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/deployer/DeployerImpl.java
new file mode 100644
index 0000000000..9a9778a0b7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/deployer/DeployerImpl.java
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.deployer;
+
+import java.net.URI;
+import java.util.Collection;
+import javax.xml.stream.XMLInputFactory;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.api.annotation.Monitor;
+import org.apache.tuscany.core.resolver.AutowireResolver;
+import org.apache.tuscany.spi.builder.Builder;
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.builder.BuilderInstantiationException;
+import org.apache.tuscany.spi.builder.BuilderRegistry;
+import org.apache.tuscany.spi.builder.Connector;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ComponentManager;
+import org.apache.tuscany.spi.component.RegistrationException;
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeContainerMonitor;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.deployer.Deployer;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.Loader;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.resolver.ResolutionException;
+
+/**
+ * Default implementation of Deployer.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DeployerImpl implements Deployer {
+ private XMLInputFactory xmlFactory;
+ private Builder builder;
+ private ScopeContainerMonitor monitor;
+ private Loader loader;
+ private AutowireResolver resolver;
+ private Connector connector;
+ private ComponentManager componentManager;
+ private ScopeRegistry scopeRegistry;
+
+ public DeployerImpl(XMLInputFactory xmlFactory,
+ Loader loader,
+ Builder builder,
+ ComponentManager componentManager,
+ AutowireResolver resolver,
+ Connector connector) {
+ this.xmlFactory = xmlFactory;
+ this.loader = loader;
+ this.builder = builder;
+ this.componentManager = componentManager;
+ this.resolver = resolver;
+ this.connector = connector;
+ }
+
+ public DeployerImpl() {
+ xmlFactory = XMLInputFactory.newInstance("javax.xml.stream.XMLInputFactory", getClass().getClassLoader());
+ }
+
+ @Reference
+ public void setLoader(LoaderRegistry loader) {
+ this.loader = loader;
+ }
+
+ @Reference
+ public void setBuilder(BuilderRegistry builder) {
+ this.builder = builder;
+ }
+
+ @Monitor
+ public void setMonitor(ScopeContainerMonitor monitor) {
+ this.monitor = monitor;
+ }
+
+ @Reference
+ public void setResolver(AutowireResolver resolver) {
+ this.resolver = resolver;
+ }
+
+ @Reference
+ public void setConnector(Connector connector) {
+ this.connector = connector;
+ }
+
+ @Reference
+ public void setComponentManager(ComponentManager componentManager) {
+ this.componentManager = componentManager;
+ }
+
+ @Reference
+ public void setScopeRegistry(ScopeRegistry scopeRegistry) {
+ this.scopeRegistry = scopeRegistry;
+ }
+
+ public <I extends Implementation<?>> Collection<Component> deploy(Component parent,
+ ComponentDefinition<I> componentDefinition)
+ throws LoaderException, BuilderException, ResolutionException {
+ @SuppressWarnings("unchecked")
+ ScopeContainer<URI> scopeContainer = scopeRegistry.getScopeContainer(Scope.COMPOSITE);
+ URI groupId = componentDefinition.getUri();
+ DeploymentContext deploymentContext =
+ new RootDeploymentContext(null, null, groupId, xmlFactory, scopeContainer, false);
+ // load the model
+ load(parent, componentDefinition, deploymentContext);
+ // resolve autowires
+ resolver.resolve(null, componentDefinition);
+ // build runtime artifacts
+ build(parent, componentDefinition, deploymentContext);
+/*
+ // create a listener so the scope container is shutdown when the top-level composite stops
+ RuntimeEventListener listener = new RuntimeEventListener() {
+ public void onEvent(Event event) {
+ scopeContainer.onEvent(event);
+ if (event instanceof ComponentStop) {
+ scopeContainer.stop();
+ }
+ }
+ };
+ component.addListener(listener);
+*/
+
+ Collection<Component> components = deploymentContext.getComponents().values();
+ for (Component toRegister : components) {
+ try {
+ componentManager.register(toRegister);
+ } catch (RegistrationException e) {
+ throw new BuilderInstantiationException("Error registering component", e);
+ }
+ }
+ connector.connect(componentDefinition);
+ return components;
+ }
+
+ /**
+ * Load the componentDefinition type information for the componentDefinition being deployed. For a typical
+ * deployment this will result in the SCDL definition being loaded.
+ *
+ * @param componentDefinition the componentDefinition being deployed
+ * @param deploymentContext the current deployment context
+ */
+ protected <I extends Implementation<?>> void load(Component parent,
+ ComponentDefinition<I> componentDefinition,
+ DeploymentContext deploymentContext) throws LoaderException {
+ loader.loadComponentType(componentDefinition.getImplementation(), deploymentContext);
+ }
+
+ /**
+ * Build the runtime context for a loaded componentDefinition.
+ *
+ * @param parent the context that will be the parent of the new sub-context
+ * @param componentDefinition the componentDefinition being deployed
+ * @param deploymentContext the current deployment context
+ * @return the new runtime context
+ */
+ protected <I extends Implementation<?>> SCAObject build(Component parent,
+ ComponentDefinition<I> componentDefinition,
+ DeploymentContext deploymentContext)
+ throws BuilderException {
+ return builder.build(componentDefinition, deploymentContext);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/deployer/RootDeploymentContext.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/deployer/RootDeploymentContext.java
new file mode 100644
index 0000000000..a523dadbf4
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/deployer/RootDeploymentContext.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.core.deployer;
+
+import java.net.URI;
+import java.net.URL;
+import javax.xml.stream.XMLInputFactory;
+
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+
+/**
+ * A holder that can be used during the load process to store information that is not part of the logical assembly
+ * model. This should be regarded as transient and references to this context should not be stored inside the model.
+ *
+ * @version $Rev$ $Date$
+ */
+public class RootDeploymentContext extends AbstractDeploymentContext {
+ private final XMLInputFactory xmlFactory;
+ private final ScopeContainer scopeContainer;
+
+ /**
+ * Constructor defining properties of this context.
+ *
+ * @param classLoader the classloader for loading application resources
+ * @param scdlLocation the location of the SCDL defining this composite
+ * @param componentId the id of the component being deployed
+ * @param xmlFactory a factory that can be used to obtain an StAX XMLStreamReader
+ * @param scopeContainer the scope context representing this deployment's COMPOSITE scope
+ * @param autowire if autowire is enabled
+ */
+ public RootDeploymentContext(ClassLoader classLoader,
+ URL scdlLocation,
+ URI componentId,
+ XMLInputFactory xmlFactory,
+ ScopeContainer scopeContainer,
+ boolean autowire) {
+ super(classLoader, scdlLocation, componentId, autowire);
+ this.xmlFactory = xmlFactory;
+ this.scopeContainer = scopeContainer;
+ }
+
+ public DeploymentContext getParent() {
+ return null;
+ }
+
+ public XMLInputFactory getXmlFactory() {
+ return xmlFactory;
+ }
+
+ public ScopeContainer getCompositeScope() {
+ return scopeContainer;
+ }
+
+ public URI getGroupId() {
+ return getComponentId();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/deployer/federation/FederatedDeployer.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/deployer/federation/FederatedDeployer.java
new file mode 100644
index 0000000000..a8e78d9c55
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/deployer/federation/FederatedDeployer.java
@@ -0,0 +1,181 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.deployer.federation;
+
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import java.util.Set;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.core.marshaller.PhysicalChangeSetMarshaller;
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.builder.Connector;
+import org.apache.tuscany.spi.builder.physical.PhysicalComponentBuilderRegistry;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ComponentManager;
+import org.apache.tuscany.spi.component.RegistrationException;
+import org.apache.tuscany.spi.marshaller.MarshalException;
+import org.apache.tuscany.spi.marshaller.ModelMarshallerRegistry;
+import org.apache.tuscany.spi.model.physical.PhysicalChangeSet;
+import org.apache.tuscany.spi.model.physical.PhysicalComponentDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireDefinition;
+import org.apache.tuscany.spi.services.discovery.DiscoveryService;
+import org.apache.tuscany.spi.services.discovery.RequestListener;
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * Federated deployer that deploys components in response to asynchronous messages from the federated domain.
+ *
+ * @version $Revision$ $Date$
+ */
+@EagerInit
+public class FederatedDeployer implements RequestListener {
+
+ /**
+ * Marshaller registry.
+ */
+ private ModelMarshallerRegistry marshallerRegistry;
+
+ /**
+ * Physical component builder registry.
+ */
+ private PhysicalComponentBuilderRegistry builderRegistry;
+
+ /**
+ * Component manager.
+ */
+ private ComponentManager componentManager;
+
+ /**
+ * Connector.
+ */
+ private Connector connector;
+
+ /**
+ * Deploys the component.
+ *
+ * @param content SCDL content.
+ * @return Response to the request message.
+ * <p/>
+ * TODO Handle response messages.
+ */
+ public XMLStreamReader onRequest(XMLStreamReader content) {
+
+ try {
+
+ // Get to the document element
+ while(content.next() != START_ELEMENT) {
+ }
+
+ final PhysicalChangeSet changeSet = (PhysicalChangeSet) marshallerRegistry.unmarshall(content);
+ applyChangeSet(changeSet);
+ } catch (MarshalException ex) {
+ // FIXME log this
+ ex.printStackTrace();
+ return null;
+ } catch (BuilderException ex) {
+ // FIXME log this
+ ex.printStackTrace();
+ return null;
+ } catch (RegistrationException ex) {
+ // FIXME log this
+ ex.printStackTrace();
+ return null;
+ } catch (XMLStreamException ex) {
+ // FIXME log this
+ ex.printStackTrace();
+ return null;
+ } catch (RuntimeException ex) {
+ // FIXME log this
+ ex.printStackTrace();
+ return null;
+ }
+
+ return null;
+ }
+
+ public void applyChangeSet(PhysicalChangeSet changeSet) throws BuilderException, RegistrationException {
+ Set<PhysicalComponentDefinition> componentDefinitions = changeSet.getComponentDefinitions();
+ List<Component> components = new ArrayList<Component>(componentDefinitions.size());
+ for (PhysicalComponentDefinition pcd : componentDefinitions) {
+ final Component component = builderRegistry.build(pcd);
+ components.add(component);
+ }
+ for (Component component : components) {
+ componentManager.register(component);
+ }
+ for (PhysicalWireDefinition pwd : changeSet.getWireDefinitions()) {
+ connector.connect(pwd);
+ }
+ for (Component component : components) {
+ component.start();
+ }
+ }
+
+ /**
+ * Injects the discovery service.
+ * @param discoveryService Discovery service to be injected.
+ */
+ @Reference
+ public void setDiscoveryService(DiscoveryService discoveryService) {
+ discoveryService.registerRequestListener(PhysicalChangeSetMarshaller.QNAME, this);
+ }
+
+ /**
+ * Injects the model marshaller registry.
+ * @param marshallerRegistry Marshaller registry.
+ */
+ @Reference
+ public void setMarshallerRegistry(ModelMarshallerRegistry marshallerRegistry) {
+ this.marshallerRegistry = marshallerRegistry;
+ }
+
+ /**
+ * Injects the builder registry.
+ * @param builderRegistry Builder registry.
+ */
+ @Reference
+ public void setBuilderRegistry(PhysicalComponentBuilderRegistry builderRegistry) {
+ this.builderRegistry = builderRegistry;
+ }
+
+ /**
+ * Injects the component manager.
+ * @param componentManager Component manager.
+ */
+ @Reference
+ public void setComponentManager(ComponentManager componentManager) {
+ this.componentManager = componentManager;
+ }
+
+ /**
+ * Injects the connector.
+ * @param connector Connector.
+ */
+ @Reference
+ public void setConnector(Connector connector) {
+ this.connector = connector;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/generator/DefaultGeneratorContext.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/generator/DefaultGeneratorContext.java
new file mode 100644
index 0000000000..aca3560667
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/generator/DefaultGeneratorContext.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.core.generator;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.generator.GeneratorContext;
+import org.apache.tuscany.spi.model.physical.PhysicalChangeSet;
+
+/**
+ * The default implementation of a GeneratorContext
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultGeneratorContext implements GeneratorContext {
+ private PhysicalChangeSet changeSet;
+
+
+ public DefaultGeneratorContext(PhysicalChangeSet changeSet) {
+ this.changeSet = changeSet;
+ }
+
+ public PhysicalChangeSet getPhysicalChangeSet() {
+ return changeSet;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/generator/GeneratorNotFoundException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/generator/GeneratorNotFoundException.java
new file mode 100644
index 0000000000..3ca18ac836
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/generator/GeneratorNotFoundException.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.core.generator;
+
+import org.apache.tuscany.spi.generator.GenerationException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class GeneratorNotFoundException extends GenerationException {
+ public GeneratorNotFoundException(Class<?> type) {
+ super("Generator not registered for type", type.getName());
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/generator/GeneratorRegistryImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/generator/GeneratorRegistryImpl.java
new file mode 100644
index 0000000000..a1462563ac
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/generator/GeneratorRegistryImpl.java
@@ -0,0 +1,275 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.generator;
+
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.tuscany.spi.generator.BindingGenerator;
+import org.apache.tuscany.spi.generator.ComponentGenerator;
+import org.apache.tuscany.spi.generator.GenerationException;
+import org.apache.tuscany.spi.generator.GeneratorContext;
+import org.apache.tuscany.spi.generator.GeneratorRegistry;
+import org.apache.tuscany.spi.generator.InterceptorGenerator;
+import org.apache.tuscany.spi.generator.ResourceGenerator;
+import org.apache.tuscany.spi.model.BindingDefinition;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.IntentDefinition;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ResourceDefinition;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalInterceptorDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition;
+
+import org.apache.tuscany.core.model.NonBlockingIntentDefinition;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class GeneratorRegistryImpl implements GeneratorRegistry {
+
+ private Map<Class<?>,
+ ComponentGenerator<? extends ComponentDefinition<? extends Implementation>>> componentGenerators;
+ private Map<Class<?>, BindingGenerator> bindingGenerators;
+ private Map<Class<?>, InterceptorGenerator<? extends IntentDefinition>> interceptorGenerators;
+ private Map<Class<?>, ResourceGenerator> resourceGenerators;
+
+
+ public GeneratorRegistryImpl() {
+ componentGenerators =
+ new ConcurrentHashMap<Class<?>,
+ ComponentGenerator<? extends ComponentDefinition<? extends Implementation>>>();
+ bindingGenerators = new ConcurrentHashMap<Class<?>, BindingGenerator>();
+ resourceGenerators = new ConcurrentHashMap<Class<?>, ResourceGenerator>();
+ interceptorGenerators = new ConcurrentHashMap<Class<?>, InterceptorGenerator<? extends IntentDefinition>>();
+ }
+
+ public void register(Class<?> clazz, BindingGenerator generator) {
+ bindingGenerators.put(clazz, generator);
+ }
+
+ public <T extends IntentDefinition> void register(Class<T> clazz, InterceptorGenerator<T> generator) {
+ interceptorGenerators.put(clazz, generator);
+ }
+
+ public void register(Class<?> clazz, ResourceGenerator generator) {
+ resourceGenerators.put(clazz, generator);
+ }
+
+ public <T extends Implementation<?>> void register(Class<T> clazz,
+ ComponentGenerator<ComponentDefinition<T>> generator) {
+ componentGenerators.put(clazz, generator);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public <C extends ComponentDefinition<? extends Implementation>> void generate(C definition,
+ GeneratorContext context)
+ throws GenerationException {
+ Class<?> type = definition.getImplementation().getClass();
+ ComponentGenerator<C> generator = (ComponentGenerator<C>) componentGenerators.get(type);
+ if (generator == null) {
+ throw new GeneratorNotFoundException(type);
+ }
+ generator.generate(definition, context);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public <C extends ComponentDefinition<? extends Implementation>>
+ void generateWire(ServiceContract<?> contract,
+ BindingDefinition bindingDefinition,
+ ServiceDefinition serviceDefinition,
+ C componentDefinition,
+ GeneratorContext context) throws GenerationException {
+
+ PhysicalWireDefinition wireDefinition = createWireDefinition(contract, context);
+ Class<?> type = componentDefinition.getImplementation().getClass();
+ ComponentGenerator<C> targetGenerator = (ComponentGenerator<C>) componentGenerators.get(type);
+ if (targetGenerator == null) {
+ throw new GeneratorNotFoundException(type);
+ }
+ PhysicalWireTargetDefinition targetDefinition =
+ targetGenerator.generateWireTarget(componentDefinition, serviceDefinition, context);
+ wireDefinition.setTarget(targetDefinition);
+ type = bindingDefinition.getClass();
+ BindingGenerator sourceGenerator = bindingGenerators.get(type);
+ if (sourceGenerator == null) {
+ throw new GeneratorNotFoundException(type);
+ }
+ PhysicalWireSourceDefinition sourceDefinition = sourceGenerator.generateWireSource(bindingDefinition, context);
+ wireDefinition.setSource(sourceDefinition);
+ context.getPhysicalChangeSet().addWireDefinition(wireDefinition);
+
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public <C extends ComponentDefinition<? extends Implementation>>
+ void generateWire(C componentDefinition,
+ ReferenceDefinition referenceDefinition,
+ BindingDefinition bindingDefinition,
+ GeneratorContext context) throws GenerationException {
+
+ ServiceContract<?> contract = referenceDefinition.getServiceContract();
+ PhysicalWireDefinition wireDefinition = createWireDefinition(contract, context);
+ Class<?> type = bindingDefinition.getClass();
+ BindingGenerator targetGenerator = bindingGenerators.get(type);
+ if (targetGenerator == null) {
+ throw new GeneratorNotFoundException(type);
+ }
+ PhysicalWireTargetDefinition targetDefinition = targetGenerator.generateWireTarget(bindingDefinition, context);
+ wireDefinition.setTarget(targetDefinition);
+
+ type = componentDefinition.getImplementation().getClass();
+ ComponentGenerator<C> sourceGenerator = (ComponentGenerator<C>) componentGenerators.get(type);
+ if (sourceGenerator == null) {
+ throw new GeneratorNotFoundException(type);
+ }
+ PhysicalWireSourceDefinition sourceDefinition =
+ sourceGenerator.generateWireSource(componentDefinition, referenceDefinition, false, context);
+ wireDefinition.setSource(sourceDefinition);
+
+ context.getPhysicalChangeSet().addWireDefinition(wireDefinition);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public <S extends ComponentDefinition<? extends Implementation>,
+ T extends ComponentDefinition<? extends Implementation>>
+ void generateWire(S source,
+ ReferenceDefinition referenceDefinition,
+ ServiceDefinition serviceDefinition,
+ T target,
+ GeneratorContext context) throws GenerationException {
+ ServiceContract<?> contract = referenceDefinition.getServiceContract();
+ PhysicalWireDefinition wireDefinition = createWireDefinition(contract, context);
+ Class<?> type = target.getImplementation().getClass();
+ ComponentGenerator<T> targetGenerator = (ComponentGenerator<T>) componentGenerators.get(type);
+ if (targetGenerator == null) {
+ throw new GeneratorNotFoundException(type);
+ }
+ PhysicalWireTargetDefinition targetDefinition =
+ targetGenerator.generateWireTarget(target, serviceDefinition, context);
+ wireDefinition.setTarget(targetDefinition);
+
+ type = source.getImplementation().getClass();
+ ComponentGenerator<S> sourceGenerator = (ComponentGenerator<S>) componentGenerators.get(type);
+ if (sourceGenerator == null) {
+ throw new GeneratorNotFoundException(type);
+ }
+ // determine if it is optimizable
+ boolean optimizable = true;
+ for (PhysicalOperationDefinition operation : wireDefinition.getOperations()) {
+ if (!operation.getInterceptors().isEmpty()){
+ optimizable = false;
+ break;
+ }
+ }
+ PhysicalWireSourceDefinition sourceDefinition =
+ sourceGenerator.generateWireSource(source, referenceDefinition, optimizable, context);
+ wireDefinition.setSource(sourceDefinition);
+ context.getPhysicalChangeSet().addWireDefinition(wireDefinition);
+ }
+
+ public URI generate(ResourceDefinition definition, GeneratorContext context) throws GenerationException {
+ Class<?> type = definition.getClass();
+ ResourceGenerator generator = resourceGenerators.get(type);
+ if (generator == null) {
+ throw new GeneratorNotFoundException(type);
+ }
+ return generator.generate(definition, context);
+ }
+
+
+ @SuppressWarnings({"unchecked"})
+ private PhysicalOperationDefinition mapOperation(Operation o) {
+ PhysicalOperationDefinition operation = new PhysicalOperationDefinition();
+ operation.setName(o.getName());
+ operation.setConversationSequence(o.getConversationSequence());
+ Type returnType = o.getOutputType().getPhysical();
+ // TODO this needs to be fixed
+ if (returnType instanceof Class) {
+ operation.setReturnType(((Class) returnType).getName());
+ } else if (returnType != null) {
+ throw new AssertionError();
+ }
+
+ DataType<List<? extends DataType<?>>> params = o.getInputType();
+ for (DataType<?> param : params.getLogical()) {
+ Type paramType = param.getPhysical();
+ // TODO this needs to be fixed
+ if (paramType instanceof Class) {
+ operation.addParameter(((Class) paramType).getName());
+ } else if (paramType != null) {
+ throw new AssertionError();
+ }
+ }
+ return operation;
+
+ }
+
+
+ @SuppressWarnings({"unchecked"})
+ private PhysicalWireDefinition createWireDefinition(ServiceContract<?> contract, GeneratorContext context)
+ throws GenerationException {
+ PhysicalWireDefinition wireDefinition = new PhysicalWireDefinition();
+ for (Operation o : contract.getOperations().values()) {
+ PhysicalOperationDefinition physicalOperation = mapOperation(o);
+ wireDefinition.addOperation(physicalOperation);
+ if (o.isNonBlocking()) {
+ // this is egregious
+ // hardcode intent until we get the intent infrastructure in place
+ IntentDefinition intent = new NonBlockingIntentDefinition();
+ Class<? extends IntentDefinition> type = NonBlockingIntentDefinition.class;
+ InterceptorGenerator generator = interceptorGenerators.get(type);
+ if (generator == null) {
+ throw new GeneratorNotFoundException(type);
+ }
+ PhysicalInterceptorDefinition interceptorDefinition = generator.generate(intent, context);
+ physicalOperation.addInterceptor(interceptorDefinition);
+ }
+ }
+ for (Operation o : contract.getCallbackOperations().values()) {
+ PhysicalOperationDefinition physicalOperation = mapOperation(o);
+ physicalOperation.setCallback(true);
+ wireDefinition.addOperation(physicalOperation);
+ if (o.isNonBlocking()) {
+ // this is egregious
+ // hardcode intent until we get the intent infrastructure in place
+ IntentDefinition intent = new NonBlockingIntentDefinition();
+ Class<? extends IntentDefinition> type = NonBlockingIntentDefinition.class;
+ InterceptorGenerator generator = interceptorGenerators.get(type);
+ if (generator == null) {
+ throw new GeneratorNotFoundException(type);
+ }
+ PhysicalInterceptorDefinition interceptorDefinition = generator.generate(intent, context);
+ physicalOperation.addInterceptor(interceptorDefinition);
+ }
+ }
+ return wireDefinition;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/idl/java/IllegalCallbackException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/idl/java/IllegalCallbackException.java
new file mode 100644
index 0000000000..f52bd4cfb1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/idl/java/IllegalCallbackException.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.core.idl.java;
+
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+
+/**
+ * Denotes an illegal callback interface
+ *
+ * @version $Rev$ $Date$
+ */
+
+public class IllegalCallbackException extends InvalidServiceContractException {
+
+ public IllegalCallbackException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/idl/java/InterfaceJavaLoader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/idl/java/InterfaceJavaLoader.java
new file mode 100644
index 0000000000..e2169d8978
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/idl/java/InterfaceJavaLoader.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.core.idl.java;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.loader.InvalidValueException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.LoaderUtil;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * Loads a Java interface definition from an XML-based assembly file
+ *
+ * @version $Rev$ $Date$
+ */
+public class InterfaceJavaLoader extends LoaderExtension<JavaServiceContract> {
+ public static final QName INTERFACE_JAVA = new QName(SCA_NS, "interface.java");
+
+ private final JavaInterfaceProcessorRegistry interfaceRegsitry;
+
+ @Constructor({"registry", "interfaceRegsitry"})
+ public InterfaceJavaLoader(@Reference LoaderRegistry registry,
+ @Reference JavaInterfaceProcessorRegistry interfaceRegistry) {
+ super(registry);
+ this.interfaceRegsitry = interfaceRegistry;
+ }
+
+ public QName getXMLType() {
+ return INTERFACE_JAVA;
+ }
+
+ public JavaServiceContract load(
+ ModelObject object, XMLStreamReader reader,
+ DeploymentContext deploymentContext)
+ throws XMLStreamException, LoaderException {
+
+ assert INTERFACE_JAVA.equals(reader.getName());
+ String conversationalAttr = reader.getAttributeValue(null, "conversational");
+ boolean conversational = Boolean.parseBoolean(conversationalAttr);
+ String name = reader.getAttributeValue(null, "interface");
+ if (name == null) {
+ // allow "class" as well as seems to be a common mistake
+ name = reader.getAttributeValue(null, "class");
+ }
+ if (name == null) {
+ throw new InvalidValueException("interface name not supplied");
+ }
+ Class<?> interfaceClass = LoaderUtil.loadClass(name, deploymentContext.getClassLoader());
+
+ name = reader.getAttributeValue(null, "callbackInterface");
+ Class<?> callbackClass = (name != null) ? LoaderUtil.loadClass(name, deploymentContext.getClassLoader()) : null;
+
+ Map<Class<?>, ModelObject> extensions = new HashMap<Class<?>, ModelObject>();
+ while (true) {
+ int event = reader.next();
+ if (event == XMLStreamConstants.START_ELEMENT) {
+ ModelObject mo = registry.load(null, reader, deploymentContext);
+ if (mo != null) {
+ extensions.put(mo.getClass(), mo);
+ }
+ } else if (event == XMLStreamConstants.END_ELEMENT && reader.getName().equals(INTERFACE_JAVA)) {
+ break;
+ }
+ }
+ JavaServiceContract serviceContract;
+ try {
+ serviceContract = interfaceRegsitry.introspect(interfaceClass, callbackClass);
+ } catch (InvalidServiceContractException e) {
+ throw new LoaderException(interfaceClass.getName(), e);
+ }
+
+ // Set databinding from the SCDL extension <databinding>
+ DataType<?> dataType = (DataType<?>) extensions.get(DataType.class);
+ if (dataType != null) {
+ serviceContract.setDataBinding(dataType.getDataBinding());
+ }
+ serviceContract.getExtensions().putAll(extensions);
+ serviceContract.setConversational(conversational);
+ return serviceContract;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/idl/java/JavaInterfaceProcessorRegistryImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/idl/java/JavaInterfaceProcessorRegistryImpl.java
new file mode 100644
index 0000000000..e844888f69
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/idl/java/JavaInterfaceProcessorRegistryImpl.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.core.idl.java;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.Conversational;
+import org.osoa.sca.annotations.EndsConversation;
+import org.osoa.sca.annotations.OneWay;
+import org.osoa.sca.annotations.Remotable;
+
+import org.apache.tuscany.spi.idl.InvalidConversationalOperationException;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.OverloadedOperationException;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessor;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+import static org.apache.tuscany.spi.model.Operation.CONVERSATION_END;
+import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION;
+
+import static org.apache.tuscany.core.util.JavaIntrospectionHelper.getBaseName;
+
+/**
+ * Default implementation of an InterfaceJavaIntrospector.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaInterfaceProcessorRegistryImpl implements JavaInterfaceProcessorRegistry {
+ public static final String IDL_INPUT = "idl:input";
+
+ private static final String UNKNOWN_DATABINDING = null;
+
+ private List<JavaInterfaceProcessor> processors = new ArrayList<JavaInterfaceProcessor>();
+
+ public JavaInterfaceProcessorRegistryImpl() {
+ }
+
+ public void registerProcessor(JavaInterfaceProcessor processor) {
+ processors.add(processor);
+ }
+
+ public void unregisterProcessor(JavaInterfaceProcessor processor) {
+ processors.remove(processor);
+ }
+
+ public <T> JavaServiceContract<T> introspect(Class<T> type) throws InvalidServiceContractException {
+ Class<?> callbackClass = null;
+ Callback callback = type.getAnnotation(Callback.class);
+ if (callback != null && !Void.class.equals(callback.value())) {
+ callbackClass = callback.value();
+ } else if (callback != null && Void.class.equals(callback.value())) {
+ throw new IllegalCallbackException("No callback interface specified on annotation", type.getName());
+ }
+ return introspect(type, callbackClass);
+ }
+
+ public <I, C> JavaServiceContract<I> introspect(Class<I> type, Class<C> callback)
+ throws InvalidServiceContractException {
+ JavaServiceContract<I> contract = new JavaServiceContract<I>();
+ contract.setInterfaceName(getBaseName(type));
+ contract.setInterfaceClass(type);
+ boolean remotable = type.isAnnotationPresent(Remotable.class);
+ contract.setRemotable(remotable);
+ //Scope interactionScope = type.getAnnotation(Scope.class);
+ boolean conversational = type.isAnnotationPresent(Conversational.class);
+ contract.setConversational(conversational);
+ contract.setOperations(getOperations(type, remotable, conversational));
+
+ if (callback != null) {
+ contract.setCallbackName(getBaseName(callback));
+ contract.setCallbackClass(callback);
+ contract.setCallbackOperations(getOperations(callback, remotable, conversational));
+ }
+
+ for (JavaInterfaceProcessor processor : processors) {
+ processor.visitInterface(type, callback, contract);
+ }
+ return contract;
+ }
+
+ private <T> Map<String, Operation<Type>> getOperations(Class<T> type, boolean remotable, boolean conversational)
+ throws InvalidServiceContractException {
+ Method[] methods = type.getMethods();
+ Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>(methods.length);
+ for (Method method : methods) {
+ String name = method.getName();
+ if (remotable && operations.containsKey(name)) {
+ throw new OverloadedOperationException(method);
+ }
+
+ Type returnType = method.getGenericReturnType();
+ Type[] paramTypes = method.getGenericParameterTypes();
+ Type[] faultTypes = method.getGenericExceptionTypes();
+ boolean nonBlocking = method.isAnnotationPresent(OneWay.class);
+ int conversationSequence = NO_CONVERSATION;
+ if (method.isAnnotationPresent(EndsConversation.class)) {
+ if (!conversational) {
+ throw new InvalidConversationalOperationException(
+ "Method is marked as end conversation but contract is not conversational",
+ method.getDeclaringClass().getName(),
+ method);
+ }
+ conversationSequence = CONVERSATION_END;
+ } else if (conversational) {
+ conversationSequence = Operation.CONVERSATION_CONTINUE;
+ }
+
+ DataType<Type> returnDataType = new DataType<Type>(UNKNOWN_DATABINDING, returnType, returnType);
+ List<DataType<Type>> paramDataTypes = new ArrayList<DataType<Type>>(paramTypes.length);
+ for (Type paramType : paramTypes) {
+ paramDataTypes.add(new DataType<Type>(UNKNOWN_DATABINDING, paramType, paramType));
+ }
+ List<DataType<Type>> faultDataTypes = new ArrayList<DataType<Type>>(faultTypes.length);
+ for (Type faultType : faultTypes) {
+ faultDataTypes.add(new DataType<Type>(UNKNOWN_DATABINDING, faultType, faultType));
+ }
+
+ DataType<List<DataType<Type>>> inputType =
+ new DataType<List<DataType<Type>>>(IDL_INPUT, Object[].class, paramDataTypes);
+ Operation<Type> operation = new Operation<Type>(name,
+ inputType,
+ returnDataType,
+ faultDataTypes,
+ nonBlocking,
+ UNKNOWN_DATABINDING,
+ conversationSequence);
+ operations.put(name, operation);
+ }
+ return operations;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/IntrospectionRegistryImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/IntrospectionRegistryImpl.java
new file mode 100644
index 0000000000..3c0986a83e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/IntrospectionRegistryImpl.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.core.implementation;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessor;
+import org.apache.tuscany.spi.implementation.java.IntrospectionRegistry;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+import org.apache.tuscany.core.util.JavaIntrospectionHelper;
+
+/**
+ * Default implementation of the <code>IntrospectionRegistry</code>
+ *
+ * @version $Rev$ $Date$
+ */
+public class IntrospectionRegistryImpl implements IntrospectionRegistry {
+
+ private Monitor monitor;
+ private List<ImplementationProcessor> cache = new ArrayList<ImplementationProcessor>();
+
+ public IntrospectionRegistryImpl() {
+ }
+
+ public IntrospectionRegistryImpl(Monitor monitor) {
+ this.monitor = monitor;
+ }
+
+ @org.apache.tuscany.api.annotation.Monitor
+ public void setMonitor(Monitor monitor) {
+ this.monitor = monitor;
+ }
+
+ public void registerProcessor(ImplementationProcessor processor) {
+ monitor.register(processor);
+ cache.add(processor);
+ }
+
+ public void unregisterProcessor(ImplementationProcessor processor) {
+ monitor.unregister(processor);
+ cache.remove(processor);
+ }
+
+ public PojoComponentType introspect(Class<?> clazz,
+ PojoComponentType<JavaMappedService, JavaMappedReference,
+ JavaMappedProperty<?>> type,
+ DeploymentContext context)
+ throws ProcessingException {
+ for (ImplementationProcessor processor : cache) {
+ processor.visitClass(clazz, type, context);
+ }
+
+ for (Constructor<?> constructor : clazz.getConstructors()) {
+ for (ImplementationProcessor processor : cache) {
+ processor.visitConstructor(constructor, type, context);
+ }
+ }
+
+ Set<Method> methods = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(clazz);
+ for (Method method : methods) {
+ for (ImplementationProcessor processor : cache) {
+ processor.visitMethod(method, type, context);
+ }
+ }
+
+ Set<Field> fields = JavaIntrospectionHelper.getAllPublicAndProtectedFields(clazz);
+ for (Field field : fields) {
+ for (ImplementationProcessor processor : cache) {
+ processor.visitField(field, type, context);
+ }
+ }
+
+ Class superClass = clazz.getSuperclass();
+ if (superClass != null) {
+ visitSuperClass(superClass, type, context);
+ }
+
+ for (ImplementationProcessor processor : cache) {
+ processor.visitEnd(clazz, type, context);
+ }
+ return type;
+ }
+
+ private void visitSuperClass(Class<?> clazz,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context)
+ throws ProcessingException {
+ if (!Object.class.equals(clazz)) {
+ for (ImplementationProcessor processor : cache) {
+ processor.visitSuperClass(clazz, type, context);
+ }
+ clazz = clazz.getSuperclass();
+ if (clazz != null) {
+ visitSuperClass(clazz, type, context);
+ }
+ }
+ }
+
+ public static interface Monitor {
+ void register(ImplementationProcessor processor);
+
+ void unregister(ImplementationProcessor processor);
+
+ void processing(ImplementationProcessor processor);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/POJOPhysicalComponentBuilder.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/POJOPhysicalComponentBuilder.java
new file mode 100644
index 0000000000..4bb5f0cde8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/POJOPhysicalComponentBuilder.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.core.implementation;
+
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.core.component.instancefactory.IFProviderBuilderRegistry;
+import org.apache.tuscany.core.implementation.system.model.SystemPhysicalComponentDefinition;
+import org.apache.tuscany.spi.builder.physical.PhysicalComponentBuilder;
+import org.apache.tuscany.spi.builder.physical.PhysicalComponentBuilderRegistry;
+import org.apache.tuscany.spi.builder.physical.WireAttacherRegistry;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.model.physical.PhysicalComponentDefinition;
+import org.apache.tuscany.spi.services.classloading.ClassLoaderRegistry;
+
+/**
+ * Base class for PhysicalComponentBuilders that build components based on POJOs.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class POJOPhysicalComponentBuilder<PCD extends PhysicalComponentDefinition, C extends Component>
+ implements PhysicalComponentBuilder<PCD, C> {
+
+ protected final PhysicalComponentBuilderRegistry builderRegistry;
+ protected final WireAttacherRegistry wireAttacherRegistry;
+ protected final ScopeRegistry scopeRegistry;
+ protected final IFProviderBuilderRegistry providerBuilders;
+ protected final ClassLoaderRegistry classLoaderRegistry;
+
+ protected POJOPhysicalComponentBuilder(
+ @Reference(name = "builderRegistry")PhysicalComponentBuilderRegistry builderRegistry,
+ @Reference(name = "wireAttacherRegistry")WireAttacherRegistry wireAttacherRegistry,
+ @Reference(name = "scopeRegistry")ScopeRegistry scopeRegistry,
+ @Reference(name = "providerBuilders")IFProviderBuilderRegistry providerBuilders,
+ @Reference(name = "classloaderRegistry")ClassLoaderRegistry classLoaderRegistry) {
+ this.builderRegistry = builderRegistry;
+ this.wireAttacherRegistry = wireAttacherRegistry;
+ this.scopeRegistry = scopeRegistry;
+ this.providerBuilders = providerBuilders;
+ this.classLoaderRegistry = classLoaderRegistry;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PhysicalComponent.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PhysicalComponent.java
new file mode 100644
index 0000000000..b8e8c6cf51
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PhysicalComponent.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.core.implementation;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.extension.AbstractComponentExtension;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.core.component.InstanceFactory;
+
+/**
+ * Base class for implementations of physical components.
+ *
+ * @version $Rev$ $Date$
+ * @param <T> the type of the physical instance
+ */
+public abstract class PhysicalComponent<T> extends AbstractComponentExtension {
+ private final InstanceFactory<T> factory;
+
+ /**
+ * Constructor specifying the component id.
+ *
+ * @param id the component id
+ * @param factory a factory for physical instances
+ */
+ protected PhysicalComponent(URI id, InstanceFactory<T> factory) {
+ super(id);
+ this.factory = factory;
+ }
+
+ public InstanceWrapper<T> createInstance() {
+ return factory.newInstance();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PojoAtomicComponent.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PojoAtomicComponent.java
new file mode 100644
index 0000000000..eb7dbc9eaf
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PojoAtomicComponent.java
@@ -0,0 +1,397 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation;
+
+import java.lang.reflect.Field;
+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 java.util.concurrent.ConcurrentHashMap;
+
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.ServiceReference;
+
+import org.apache.tuscany.spi.CoreRuntimeException;
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.TargetDestructionException;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.extension.AtomicComponentExtension;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.wire.Wire;
+
+import org.apache.tuscany.core.component.ComponentContextImpl;
+import org.apache.tuscany.core.component.ComponentContextProvider;
+import org.apache.tuscany.core.component.InstanceFactory;
+import org.apache.tuscany.core.component.ServiceReferenceImpl;
+import org.apache.tuscany.core.component.scope.ReflectiveInstanceWrapper;
+import org.apache.tuscany.core.injection.ArrayMultiplicityObjectFactory;
+import org.apache.tuscany.core.injection.CallbackWireObjectFactory;
+import org.apache.tuscany.core.injection.ConversationIDObjectFactory;
+import org.apache.tuscany.core.injection.EventInvoker;
+import org.apache.tuscany.core.injection.FieldInjector;
+import org.apache.tuscany.core.injection.Injector;
+import org.apache.tuscany.core.injection.InvalidAccessorException;
+import org.apache.tuscany.core.injection.ListMultiplicityObjectFactory;
+import org.apache.tuscany.core.injection.MethodInjector;
+import org.apache.tuscany.core.injection.NoAccessorException;
+import org.apache.tuscany.core.injection.NoMultiplicityTypeException;
+import org.apache.tuscany.core.injection.ObjectCallbackException;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+
+/**
+ * Base implementation of an {@link org.apache.tuscany.spi.component.AtomicComponent} whose type is a Java class
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public abstract class PojoAtomicComponent extends AtomicComponentExtension implements ComponentContextProvider {
+ protected EventInvoker<Object> initInvoker;
+ protected EventInvoker<Object> destroyInvoker;
+ protected PojoObjectFactory<?> instanceFactory;
+ protected InstanceFactory<?> instanceFactory2;
+ protected List<String> constructorParamNames;
+ protected Map<String, Member> referenceSites;
+ protected Map<String, Member> resourceSites;
+ protected Map<String, Member> propertySites;
+ protected Map<String, Member> callbackSites;
+ protected List<Injector<Object>> injectors;
+ protected Class implementationClass;
+ protected Map<String, List<Wire>> wires = new HashMap<String, List<Wire>>();
+ protected Map<String, List<Wire>> callBackwires = new HashMap<String, List<Wire>>();
+
+ private final ComponentContext componentContext;
+ private final Map<String, ObjectFactory<?>> propertyFactories = new ConcurrentHashMap<String, ObjectFactory<?>>();
+ private List<Class<?>> constructorParamTypes = new ArrayList<Class<?>>();
+
+ public PojoAtomicComponent(PojoConfiguration configuration) {
+ super(configuration.getName(),
+ configuration.getProxyService(),
+ configuration.getWorkContext(),
+ configuration.getGroupId(),
+ configuration.getInitLevel(),
+ configuration.getMaxIdleTime(),
+ configuration.getMaxAge());
+ assert configuration.getInstanceFactory() != null : "Object factory was null";
+ initInvoker = configuration.getInitInvoker();
+ destroyInvoker = configuration.getDestroyInvoker();
+ instanceFactory = configuration.getInstanceFactory();
+ instanceFactory2 = configuration.getInstanceFactory2();
+ constructorParamNames = configuration.getConstructorParamNames();
+ constructorParamTypes = configuration.getConstructorParamTypes();
+ injectors = new ArrayList<Injector<Object>>();
+ referenceSites = configuration.getReferenceSite() != null ? configuration.getReferenceSite()
+ : new HashMap<String, Member>();
+ propertySites = configuration.getPropertySites() != null ? configuration.getPropertySites()
+ : new HashMap<String, Member>();
+ resourceSites = configuration.getResourceSites() != null ? configuration.getResourceSites()
+ : new HashMap<String, Member>();
+ callbackSites = configuration.getCallbackSites() != null ? configuration.getCallbackSites()
+ : new HashMap<String, Member>();
+ implementationClass = configuration.getImplementationClass();
+
+ componentContext = new ComponentContextImpl(this);
+ }
+
+ public void destroy(Object instance) throws TargetDestructionException {
+ if (destroyInvoker != null) {
+ try {
+ destroyInvoker.invokeEvent(instance);
+ } catch (ObjectCallbackException e) {
+ throw new TargetDestructionException("Error destroying component instance", getUri().toString(), e);
+ }
+ }
+ }
+
+ public boolean isOptimizable() {
+ // stateless implementations that require a destroy callback cannot be optimized since the callback is
+ // performed by the JavaTargetInvoker
+ return !(getScope() == Scope.STATELESS && destroyInvoker != null);
+ }
+
+ public Object getTargetInstance() throws TargetResolutionException {
+ InstanceWrapper wrapper = scopeContainer.getWrapper(this, groupId);
+ if (!wrapper.isStarted()) {
+ wrapper.start();
+ }
+ return wrapper.getInstance();
+ }
+
+ public Object createInstance() throws ObjectCreationException {
+ Object instance = instanceFactory.getInstance();
+ // inject the instance with properties and references
+ for (Injector<Object> injector : injectors) {
+ injector.inject(instance);
+ }
+ return instance;
+ }
+
+ public InstanceWrapper<?> createInstanceWrapper() throws ObjectCreationException {
+/* FIXME make this work
+ return instanceFactory2.newInstance();
+*/
+ Object instance = createInstance();
+ return new ReflectiveInstanceWrapper<Object>(instance, initInvoker, destroyInvoker);
+ }
+
+ public List<Wire> getWires(String name) {
+ return wires.get(name);
+ }
+
+ public void attachWire(Wire wire) {
+ assert wire.getSourceUri().getFragment() != null;
+ String referenceName = wire.getSourceUri().getFragment();
+ List<Wire> wireList = wires.get(referenceName);
+ if (wireList == null) {
+ wireList = new ArrayList<Wire>();
+ wires.put(referenceName, wireList);
+ }
+ wireList.add(wire);
+ Member member = referenceSites.get(referenceName);
+ if (member != null) {
+ injectors.add(createInjector(member, wire));
+ }
+ // cycle through constructor param names as well
+ for (int i = 0; i < constructorParamNames.size(); i++) {
+ if (referenceName.equals(constructorParamNames.get(i))) {
+ ObjectFactory[] initializerFactories = instanceFactory.getInitializerFactories();
+ initializerFactories[i] = createWireFactory(constructorParamTypes.get(i), wire);
+ break;
+ }
+ }
+ //TODO error if ref not set on constructor or ref site
+
+ }
+
+ public void attachWires(List<Wire> attachWires) {
+ assert attachWires.size() > 0;
+ assert attachWires.get(0).getSourceUri().getFragment() != null;
+ String referenceName = attachWires.get(0).getSourceUri().getFragment();
+ List<Wire> wireList = wires.get(referenceName);
+ if (wireList == null) {
+ wireList = new ArrayList<Wire>();
+ wires.put(referenceName, wireList);
+ }
+ wireList.addAll(attachWires);
+ Member member = referenceSites.get(referenceName);
+ if (member == null) {
+ if (constructorParamNames.contains(referenceName)) {
+ // injected on the constructor
+ throw new UnsupportedOperationException();
+ } else {
+ throw new NoAccessorException(referenceName);
+ }
+ }
+
+ Class<?> type = attachWires.get(0).getSourceContract().getInterfaceClass();
+ if (type == null) {
+ throw new NoMultiplicityTypeException("Java interface must be specified for multiplicity", referenceName);
+ }
+ injectors.add(createMultiplicityInjector(member, type, wireList));
+
+ }
+
+ public void attachCallbackWire(Wire wire) {
+ assert wire.getSourceUri().getFragment() != null;
+ String callbackName = wire.getSourceContract().getCallbackName();
+ assert callbackSites.get(callbackName) != null;
+ List<Wire> wireList = callBackwires.get(callbackName);
+ if (wireList == null) {
+ wireList = new ArrayList<Wire>();
+ callBackwires.put(callbackName, wireList);
+ }
+ wireList.add(wire);
+ }
+
+ public void start() throws CoreRuntimeException {
+ if (!callbackSites.isEmpty()) {
+ for (Map.Entry<String, Member> entry : callbackSites.entrySet()) {
+ List<Wire> wires = callBackwires.get(entry.getKey());
+ if (wires == null) {
+ // this can happen when there are no client wires to a component that has a callback
+ continue;
+ }
+ Member member = entry.getValue();
+ if (member instanceof Field) {
+ Field field = (Field) member;
+ ObjectFactory<?> factory = new CallbackWireObjectFactory(field.getType(), proxyService, wires);
+ injectors.add(new FieldInjector<Object>(field, factory));
+ } else if (member instanceof Method) {
+ Method method = (Method) member;
+ Class<?> type = method.getParameterTypes()[0];
+ ObjectFactory<?> factory = new CallbackWireObjectFactory(type, proxyService, wires);
+ injectors.add(new MethodInjector<Object>(method, factory));
+ } else {
+ throw new InvalidAccessorException("Member must be a field or method", member.getName());
+ }
+ }
+ }
+ super.start();
+
+ }
+
+ public void addPropertyFactory(String name, ObjectFactory<?> factory) {
+ Member member = propertySites.get(name);
+ if (member instanceof Field) {
+ injectors.add(new FieldInjector<Object>((Field) member, factory));
+ } else if (member instanceof Method) {
+ injectors.add(new MethodInjector<Object>((Method) member, factory));
+ }
+ // cycle through constructor param names as well
+ for (int i = 0; i < constructorParamNames.size(); i++) {
+ if (name.equals(constructorParamNames.get(i))) {
+ ObjectFactory[] initializerFactories = instanceFactory.getInitializerFactories();
+ initializerFactories[i] = factory;
+ break;
+ }
+ }
+ //FIXME throw an error if no injection site found
+
+ propertyFactories.put(name, factory);
+ }
+
+ public void addResourceFactory(String name, ObjectFactory<?> factory) {
+ Member member = resourceSites.get(name);
+ if (member instanceof Field) {
+ injectors.add(new FieldInjector<Object>((Field) member, factory));
+ } else if (member instanceof Method) {
+ injectors.add(new MethodInjector<Object>((Method) member, factory));
+ }
+ // cycle through constructor param names as well
+ for (int i = 0; i < constructorParamNames.size(); i++) {
+ if (name.equals(constructorParamNames.get(i))) {
+ ObjectFactory[] initializerFactories = instanceFactory.getInitializerFactories();
+ initializerFactories[i] = factory;
+ break;
+ }
+ }
+ //FIXME throw an error if no injection site found
+ }
+
+ public void addConversationIDFactory(Member member) {
+ ObjectFactory<String> convIDObjectFactory = new ConversationIDObjectFactory(workContext);
+ if (member instanceof Field) {
+ injectors.add(new FieldInjector<Object>((Field) member, convIDObjectFactory));
+ } else if (member instanceof Method) {
+ injectors.add(new MethodInjector<Object>((Method) member, convIDObjectFactory));
+ } else {
+ throw new InvalidAccessorException("Member must be a field or method", member.getName());
+ }
+ }
+
+ public boolean implementsCallback(Class callbackClass) {
+ Class<?>[] implementedInterfaces = implementationClass.getInterfaces();
+ for (Class<?> implementedInterface : implementedInterfaces) {
+ if (implementedInterface.isAssignableFrom(callbackClass)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ protected Injector<Object> createInjector(Member member, Wire wire) {
+ if (member instanceof Field) {
+ Class<?> type = ((Field) member).getType();
+ ObjectFactory<?> factory = createWireFactory(type, wire);
+ return new FieldInjector<Object>((Field) member, factory);
+ } else if (member instanceof Method) {
+ Class<?> type = ((Method) member).getParameterTypes()[0];
+ ObjectFactory<?> factory = createWireFactory(type, wire);
+ return new MethodInjector<Object>((Method) member, factory);
+ } else {
+ throw new InvalidAccessorException("Member must be a field or method", member.getName());
+ }
+ }
+
+ protected Injector<Object> createMultiplicityInjector(Member member,
+ Class<?> interfaceType,
+ List<Wire> wireFactories) {
+ List<ObjectFactory<?>> factories = new ArrayList<ObjectFactory<?>>();
+ for (Wire wire : wireFactories) {
+ factories.add(createWireFactory(interfaceType, wire));
+ }
+ if (member instanceof Field) {
+ Field field = (Field) member;
+ if (field.getType().isArray()) {
+ return new FieldInjector<Object>(field, new ArrayMultiplicityObjectFactory(interfaceType, factories));
+ } else {
+ return new FieldInjector<Object>(field, new ListMultiplicityObjectFactory(factories));
+ }
+ } else if (member instanceof Method) {
+ Method method = (Method) member;
+ if (method.getParameterTypes()[0].isArray()) {
+ return new MethodInjector<Object>(method, new ArrayMultiplicityObjectFactory(interfaceType, factories));
+ } else {
+ return new MethodInjector<Object>(method, new ListMultiplicityObjectFactory(factories));
+ }
+ } else {
+ throw new InvalidAccessorException("Member must be a field or method", member.getName());
+ }
+ }
+
+ public ComponentContext getComponentContext() {
+ return componentContext;
+ }
+
+ public <B> B getProperty(Class<B> type, String propertyName) {
+ ObjectFactory<?> factory = propertyFactories.get(propertyName);
+ if (factory != null) {
+ return type.cast(factory.getInstance());
+ } else {
+ return null;
+ }
+
+ }
+
+ public <B> B getService(Class<B> type, String name) {
+ List<Wire> referenceWires = wires.get(name);
+ if (referenceWires == null || referenceWires.size() < 1) {
+ return null;
+ } else {
+ // TODO support multiplicity
+ Wire wire = referenceWires.get(0);
+ ObjectFactory<B> factory = createWireFactory(type, wire);
+ return factory.getInstance();
+ }
+ }
+
+ public <B> ServiceReference<B> getServiceReference(Class<B> type, String name) {
+ List<Wire> referenceWires = wires.get(name);
+ if (referenceWires == null || referenceWires.size() < 1) {
+ return null;
+ } else {
+ // TODO support multiplicity
+ Wire wire = referenceWires.get(0);
+ ObjectFactory<B> factory = createWireFactory(type, wire);
+ return new ServiceReferenceImpl<B>(type, factory);
+ }
+ }
+
+ public <B, R extends CallableReference<B>> R cast(B target) {
+ return (R) proxyService.cast(target);
+ }
+
+ protected abstract <B> ObjectFactory<B> createWireFactory(Class<B> interfaze, Wire wire);
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PojoComponent.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PojoComponent.java
new file mode 100644
index 0000000000..295ec5482a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PojoComponent.java
@@ -0,0 +1,218 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation;
+
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+
+import org.osoa.sca.ComponentContext;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.component.AbstractSCAObject;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ComponentException;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.RegistrationException;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.PropertyValue;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+import org.apache.tuscany.core.component.InstanceFactory;
+import org.apache.tuscany.core.component.InstanceFactoryProvider;
+import org.apache.tuscany.core.component.ComponentObjectFactory;
+import org.apache.tuscany.core.model.physical.instancefactory.InjectionSource;
+
+/**
+ * Base class for Component implementations based on Java objects.
+ *
+ * @version $Rev$ $Date$
+ * @param <T> the implementation class
+ */
+public abstract class PojoComponent<T> extends AbstractSCAObject implements AtomicComponent<T> {
+ private final InstanceFactoryProvider<T> provider;
+ private final ScopeContainer<?> scopeContainer;
+ private final URI groupId;
+ private final int initLevel;
+ private final long maxIdleTime;
+ private final long maxAge;
+ private InstanceFactory<T> instanceFactory;
+
+ public PojoComponent(URI componentId,
+ InstanceFactoryProvider<T> provider,
+ ScopeContainer<?> scopeContainer,
+ URI groupId,
+ int initLevel,
+ long maxIdleTime,
+ long maxAge) {
+ super(componentId);
+ this.provider = provider;
+ this.scopeContainer = scopeContainer;
+ this.groupId = groupId;
+ this.initLevel = initLevel;
+ this.maxIdleTime = maxIdleTime;
+ this.maxAge = maxAge;
+ }
+
+ public boolean isEagerInit() {
+ return initLevel > 0;
+ }
+
+ public int getInitLevel() {
+ return initLevel;
+ }
+
+ public long getMaxIdleTime() {
+ return maxIdleTime;
+ }
+
+ public long getMaxAge() {
+ return maxAge;
+ }
+
+ public void attachWire(Wire wire) {
+ }
+
+ public void attachWires(List<Wire> wires) {
+ }
+
+ public void attachCallbackWire(Wire wire) {
+ }
+
+ public void start() {
+ super.start();
+ scopeContainer.register(this, groupId);
+ instanceFactory = provider.createFactory();
+ }
+
+ public void stop() {
+ instanceFactory = null;
+ scopeContainer.unregister(this);
+ super.stop();
+ }
+
+ public InstanceWrapper<T> createInstanceWrapper() {
+ return instanceFactory.newInstance();
+ }
+
+ public ObjectFactory<T> createObjectFactory() {
+ return new ComponentObjectFactory(this, scopeContainer);
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, PhysicalOperationDefinition operation)
+ throws TargetInvokerCreationException {
+ return null;
+ }
+
+ public ComponentContext getComponentContext() {
+ return null;
+ }
+
+ public List<Wire> getWires(String name) {
+ return null;
+ }
+
+ public Map<String, PropertyValue<?>> getDefaultPropertyValues() {
+ return null;
+ }
+
+ public void setDefaultPropertyValues(Map<String, PropertyValue<?>> defaultPropertyValues) {
+ }
+
+ public ScopeContainer getScopeContainer() {
+ return scopeContainer;
+ }
+
+ public Class<T> getImplementationClass() {
+ return provider.getImplementationClass();
+ }
+
+ public void setObjectFactory(InjectionSource name, ObjectFactory<?> objectFactory) {
+ provider.setObjectFactory(name, objectFactory);
+ }
+
+ public Class<?> getMemberType(InjectionSource injectionSite) {
+ return provider.getMemberType(injectionSite);
+ }
+
+ @Deprecated
+ public Object createInstance() throws ObjectCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ public void removeInstance() throws ComponentException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ public Object getTargetInstance() throws TargetResolutionException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ public Scope getScope() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ public void setScopeContainer(ScopeContainer scopeContainer) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ public boolean isOptimizable() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ public void register(Service service) throws RegistrationException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ public void register(Reference reference) throws RegistrationException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ public Service getService(String name) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ public Reference getReference(String name) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Deprecated
+ public TargetInvoker createTargetInvoker(String targetName, Operation operation)
+ throws TargetInvokerCreationException {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PojoComponentContextFactory.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PojoComponentContextFactory.java
new file mode 100644
index 0000000000..880802e086
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PojoComponentContextFactory.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.core.implementation;
+
+import org.osoa.sca.ComponentContext;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.ObjectCreationException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PojoComponentContextFactory implements ObjectFactory<ComponentContext> {
+ private final PojoAtomicComponent component;
+
+
+ public PojoComponentContextFactory(PojoAtomicComponent component) {
+ this.component = component;
+ }
+
+
+ public ComponentContext getInstance() throws ObjectCreationException {
+ return component.getComponentContext();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PojoConfiguration.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PojoConfiguration.java
new file mode 100644
index 0000000000..62a917fb67
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PojoConfiguration.java
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.implementation;
+
+import java.lang.reflect.Member;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.wire.ProxyService;
+
+import org.apache.tuscany.core.injection.EventInvoker;
+import org.apache.tuscany.core.injection.Injector;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.component.InstanceFactory;
+
+/**
+ * Encapsulates confuration for a Java-based atomic component
+ *
+ * @version $Rev$ $Date$
+ */
+public class PojoConfiguration {
+ private URI name;
+ private InstanceFactory<?> instanceFactory2;
+ private PojoObjectFactory<?> instanceFactory;
+ private List<String> constructorParamNames = new ArrayList<String>();
+ private List<Class<?>> constructorParamTypes = new ArrayList<Class<?>>();
+ private int initLevel;
+ private EventInvoker<Object> initInvoker;
+ private EventInvoker<Object> destroyInvoker;
+ private List<Injector> propertyInjectors = new ArrayList<Injector>();
+ private Map<String, Member> referenceSites = new HashMap<String, Member>();
+ private Map<String, Member> propertySites = new HashMap<String, Member>();
+ private Map<String, Member> resourceSites = new HashMap<String, Member>();
+ private Map<String, Member> callbackSites = new HashMap<String, Member>();
+ private ProxyService proxyService;
+ private WorkContext workContext;
+ private long maxIdleTime = -1;
+ private long maxAge = -1;
+ private Class implementationClass;
+ private URI groupId;
+
+ public URI getName() {
+ return name;
+ }
+
+ public void setName(URI name) {
+ this.name = name;
+ }
+
+ @Deprecated
+ public PojoObjectFactory<?> getInstanceFactory() {
+ return instanceFactory;
+ }
+
+ @Deprecated
+ public void setInstanceFactory(PojoObjectFactory<?> objectFactory) {
+ this.instanceFactory = objectFactory;
+ }
+
+ public InstanceFactory<?> getInstanceFactory2() {
+ return instanceFactory2;
+ }
+
+ public void setInstanceFactory2(InstanceFactory<?> instanceFactory2) {
+ this.instanceFactory2 = instanceFactory2;
+ }
+
+ public List<String> getConstructorParamNames() {
+ return constructorParamNames;
+ }
+
+ public void setConstructorParamNames(List<String> names) {
+ constructorParamNames = names;
+ }
+
+ public void addConstructorParamName(String name) {
+ constructorParamNames.add(name);
+ }
+
+ public List<Class<?>> getConstructorParamTypes() {
+ return constructorParamTypes;
+ }
+
+ public void setConstructorParamTypes(List<Class<?>> constructorParamTypes) {
+ this.constructorParamTypes = constructorParamTypes;
+ }
+
+ public void addConstructorParamType(Class<?> type) {
+ constructorParamTypes.add(type);
+ }
+
+ public URI getGroupId() {
+ return groupId;
+ }
+
+ public void setGroupId(URI groupId) {
+ this.groupId = groupId;
+ }
+
+ public int getInitLevel() {
+ return initLevel;
+ }
+
+ public void setInitLevel(int initLevel) {
+ this.initLevel = initLevel;
+ }
+
+ public long getMaxIdleTime() {
+ return maxIdleTime;
+ }
+
+ public void setMaxIdleTime(long maxIdleTime) {
+ this.maxIdleTime = maxIdleTime;
+ }
+
+ public long getMaxAge() {
+ return maxAge;
+ }
+
+ public void setMaxAge(long maxAge) {
+ this.maxAge = maxAge;
+ }
+
+ public EventInvoker<Object> getInitInvoker() {
+ return initInvoker;
+ }
+
+ public void setInitInvoker(EventInvoker<Object> initInvoker) {
+ this.initInvoker = initInvoker;
+ }
+
+ public EventInvoker<Object> getDestroyInvoker() {
+ return destroyInvoker;
+ }
+
+ public void setDestroyInvoker(EventInvoker<Object> destroyInvoker) {
+ this.destroyInvoker = destroyInvoker;
+ }
+
+ public List<Injector> getPropertyInjectors() {
+ return propertyInjectors;
+ }
+
+ public void addPropertyInjector(Injector injector) {
+ propertyInjectors.add(injector);
+ }
+
+ public Map<String, Member> getReferenceSite() {
+ return referenceSites;
+ }
+
+ public void addReferenceSite(String name, Member member) {
+ referenceSites.put(name, member);
+ }
+
+ public Map<String, Member> getResourceSites() {
+ return resourceSites;
+ }
+
+ public void addResourceSite(String name, Member member) {
+ resourceSites.put(name, member);
+ }
+
+ public Map<String, Member> getCallbackSites() {
+ return callbackSites;
+ }
+
+ public void addCallbackSite(String name, Member member) {
+ callbackSites.put(name, member);
+ }
+
+ public Map<String, Member> getPropertySites() {
+ return propertySites;
+ }
+
+ public void addPropertySite(String name, Member member) {
+ propertySites.put(name, member);
+ }
+
+ public ProxyService getProxyService() {
+ return proxyService;
+ }
+
+ public void setProxyService(ProxyService proxyService) {
+ this.proxyService = proxyService;
+ }
+
+ public WorkContext getWorkContext() {
+ return workContext;
+ }
+
+ public void setWorkContext(WorkContext workContext) {
+ this.workContext = workContext;
+ }
+
+ public Class getImplementationClass() {
+ return implementationClass;
+ }
+
+ public void setImplementationClass(Class implementationClass) {
+ this.implementationClass = implementationClass;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PojoWorkContextTunnel.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PojoWorkContextTunnel.java
new file mode 100644
index 0000000000..cef6675f05
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/PojoWorkContextTunnel.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.core.implementation;
+
+import org.apache.tuscany.spi.component.WorkContext;
+
+/**
+ * Class for tunneling a WorkContext through the invocation of a user class.
+ *
+ * @version $Rev$ $Date$
+ */
+public final class PojoWorkContextTunnel {
+ private PojoWorkContextTunnel() {
+ }
+
+ private static final ThreadLocal<WorkContext> CONTEXT = new ThreadLocal<WorkContext>();
+
+ /**
+ * 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:
+ * <pre>
+ * WorkContext old = PojoWorkContextTunnel.setThreadWorkContext(newContext);
+ * try {
+ * ... invoke user code ...
+ * } finally {
+ * PojoWorkContextTunnel.setThreadWorkContext(old);
+ * }
+ * </pre>
+ * @param context
+ * @return the current work context for the thread; this must be restored after the invocation is made
+ */
+ public static WorkContext setThreadWorkContext(WorkContext context) {
+ WorkContext old = CONTEXT.get();
+ CONTEXT.set(context);
+ return old;
+ }
+
+ /**
+ * Returns the WorkContext for the current thread.
+ *
+ * @return the WorkContext for the current thread
+ */
+ public static WorkContext getThreadWorkContext() {
+ return CONTEXT.get();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeBuilder.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeBuilder.java
new file mode 100644
index 0000000000..d12b407ea7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeBuilder.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.core.implementation.composite;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.builder.BuilderInstantiationException;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.RegistrationException;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentBuilderExtension;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+/**
+ * Abstract builder for composites
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractCompositeBuilder<T extends Implementation<CompositeComponentType>>
+ extends ComponentBuilderExtension<T> {
+
+ public Component build(
+ Component component,
+ CompositeComponentType<?, ?, ?> componentType,
+ DeploymentContext deploymentContext) throws BuilderException {
+ for (ComponentDefinition<? extends Implementation<?>> definition : componentType.getComponents().values()) {
+ builderRegistry.build(definition, deploymentContext);
+ }
+ for (ServiceDefinition definition : componentType.getServices().values()) {
+ try {
+ Service service = builderRegistry.build(definition, deploymentContext);
+ component.register(service);
+ } catch (RegistrationException e) {
+ throw new BuilderInstantiationException("Error registering service", e);
+ }
+ }
+ for (ReferenceDefinition definition : componentType.getReferences().values()) {
+ try {
+ Reference reference = builderRegistry.build(definition, deploymentContext);
+ component.register(reference);
+ } catch (RegistrationException e) {
+ throw new BuilderInstantiationException("Error registering reference", e);
+ }
+ }
+ return component;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ComponentTimeoutException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ComponentTimeoutException.java
new file mode 100644
index 0000000000..ed64cb1236
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ComponentTimeoutException.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.core.implementation.composite;
+
+import org.apache.tuscany.spi.component.ComponentRuntimeException;
+
+/**
+ * Denotes a condition where a component times out waiting to perform an operation
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentTimeoutException extends ComponentRuntimeException {
+
+ public ComponentTimeoutException(String message) {
+ super(message);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeBuilder.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeBuilder.java
new file mode 100644
index 0000000000..51d360ec39
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeBuilder.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.core.implementation.composite;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+
+/**
+ * Instantiates a composite component from an assembly definition
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeBuilder extends AbstractCompositeBuilder<CompositeImplementation> {
+
+ public Component build(ComponentDefinition<CompositeImplementation> componentDefinition,
+ DeploymentContext deploymentContext) throws BuilderException {
+
+ CompositeImplementation implementation = componentDefinition.getImplementation();
+ CompositeComponentType<?, ?, ?> componentType = implementation.getComponentType();
+ URI name = componentDefinition.getUri();
+ CompositeComponentImpl component = new CompositeComponentImpl(name);
+
+ return build(component, componentType, deploymentContext);
+ }
+
+ protected Class<CompositeImplementation> getImplementationType() {
+ return CompositeImplementation.class;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImpl.java
new file mode 100644
index 0000000000..8df05048c8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImpl.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.core.implementation.composite;
+
+import java.net.URI;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.tuscany.spi.event.Event;
+import org.apache.tuscany.spi.extension.CompositeComponentExtension;
+import org.apache.tuscany.spi.wire.Wire;
+
+import org.apache.tuscany.core.component.event.ComponentStop;
+
+/**
+ * The standard implementation of a composite component. Autowiring is performed by delegating to the parent composite.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeComponentImpl extends CompositeComponentExtension {
+ public static final int DEFAULT_WAIT = 1000 * 60;
+ // Blocking latch to ensure the composite is initialized exactly once prior to servicing requests
+ protected CountDownLatch initializeLatch = new CountDownLatch(1);
+ protected final Object lock = new Object();
+ // Indicates whether the composite context has been initialized
+ protected boolean initialized;
+
+ /**
+ * Constructor
+ *
+ * @param name the name of this Component
+ */
+ public CompositeComponentImpl(URI name) {
+ super(name);
+ }
+
+ public void attachWire(Wire wire) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void attachWires(List<Wire> wires) {
+ throw new UnsupportedOperationException();
+ }
+
+ public List<Wire> getWires(String name) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void attachCallbackWire(Wire wire) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void start() {
+ synchronized (lock) {
+ if (lifecycleState != UNINITIALIZED && lifecycleState != STOPPED) {
+ throw new IllegalStateException("Composite not in UNINITIALIZED state");
+ }
+ initializeLatch.countDown();
+ initialized = true;
+ lifecycleState = INITIALIZED;
+ }
+ }
+
+ public void stop() {
+ if (lifecycleState == STOPPED) {
+ return;
+ }
+
+ publish(new ComponentStop(this, getUri()));
+ // need to block a start until reset is complete
+ initializeLatch = new CountDownLatch(2);
+ lifecycleState = STOPPING;
+ initialized = false;
+ // allow initialized to be called
+ initializeLatch.countDown();
+ lifecycleState = STOPPED;
+ }
+
+ public void publish(Event event) {
+ if (lifecycleState == STOPPED) {
+ return;
+ }
+ checkInit();
+ super.publish(event);
+ }
+
+ /**
+ * Blocks until the composite context has been initialized
+ */
+ protected void checkInit() throws ComponentTimeoutException {
+ if (!initialized) {
+ try {
+ /* block until the composite has initialized */
+ boolean success = initializeLatch.await(DEFAULT_WAIT, TimeUnit.MILLISECONDS);
+ if (!success) {
+ throw new ComponentTimeoutException("Timeout waiting for context to initialize");
+ }
+ } catch (InterruptedException e) { // should not happen
+ }
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeComponentTypeLoader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeComponentTypeLoader.java
new file mode 100644
index 0000000000..6cb31a8e20
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeComponentTypeLoader.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.core.implementation.composite;
+
+import java.net.URI;
+import java.net.URL;
+
+import org.apache.tuscany.spi.deployer.CompositeClassLoader;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentTypeLoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+
+import org.apache.tuscany.core.deployer.ChildDeploymentContext;
+
+/**
+ * Loads a composite component type
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeComponentTypeLoader extends ComponentTypeLoaderExtension<CompositeImplementation> {
+ public CompositeComponentTypeLoader() {
+ }
+
+ public CompositeComponentTypeLoader(LoaderRegistry loaderRegistry) {
+ super(loaderRegistry);
+ }
+
+ protected Class<CompositeImplementation> getImplementationClass() {
+ return CompositeImplementation.class;
+ }
+
+ public void load(CompositeImplementation implementation, DeploymentContext context) throws LoaderException {
+ URL scdlLocation = implementation.getScdlLocation();
+ ClassLoader cl = new CompositeClassLoader(null, implementation.getClassLoader());
+ URI componentId = URI.create(context.getComponentId().toString() + '/');
+ DeploymentContext childContext =
+ new ChildDeploymentContext(context, cl, scdlLocation, componentId, context.isAutowire());
+ CompositeComponentType componentType = loadFromSidefile(scdlLocation, childContext);
+ implementation.setComponentType(componentType);
+ }
+
+ protected CompositeComponentType loadFromSidefile(URL url, DeploymentContext deploymentContext)
+ throws LoaderException {
+ return loaderRegistry.load(null, url, CompositeComponentType.class, deploymentContext);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeLoader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeLoader.java
new file mode 100644
index 0000000000..af0a5a7a56
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/CompositeLoader.java
@@ -0,0 +1,251 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.implementation.composite;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+import javax.xml.namespace.QName;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.CompositeClassLoader;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.InvalidServiceException;
+import org.apache.tuscany.spi.loader.InvalidWireException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.MissingResourceException;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.Include;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.model.WireDefinition;
+import org.apache.tuscany.spi.services.artifact.Artifact;
+import org.apache.tuscany.spi.services.artifact.ArtifactRepository;
+
+import org.apache.tuscany.core.property.PropertyHelper;
+
+/**
+ * Loads a composite component definition from an XML-based assembly file
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeLoader extends LoaderExtension<CompositeComponentType> {
+ public static final QName COMPOSITE = new QName(SCA_NS, "composite");
+ public static final String URI_DELIMITER = "/";
+
+ private final ArtifactRepository artifactRepository;
+
+ public CompositeLoader(@Reference LoaderRegistry registry, @Reference ArtifactRepository artifactRepository) {
+ super(registry);
+ this.artifactRepository = artifactRepository;
+ }
+
+ public QName getXMLType() {
+ return COMPOSITE;
+ }
+
+ public CompositeComponentType load(
+ ModelObject object,
+ XMLStreamReader reader,
+ DeploymentContext deploymentContext) throws XMLStreamException, LoaderException {
+
+ String name = reader.getAttributeValue(null, "name");
+ String targetNamespace = reader.getAttributeValue(null, "targetNamespace");
+ boolean autowire = Boolean.parseBoolean(reader.getAttributeValue(null, "autowire"));
+
+ CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>(
+ new QName(targetNamespace, name)
+ );
+ type.setAutowire(autowire);
+ boolean done = false;
+ while (!done) {
+ switch (reader.next()) {
+ case START_ELEMENT:
+ boolean oldAutowire = deploymentContext.isAutowire();
+ deploymentContext.setAutowire(autowire);
+ ModelObject o = registry.load(type, reader, deploymentContext);
+ deploymentContext.setAutowire(oldAutowire);
+ if (o instanceof ServiceDefinition) {
+ type.add((ServiceDefinition) o);
+ } else if (o instanceof ReferenceDefinition) {
+ type.add((ReferenceDefinition) o);
+ } else if (o instanceof Property<?>) {
+ type.add((Property<?>) o);
+ } else if (o instanceof ComponentDefinition<?>) {
+ type.add((ComponentDefinition<?>) o);
+ } else if (o instanceof Include) {
+ type.add((Include) o);
+ } else if (o instanceof Dependency) {
+ Artifact artifact = ((Dependency) o).getArtifact();
+ if (artifactRepository == null) {
+ throw new MissingResourceException("No ArtifactRepository configured for this system",
+ artifact.toString()
+ );
+ }
+
+ // default to jar type if not specified
+ if (artifact.getType() == null) {
+ artifact.setType("jar");
+ }
+ artifactRepository.resolve(artifact);
+ if (artifact.getUrl() == null) {
+ throw new MissingResourceException("Dependency not found", artifact.toString());
+ }
+
+ ClassLoader classLoader = deploymentContext.getClassLoader();
+ if (classLoader instanceof CompositeClassLoader) {
+ CompositeClassLoader ccl = (CompositeClassLoader) classLoader;
+ for (URL dep : artifact.getUrls()) {
+ ccl.addURL(dep);
+ }
+ }
+ } else if (o instanceof WireDefinition) {
+ type.add((WireDefinition) o);
+ } else {
+ // add as an unknown model extension
+ if (o != null) {
+ type.getExtensions().put(o.getClass(), o);
+ }
+ }
+ reader.next();
+ break;
+ case END_ELEMENT:
+ if (COMPOSITE.equals(reader.getName())) {
+ // if there are wire defintions then link them up to the relevant components
+ resolveWires(type);
+ verifyCompositeCompleteness(type);
+ done = true;
+ break;
+ }
+ }
+ }
+ for (ComponentDefinition<? extends Implementation<?>> c : type.getComponents().values()) {
+ PropertyHelper.processProperties(type, c, deploymentContext);
+ }
+ return type;
+ }
+
+ protected void resolveWires(CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> composite)
+ throws InvalidWireException {
+ ComponentDefinition componentDefinition;
+ ServiceDefinition serviceDefinition;
+ List<WireDefinition> wireDefns = composite.getDeclaredWires();
+ for (WireDefinition wire : wireDefns) {
+ URI targetUri = wire.getTarget();
+ // validate the target before finding the source
+ validateTarget(targetUri, composite);
+
+ String sourceName = wire.getSource().getPath(); //new QualifiedName(wire.getSource().getPath());
+ serviceDefinition = composite.getDeclaredServices().get(sourceName);
+ if (serviceDefinition != null) {
+ serviceDefinition.setTarget(wire.getTarget());
+ } else {
+ componentDefinition = composite.getDeclaredComponents().get(sourceName);
+ if (componentDefinition != null) {
+ if (wire.getSource().getFragment() == null) {
+ throw new InvalidWireException("Source reference not specified", sourceName);
+ }
+ URI referenceName = URI.create(wire.getSource().getFragment());
+ ReferenceTarget referenceTarget = createReferenceTarget(referenceName,
+ targetUri,
+ componentDefinition);
+ componentDefinition.add(referenceTarget);
+ } else {
+ throw new InvalidWireException("Source not found", sourceName);
+ }
+ }
+ }
+ }
+
+ private ReferenceTarget createReferenceTarget(URI componentReferenceName,
+ URI target,
+ ComponentDefinition componentDefn) throws InvalidWireException {
+ ComponentType componentType = componentDefn.getImplementation().getComponentType();
+ if (componentReferenceName == null) {
+ // if there is ambiguity in determining the source of the wire or there is no reference to be wired
+ if (componentType.getReferences().size() > 1 || componentType.getReferences().isEmpty()) {
+ throw new InvalidWireException("Unable to determine unique source reference");
+ } else {
+ Map references = componentType.getReferences();
+ ReferenceDefinition definition = (ReferenceDefinition) references.values().iterator().next();
+ componentReferenceName = definition.getUri();
+ }
+ }
+
+ ReferenceTarget referenceTarget = new ReferenceTarget();
+ referenceTarget.setReferenceName(componentReferenceName);
+ referenceTarget.addTarget(target);
+ return referenceTarget;
+ }
+
+ protected void verifyCompositeCompleteness(
+ CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> composite)
+ throws InvalidServiceException {
+ // check if all of the composite services have been wired
+ for (ServiceDefinition svcDefn : composite.getDeclaredServices().values()) {
+ if (svcDefn.getTarget() == null) {
+ String identifier = svcDefn.getUri().toString();
+ throw new InvalidServiceException("Composite service not wired to a target", identifier);
+ }
+ }
+ }
+
+ private void validateTarget(URI target,
+ CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> composite)
+ throws InvalidWireException {
+ // if target is not a reference of the composite
+ String targetName = target.getPath();
+ if (composite.getReferences().get(targetName) == null) {
+ ComponentDefinition<?> targetDefinition = composite.getDeclaredComponents().get(targetName);
+ // if a target component exists in this composite
+ if (targetDefinition != null) {
+ Implementation<?> implementation = targetDefinition.getImplementation();
+ ComponentType<?, ?, ?> componentType = implementation.getComponentType();
+ Map<String, ? extends ServiceDefinition> services = componentType.getServices();
+ if (target.getFragment() == null) {
+ if (services.size() > 1 || services.isEmpty()) {
+ throw new InvalidWireException("Ambiguous target", target.toString());
+ }
+ } else {
+ if (services.get(target.getFragment()) == null) {
+ throw new InvalidWireException("Invalid target service", target.toString());
+ }
+ }
+ } else {
+ throw new InvalidWireException("Target not found", target.toString());
+ }
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/Dependency.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/Dependency.java
new file mode 100644
index 0000000000..808f36072f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/Dependency.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.core.implementation.composite;
+
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.services.artifact.Artifact;
+
+/**
+ * A model object that represents a dependency on an external artifact.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Dependency extends ModelObject {
+ private Artifact artifact;
+
+ public Artifact getArtifact() {
+ return artifact;
+ }
+
+ public void setArtifact(Artifact artifact) {
+ this.artifact = artifact;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ImplementationCompositeLoader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ImplementationCompositeLoader.java
new file mode 100644
index 0000000000..09fdee105e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ImplementationCompositeLoader.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.core.implementation.composite;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Set;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.osoa.sca.Constants;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.CompositeClassLoader;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.InvalidValueException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.LoaderUtil;
+import org.apache.tuscany.spi.loader.MissingResourceException;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.services.artifact.Artifact;
+import org.apache.tuscany.spi.services.artifact.ArtifactRepository;
+
+/**
+ * Loader that handles an &lt;implementation.composite&gt; element.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ImplementationCompositeLoader extends LoaderExtension<CompositeImplementation> {
+ private static final QName IMPLEMENTATION_COMPOSITE =
+ new QName(Constants.SCA_NS, "implementation.composite");
+
+ private final ArtifactRepository artifactRepository;
+
+ public ImplementationCompositeLoader(@Reference LoaderRegistry registry,
+ @Reference ArtifactRepository artifactRepository) {
+ super(registry);
+ this.artifactRepository = artifactRepository;
+ }
+
+ public QName getXMLType() {
+ return IMPLEMENTATION_COMPOSITE;
+ }
+
+ public CompositeImplementation load(
+ ModelObject object, XMLStreamReader reader,
+ DeploymentContext deploymentContext)
+ throws XMLStreamException, LoaderException {
+
+ assert IMPLEMENTATION_COMPOSITE.equals(reader.getName());
+ String name = reader.getAttributeValue(null, "name");
+ String group = reader.getAttributeValue(null, "group");
+ String version = reader.getAttributeValue(null, "version");
+ String scdlLocation = reader.getAttributeValue(null, "scdlLocation");
+ String jarLocation = reader.getAttributeValue(null, "jarLocation");
+ LoaderUtil.skipToEndElement(reader);
+
+ CompositeImplementation impl = new CompositeImplementation();
+ impl.setName(name);
+ if (scdlLocation != null) {
+ try {
+ impl.setScdlLocation(new URL(deploymentContext.getScdlLocation(), scdlLocation));
+ } catch (MalformedURLException e) {
+ throw new InvalidValueException(scdlLocation, name, e);
+ }
+ impl.setClassLoader(deploymentContext.getClassLoader());
+ } else if (jarLocation != null) {
+ URL jarUrl;
+ try {
+ jarUrl = new URL(deploymentContext.getScdlLocation(), jarLocation);
+ } catch (MalformedURLException e) {
+ throw new InvalidValueException(jarLocation, name, e);
+ }
+ try {
+ impl.setScdlLocation(new URL("jar:" + jarUrl.toExternalForm() + "!/META-INF/sca/default.scdl"));
+ } catch (MalformedURLException e) {
+ throw new AssertionError("Could not convert URL to a jar: url");
+ }
+ impl.setClassLoader(new CompositeClassLoader(null, new URL[]{jarUrl}, deploymentContext.getClassLoader()));
+ } else if (artifactRepository != null && group != null && version != null) {
+ Artifact artifact = new Artifact();
+ artifact.setGroup(group);
+ artifact.setName(name);
+ artifact.setVersion(version);
+ artifact.setType("jar");
+ artifactRepository.resolve(artifact);
+ if (artifact.getUrl() == null) {
+ throw new MissingResourceException(artifact.toString(), name);
+ }
+ try {
+ impl.setScdlLocation(new URL("jar:" + artifact.getUrl() + "!/META-INF/sca/default.scdl"));
+ } catch (MalformedURLException e) {
+ throw new AssertionError(e);
+ }
+ Set<URL> artifactURLs = artifact.getUrls();
+ URL[] urls = new URL[artifactURLs.size()];
+ int i = 0;
+ for (URL artifactURL : artifactURLs) {
+ urls[i++] = artifactURL;
+ }
+ impl.setClassLoader(new CompositeClassLoader(null, urls, deploymentContext.getClassLoader()));
+ }
+ return impl;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ManagedRequestContext.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ManagedRequestContext.java
new file mode 100644
index 0000000000..f2a8109ee3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ManagedRequestContext.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.core.implementation.composite;
+
+import javax.security.auth.Subject;
+
+import org.osoa.sca.RequestContext;
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.CallableReference;
+
+import org.apache.tuscany.spi.component.WorkContext;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ManagedRequestContext implements RequestContext {
+ private WorkContext workContext;
+
+ public ManagedRequestContext(WorkContext workContext) {
+ this.workContext = workContext;
+ }
+
+ public Subject getSecuritySubject() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getServiceName() {
+ return workContext.getCurrentServiceName();
+ }
+
+ public <B> ServiceReference<B> getServiceReference() {
+ throw new UnsupportedOperationException();
+ }
+
+ public <CB> CB getCallback() {
+ throw new UnsupportedOperationException();
+ }
+
+ public <CB> CallableReference<CB> getCallbackReference() {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ReferenceImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ReferenceImpl.java
new file mode 100644
index 0000000000..f824980f29
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ReferenceImpl.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.core.implementation.composite;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.tuscany.spi.component.AbstractSCAObject;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+/**
+ * The default implementation of a {@link org.apache.tuscany.spi.component.Reference}
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReferenceImpl extends AbstractSCAObject implements Reference {
+ private ServiceContract<?> serviceContract;
+ private List<ReferenceBinding> bindings = new ArrayList<ReferenceBinding>();
+
+ public ReferenceImpl(URI name, ServiceContract<?> contract) {
+ super(name);
+ this.serviceContract = contract;
+ }
+
+ public ServiceContract<?> getServiceContract() {
+ return serviceContract;
+ }
+
+ public List<ReferenceBinding> getReferenceBindings() {
+ return Collections.unmodifiableList(bindings);
+ }
+
+ public void addReferenceBinding(ReferenceBinding binding) {
+ bindings.add(binding);
+ }
+
+ public void start() {
+ super.start();
+ for (ReferenceBinding binding : bindings) {
+ binding.start();
+ }
+ }
+
+ public void stop() {
+ super.stop();
+ for (ReferenceBinding binding : bindings) {
+ binding.stop();
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ServiceImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ServiceImpl.java
new file mode 100644
index 0000000000..b8b9b00b49
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/ServiceImpl.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.core.implementation.composite;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.tuscany.spi.component.AbstractSCAObject;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+/**
+ * The default implementation of a {@link Service}
+ *
+ * @version $Rev$ $Date$
+ */
+public class ServiceImpl extends AbstractSCAObject implements Service {
+ private ServiceContract<?> serviceContract;
+ private List<ServiceBinding> bindings = new ArrayList<ServiceBinding>();
+ private URI targetUri;
+
+ public ServiceImpl(URI name, ServiceContract<?> contract) {
+ this(name, contract, null);
+ }
+
+ public ServiceImpl(URI name, ServiceContract<?> contract, URI targetUri) {
+ super(name);
+ this.serviceContract = contract;
+ this.targetUri = targetUri;
+ }
+
+ public ServiceContract<?> getServiceContract() {
+ return serviceContract;
+ }
+
+ public URI getTargetUri() {
+ return targetUri;
+ }
+
+ public List<ServiceBinding> getServiceBindings() {
+ return Collections.unmodifiableList(bindings);
+ }
+
+ public void addServiceBinding(ServiceBinding binding) {
+ bindings.add(binding);
+ }
+
+ public void start() {
+ super.start();
+ for (ServiceBinding binding : bindings) {
+ binding.start();
+ }
+ }
+
+ public void stop() {
+ super.stop();
+ for (ServiceBinding binding : bindings) {
+ binding.stop();
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/SystemCompositeBuilder.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/SystemCompositeBuilder.java
new file mode 100644
index 0000000000..531f610bf9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/SystemCompositeBuilder.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.core.implementation.composite;
+
+import java.net.URI;
+
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.builder.BuilderRegistry;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+
+import org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation;
+
+/**
+ * Produces system composite components by evaluating an assembly.
+ *
+ * @version $Rev$ $Date$
+ */
+public class SystemCompositeBuilder extends AbstractCompositeBuilder<SystemCompositeImplementation> {
+
+ @Constructor
+ public SystemCompositeBuilder(@Reference BuilderRegistry builderRegistry) {
+ this.builderRegistry = builderRegistry;
+ }
+
+ public Component build(ComponentDefinition<SystemCompositeImplementation> componentDefinition,
+ DeploymentContext context) throws BuilderException {
+ SystemCompositeImplementation impl = componentDefinition.getImplementation();
+ CompositeComponentType<?, ?, ?> componentType = impl.getComponentType();
+ URI name = componentDefinition.getUri();
+ Component component = new CompositeComponentImpl(name);
+ build(component, componentType, context);
+ return component;
+ }
+
+ protected Class<SystemCompositeImplementation> getImplementationType() {
+ return SystemCompositeImplementation.class;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponent.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponent.java
new file mode 100644
index 0000000000..8da671a165
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponent.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.core.implementation.java;
+
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.idl.java.JavaIDLUtils;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+import org.apache.tuscany.core.implementation.PojoAtomicComponent;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.wire.WireObjectFactory;
+
+/**
+ * The runtime instantiation of Java component implementations
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaAtomicComponent extends PojoAtomicComponent {
+
+ public JavaAtomicComponent(PojoConfiguration configuration) {
+ super(configuration);
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, Operation operation)
+ throws TargetInvokerCreationException {
+
+ Class<?> implClass;
+ if (operation.isCallback()) {
+ implClass = operation.getServiceContract().getCallbackClass();
+ } else {
+ implClass = implementationClass;
+ }
+ try {
+ Method method = JavaIDLUtils.findMethod(implClass, operation);
+ return new JavaTargetInvoker(method, this, scopeContainer);
+ } catch (NoSuchMethodException e) {
+ throw new TargetMethodNotFoundException(operation);
+ }
+
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, PhysicalOperationDefinition operation)
+ throws TargetInvokerCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ protected <B> ObjectFactory<B> createWireFactory(Class<B> interfaze, Wire wire) {
+ return new WireObjectFactory<B>(interfaze, wire, proxyService);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaComponent.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaComponent.java
new file mode 100644
index 0000000000..c735197f9a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaComponent.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.core.implementation.java;
+
+import java.net.URI;
+
+import org.apache.tuscany.core.component.InstanceFactoryProvider;
+import org.apache.tuscany.core.implementation.PojoComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+
+/**
+ * @version $Revision$ $Date$
+ * @param <T> the implementation class for the defined component
+ */
+public class JavaComponent<T> extends PojoComponent<T> {
+ public JavaComponent(URI componentId,
+ InstanceFactoryProvider<T> instanceFactoryProvider,
+ ScopeContainer<?> scopeContainer,
+ URI groupId,
+ int initLevel,
+ long maxIdleTime,
+ long maxAge) {
+ super(componentId, instanceFactoryProvider, scopeContainer, groupId, initLevel, maxIdleTime, maxAge);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilder.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilder.java
new file mode 100644
index 0000000000..341dedae72
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilder.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.core.implementation.java;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.builder.BuilderConfigException;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentBuilderExtension;
+import org.apache.tuscany.spi.host.ResourceHost;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.Resource;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.PropertyValue;
+
+import org.apache.tuscany.core.implementation.PojoComponentContextFactory;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.injection.MethodEventInvoker;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.injection.ResourceObjectFactory;
+
+/**
+ * Builds a Java-based atomic context from a component definition
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class JavaComponentBuilder extends ComponentBuilderExtension<JavaImplementation> {
+
+ private ResourceHost host;
+
+ @Reference
+ public void setHost(ResourceHost host) {
+ this.host = host;
+ }
+
+ @SuppressWarnings("unchecked")
+ public AtomicComponent build(ComponentDefinition<JavaImplementation> definition, DeploymentContext context)
+ throws BuilderConfigException {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> componentType =
+ definition.getImplementation().getComponentType();
+
+ PojoConfiguration configuration = new PojoConfiguration();
+ if (definition.getInitLevel() != null) {
+ configuration.setInitLevel(definition.getInitLevel());
+ } else {
+ configuration.setInitLevel(componentType.getInitLevel());
+ }
+ if (componentType.getMaxAge() > 0) {
+ configuration.setMaxAge(componentType.getMaxAge());
+ } else if (componentType.getMaxIdleTime() > 0) {
+ configuration.setMaxIdleTime(componentType.getMaxIdleTime());
+ }
+ Method initMethod = componentType.getInitMethod();
+ if (initMethod != null) {
+ configuration.setInitInvoker(new MethodEventInvoker(initMethod));
+ }
+ Method destroyMethod = componentType.getDestroyMethod();
+ if (destroyMethod != null) {
+ configuration.setDestroyInvoker(new MethodEventInvoker(destroyMethod));
+ }
+
+ configuration.setGroupId(context.getGroupId());
+ configuration.setProxyService(proxyService);
+ configuration.setWorkContext(workContext);
+ configuration.setImplementationClass(definition.getImplementation().getImplementationClass());
+
+ // setup property injection sites
+ for (JavaMappedProperty<?> property : componentType.getProperties().values()) {
+ configuration.addPropertySite(property.getName(), property.getMember());
+ }
+
+ // setup reference injection sites
+ for (JavaMappedReference reference : componentType.getReferences().values()) {
+ Member member = reference.getMember();
+ if (member != null) {
+ // could be null if the reference is mapped to a constructor
+ configuration.addReferenceSite(reference.getUri().getFragment(), member);
+ }
+ }
+
+ for (Resource resource : componentType.getResources().values()) {
+ Member member = resource.getMember();
+ if (member != null) {
+ // could be null if the resource is mapped to a constructor
+ configuration.addResourceSite(resource.getName(), member);
+ }
+ }
+
+ // setup constructor injection
+ ConstructorDefinition<?> ctorDef = componentType.getConstructorDefinition();
+ Constructor<?> constr = ctorDef.getConstructor();
+ PojoObjectFactory<?> instanceFactory = new PojoObjectFactory(constr);
+ configuration.setInstanceFactory(instanceFactory);
+ configuration.getConstructorParamNames().addAll(ctorDef.getInjectionNames());
+ for (Class<?> clazz : constr.getParameterTypes()) {
+ configuration.addConstructorParamType(clazz);
+ }
+ configuration.setName(definition.getUri());
+ handleCallbackSites(componentType, configuration);
+
+ JavaAtomicComponent component = new JavaAtomicComponent(configuration);
+
+ // handle properties
+ handleProperties(definition, component);
+
+ // handle resources
+ handleResources(componentType, component);
+
+ if (componentType.getConversationIDMember() != null) {
+ component.addConversationIDFactory(componentType.getConversationIDMember());
+ }
+
+ return component;
+ }
+
+ private void handleCallbackSites(
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> componentType,
+ PojoConfiguration configuration) {
+ for (JavaMappedService service : componentType.getServices().values()) {
+ // setup callback injection sites
+ String name = service.getServiceContract().getCallbackName();
+ if (name != null) {
+ // Only if there is a callback reference in the service
+ configuration.addCallbackSite(name, service.getCallbackMember());
+ }
+ }
+ }
+
+ private void handleResources(
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> componentType,
+ JavaAtomicComponent component) {
+ for (Resource<?> resource : componentType.getResources().values()) {
+ String name = resource.getName();
+ ObjectFactory<?> objectFactory = resource.getObjectFactory();
+ if (objectFactory == null) {
+ Class<?> type = resource.getType();
+ if (ComponentContext.class.equals(type)) {
+ objectFactory = new PojoComponentContextFactory(component);
+ } else {
+ boolean optional = resource.isOptional();
+ String mappedName = resource.getMappedName();
+ objectFactory = createResourceObjectFactory(type, mappedName, optional, host);
+ }
+ }
+ component.addResourceFactory(name, objectFactory);
+ }
+ }
+
+ private <T> ResourceObjectFactory<T> createResourceObjectFactory(Class<T> type,
+ String mappedName,
+ boolean optional,
+ ResourceHost host) {
+ return new ResourceObjectFactory<T>(type, mappedName, optional, host);
+ }
+
+ private void handleProperties(ComponentDefinition<JavaImplementation> definition, JavaAtomicComponent component) {
+ for (PropertyValue<?> property : definition.getPropertyValues().values()) {
+ ObjectFactory<?> factory = property.getValueFactory();
+ if (factory != null) {
+ component.addPropertyFactory(property.getName(), factory);
+ }
+ }
+ }
+
+ protected Class<JavaImplementation> getImplementationType() {
+ return JavaImplementation.class;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaComponentTypeLoader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaComponentTypeLoader.java
new file mode 100644
index 0000000000..c4234596f8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaComponentTypeLoader.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.core.implementation.java;
+
+import java.net.URL;
+
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentTypeLoaderExtension;
+import org.apache.tuscany.spi.implementation.java.IntrospectionRegistry;
+import org.apache.tuscany.spi.implementation.java.Introspector;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+
+import org.apache.tuscany.core.util.JavaIntrospectionHelper;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaComponentTypeLoader extends ComponentTypeLoaderExtension<JavaImplementation> {
+ private Introspector introspector;
+
+ @Constructor({"registry", "introspector"})
+ public JavaComponentTypeLoader(@Reference LoaderRegistry loaderRegistry,
+ @Reference IntrospectionRegistry introspector) {
+ super(loaderRegistry);
+ this.introspector = introspector;
+ }
+
+ @Override
+ protected Class<JavaImplementation> getImplementationClass() {
+ return JavaImplementation.class;
+ }
+
+ public void load(
+ JavaImplementation implementation,
+ DeploymentContext deploymentContext) throws LoaderException {
+ Class<?> implClass = implementation.getImplementationClass();
+ URL resource = implClass.getResource(JavaIntrospectionHelper.getBaseName(implClass) + ".componentType");
+ PojoComponentType componentType;
+ if (resource == null) {
+ componentType = loadByIntrospection(implementation, deploymentContext);
+ } else {
+ componentType = loadFromSidefile(resource, deploymentContext);
+ }
+ implementation.setComponentType(componentType);
+ }
+
+ protected PojoComponentType loadByIntrospection(JavaImplementation implementation, DeploymentContext context)
+ throws ProcessingException {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> componentType =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Class<?> implClass = implementation.getImplementationClass();
+ introspector.introspect(implClass, componentType, context);
+ return componentType;
+ }
+
+ protected PojoComponentType loadFromSidefile(URL url, DeploymentContext deploymentContext) throws LoaderException {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> componentType =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ return loaderRegistry.load(componentType, url, PojoComponentType.class, deploymentContext);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaImplementation.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaImplementation.java
new file mode 100644
index 0000000000..432bf31d63
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaImplementation.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.core.implementation.java;
+
+import org.apache.tuscany.spi.model.AtomicImplementation;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public class JavaImplementation extends AtomicImplementation<PojoComponentType> {
+ private String className;
+ private Class<?> implementationClass;
+
+ public JavaImplementation() {
+ }
+
+ public JavaImplementation(Class<?> implementationClass) {
+ this.implementationClass = implementationClass;
+ this.className = implementationClass.getName();
+ }
+
+ public JavaImplementation(Class<?> implementationClass, PojoComponentType componentType) {
+ super(componentType);
+ this.implementationClass = implementationClass;
+ this.className = implementationClass == null ? null : implementationClass.getName();
+ }
+
+ public String getClassName() {
+ return className;
+ }
+
+ public void setClassName(String className) {
+ this.className = className;
+ this.implementationClass = null;
+ }
+
+ public Class<?> getImplementationClass() {
+ return implementationClass;
+ }
+
+ public void setImplementationClass(Class<?> implementationClass) {
+ this.implementationClass = implementationClass;
+ this.className = implementationClass.getName();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaImplementationLoader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaImplementationLoader.java
new file mode 100644
index 0000000000..91f3852c0e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaImplementationLoader.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.core.implementation.java;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.LoaderUtil;
+import org.apache.tuscany.spi.model.ModelObject;
+
+public class JavaImplementationLoader extends LoaderExtension {
+ public static final QName IMPLEMENTATION_JAVA = new QName(SCA_NS, "implementation.java");
+
+ @Constructor
+ public JavaImplementationLoader(@Reference LoaderRegistry registry) {
+ super(registry);
+ }
+
+ @Override
+ public QName getXMLType() {
+ return IMPLEMENTATION_JAVA;
+ }
+
+ public ModelObject load(ModelObject object, XMLStreamReader reader,
+ DeploymentContext deploymentContext)
+ throws XMLStreamException, LoaderException {
+ assert IMPLEMENTATION_JAVA.equals(reader.getName());
+ String implClass = reader.getAttributeValue(null, "class");
+ Class<?> implementationClass = LoaderUtil.loadClass(implClass, deploymentContext.getClassLoader());
+
+ JavaImplementation implementation = new JavaImplementation();
+ implementation.setClassName(implClass);
+ implementation.setImplementationClass(implementationClass);
+ registry.loadComponentType(implementation, deploymentContext);
+ LoaderUtil.skipToEndElement(reader);
+ return implementation;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaInvokerInterceptor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaInvokerInterceptor.java
new file mode 100644
index 0000000000..14ec22e235
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaInvokerInterceptor.java
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ComponentException;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.InvalidConversationSequenceException;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+
+/**
+ * Responsible for dispatching an invocation to a Java component implementation instance.
+ *
+ * @version $Rev$ $Date$
+ * @param <T> the implementation class for the component being invoked
+ * @param <CONTEXT> the type of context id used by the ScopeContainer
+ */
+public class JavaInvokerInterceptor<T, CONTEXT> implements Interceptor {
+ /* indicates that no conversational sequence is associated with the message */
+ public final static short NONE = 0;
+ /* indicates that the message initiates a conversation */
+ public final static short START = 1;
+ /* indicates that the message continues a conversation */
+ public final static short CONTINUE = 2;
+ /* indicates that the message ends a conversation */
+ public final static short END = 3;
+
+ private Method operation;
+ private AtomicComponent<T> component;
+ private ScopeContainer<CONTEXT> scopeContainer;
+
+ /**
+ * Creates a new interceptor instance.
+ *
+ * @param operation the method to invoke on the target instance
+ * @param component the target component
+ * @param scopeContainer the ScopeContainer that manages implementation instances for the target component
+ */
+ public JavaInvokerInterceptor(Method operation,
+ AtomicComponent<T> component,
+ ScopeContainer<CONTEXT> scopeContainer
+ ) {
+ this.operation = operation;
+ this.component = component;
+ this.scopeContainer = scopeContainer;
+ }
+
+ public void setNext(Interceptor next) {
+ throw new IllegalStateException("This interceptor must be the last one in an target interceptor chain");
+ }
+
+ public Interceptor getNext() {
+ return null;
+ }
+
+ public boolean isOptimizable() {
+ return true;
+ }
+
+ public Message invoke(Message msg) {
+ try {
+ Object body = msg.getBody();
+ short sequence = msg.getConversationSequence();
+ WorkContext workContext = msg.getWorkContext();
+ Object resp = invokeTarget(body, sequence, workContext);
+ msg.setBody(resp);
+ } catch (InvocationTargetException e) {
+ msg.setBodyWithFault(e.getCause());
+ }
+ return msg;
+ }
+
+ private Object invokeTarget(final Object payload, final short sequence, final WorkContext workContext)
+ throws InvocationTargetException {
+ @SuppressWarnings("unchecked")
+ CONTEXT contextId = (CONTEXT) workContext.getIdentifier(scopeContainer.getScope());
+ try {
+ InstanceWrapper<T> wrapper = getInstance(sequence, contextId);
+ Object instance = wrapper.getInstance();
+ try {
+ return operation.invoke(instance, (Object[]) payload);
+ } finally {
+ scopeContainer.returnWrapper(component, wrapper, contextId);
+ if (sequence == END) {
+ // if end conversation, remove resource
+ scopeContainer.remove(component);
+ }
+ }
+ } catch (IllegalAccessException e) {
+ throw new InvocationTargetException(e);
+ } catch (ComponentException e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+
+ /**
+ * Resolves the target service instance or returns a cached one
+ *
+ * @param sequence the conversational sequence
+ * @param contextId the scope contextId
+ * @return the InstanceWrapper
+ * @throws TargetException if an exception getting the wrapper is encountered
+ */
+ private InstanceWrapper<T> getInstance(short sequence, CONTEXT contextId) throws TargetException {
+ switch (sequence) {
+ case NONE:
+ case START:
+ return scopeContainer.getWrapper(component, contextId);
+ case CONTINUE:
+ case END:
+ return scopeContainer.getAssociatedWrapper(component, contextId);
+ default:
+ throw new InvalidConversationSequenceException("Unknown sequence type", String.valueOf(sequence));
+ }
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaPhysicalComponentBuilder.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaPhysicalComponentBuilder.java
new file mode 100644
index 0000000000..78fd882ef9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaPhysicalComponentBuilder.java
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Service;
+
+import org.apache.tuscany.core.component.InstanceFactoryProvider;
+import org.apache.tuscany.core.component.instancefactory.IFProviderBuilderRegistry;
+import org.apache.tuscany.core.implementation.POJOPhysicalComponentBuilder;
+import org.apache.tuscany.core.injection.CallbackWireObjectFactory2;
+import org.apache.tuscany.core.model.physical.instancefactory.InjectionSource;
+import static org.apache.tuscany.core.model.physical.instancefactory.InjectionSource.ValueSourceType.CALLBACK;
+import static org.apache.tuscany.core.model.physical.instancefactory.InjectionSource.ValueSourceType.REFERENCE;
+import org.apache.tuscany.core.model.physical.java.JavaPhysicalComponentDefinition;
+import org.apache.tuscany.core.model.physical.java.JavaPhysicalWireSourceDefinition;
+import org.apache.tuscany.core.model.physical.java.JavaPhysicalWireTargetDefinition;
+import org.apache.tuscany.core.wire.WireObjectFactory2;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.builder.physical.PhysicalComponentBuilder;
+import org.apache.tuscany.spi.builder.physical.PhysicalComponentBuilderRegistry;
+import org.apache.tuscany.spi.builder.physical.WireAttachException;
+import org.apache.tuscany.spi.builder.physical.WireAttacher;
+import org.apache.tuscany.spi.builder.physical.WireAttacherRegistry;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.physical.InstanceFactoryProviderDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition;
+import org.apache.tuscany.spi.services.classloading.ClassLoaderRegistry;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.ProxyService;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * The physical component builder for Java implementation types. Responsible for creating the Component runtime artifact
+ * from a physical component definition
+ *
+ * @version $Rev$ $Date$
+ * @param <T> the implementation class for the defined component
+ */
+@EagerInit
+@Service(interfaces = {PhysicalComponentBuilder.class, WireAttacher.class})
+public class JavaPhysicalComponentBuilder<T>
+ extends POJOPhysicalComponentBuilder<JavaPhysicalComponentDefinition<T>, JavaComponent<T>>
+ implements WireAttacher<JavaComponent, JavaPhysicalWireSourceDefinition, JavaPhysicalWireTargetDefinition> {
+
+ private ProxyService proxyService;
+
+ public JavaPhysicalComponentBuilder(
+ @Reference(name = "builderRegistry")PhysicalComponentBuilderRegistry builderRegistry,
+ @Reference(name = "wireAttacherRegistry")WireAttacherRegistry wireAttacherRegistry,
+ @Reference(name = "scopeRegistry")ScopeRegistry scopeRegistry,
+ @Reference(name = "providerBuilders")IFProviderBuilderRegistry providerBuilders,
+ @Reference(name = "classloaderRegistry")ClassLoaderRegistry classLoaderRegistry) {
+ super(builderRegistry, wireAttacherRegistry, scopeRegistry, providerBuilders, classLoaderRegistry);
+ }
+
+ @Reference
+ public void setProxyService(ProxyService proxyService) {
+ this.proxyService = proxyService;
+ }
+
+ @Init
+ public void init() {
+ builderRegistry.register(JavaPhysicalComponentDefinition.class, this);
+ wireAttacherRegistry.register(JavaPhysicalWireSourceDefinition.class, this);
+ wireAttacherRegistry.register(JavaPhysicalWireTargetDefinition.class, this);
+ }
+
+ public JavaComponent<T> build(JavaPhysicalComponentDefinition<T> definition) throws BuilderException {
+ URI componentId = definition.getComponentId();
+ int initLevel = definition.getInitLevel();
+ URI groupId = definition.getGroupId();
+ ClassLoader classLoader = classLoaderRegistry.getClassLoader(definition.getClassLoaderId());
+
+ // get the scope container for this component
+ Scope scope = definition.getScope();
+ ScopeContainer<?> scopeContainer = scopeRegistry.getScopeContainer(scope);
+
+ // create the InstanceFactoryProvider based on the definition in the model
+ InstanceFactoryProviderDefinition<T> providerDefinition = definition.getInstanceFactoryProviderDefinition();
+ InstanceFactoryProvider<T> provider = providerBuilders.build(providerDefinition, classLoader);
+
+ return new JavaComponent<T>(componentId, provider, scopeContainer, groupId, initLevel, -1, -1);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void attachToSource(JavaComponent source,
+ JavaPhysicalWireSourceDefinition sourceDefinition, Component target,
+ PhysicalWireTargetDefinition targetDefinition, Wire wire
+ ) {
+ URI sourceUri = sourceDefinition.getUri();
+ InjectionSource referenceSource = new InjectionSource(REFERENCE, sourceUri.getFragment());
+ Class<?> type = source.getMemberType(referenceSource);
+ if (sourceDefinition.isOptimizable()) {
+ assert target instanceof AtomicComponent;
+ ObjectFactory<?> factory = ((AtomicComponent<?>) target).createObjectFactory();
+ source.setObjectFactory(referenceSource, factory);
+ } else {
+ ObjectFactory<?> factory =
+ new WireObjectFactory2(type, sourceDefinition.isConversational(), wire, proxyService);
+ source.setObjectFactory(referenceSource, factory);
+ if (!wire.getCallbackInvocationChains().isEmpty()) {
+ URI callbackUri = sourceDefinition.getCallbackUri();
+ InjectionSource callbackSource = new InjectionSource(CALLBACK, callbackUri.getFragment());
+ Class<?> callbackType = source.getMemberType(callbackSource);
+ ObjectFactory<?> callbackFactory = new CallbackWireObjectFactory2(callbackType, proxyService);
+ source.setObjectFactory(callbackSource, callbackFactory);
+ }
+ }
+ }
+
+ public void attachToTarget(Component source,
+ PhysicalWireSourceDefinition sourceDefinition,
+ JavaComponent component,
+ JavaPhysicalWireTargetDefinition target,
+ Wire wire) throws WireAttachException {
+ if (sourceDefinition.isOptimizable()) {
+ return;
+ }
+
+ ScopeContainer scopeContainer = component.getScopeContainer();
+ Class<?> implementationClass = component.getImplementationClass();
+ ClassLoader loader = implementationClass.getClassLoader();
+ // attach the invoker interceptor to forward invocation chains
+ for (Map.Entry<PhysicalOperationDefinition, InvocationChain> entry : wire.getPhysicalInvocationChains()
+ .entrySet()) {
+ PhysicalOperationDefinition operation = entry.getKey();
+ InvocationChain chain = entry.getValue();
+ List<String> params = operation.getParameters();
+ Class<?>[] paramTypes = new Class<?>[params.size()];
+ assert loader != null;
+ for (int i = 0; i < params.size(); i++) {
+ String param = params.get(i);
+ try {
+ paramTypes[i] = loader.loadClass(param);
+ } catch (ClassNotFoundException e) {
+ URI sourceUri = wire.getSourceUri();
+ URI targetUri = wire.getTargetUri();
+ throw new WireAttachException("Implementation class not found", sourceUri, targetUri, e);
+ }
+ }
+ Method method;
+ try {
+ method = implementationClass.getMethod(operation.getName(), paramTypes);
+ } catch (NoSuchMethodException e) {
+ URI sourceUri = wire.getSourceUri();
+ URI targetUri = wire.getTargetUri();
+ throw new WireAttachException("No matching method found", sourceUri, targetUri, e);
+ }
+ chain.addInterceptor(new JavaInvokerInterceptor(method, component, scopeContainer));
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaPhysicalComponentGenerator.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaPhysicalComponentGenerator.java
new file mode 100644
index 0000000000..638bc46698
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaPhysicalComponentGenerator.java
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import java.lang.annotation.ElementType;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.Map;
+import java.net.URI;
+
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.generator.ComponentGenerator;
+import org.apache.tuscany.spi.generator.GenerationException;
+import org.apache.tuscany.spi.generator.GeneratorContext;
+import org.apache.tuscany.spi.generator.GeneratorRegistry;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition;
+
+import org.apache.tuscany.core.model.physical.instancefactory.InjectionSiteMapping;
+import org.apache.tuscany.core.model.physical.instancefactory.InjectionSource;
+import static org.apache.tuscany.core.model.physical.instancefactory.InjectionSource.ValueSourceType.REFERENCE;
+import org.apache.tuscany.core.model.physical.instancefactory.MemberSite;
+import org.apache.tuscany.core.model.physical.instancefactory.ReflectiveIFProviderDefinition;
+import org.apache.tuscany.core.model.physical.java.JavaPhysicalComponentDefinition;
+import org.apache.tuscany.core.model.physical.java.JavaPhysicalWireSourceDefinition;
+import org.apache.tuscany.core.model.physical.java.JavaPhysicalWireTargetDefinition;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+public class JavaPhysicalComponentGenerator implements ComponentGenerator<ComponentDefinition<JavaImplementation>> {
+
+ public JavaPhysicalComponentGenerator(@Reference GeneratorRegistry registry) {
+ registry.register(JavaImplementation.class, this);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void generate(ComponentDefinition<JavaImplementation> definition, GeneratorContext context) {
+ JavaImplementation implementation = definition.getImplementation();
+ // TODO not a safe cast
+ PojoComponentType<JavaMappedService, JavaMappedReference, Property<?>> type = implementation.getComponentType();
+ JavaPhysicalComponentDefinition pDefinition = new JavaPhysicalComponentDefinition();
+ pDefinition.setComponentId(definition.getUri());
+ // set the classloader id temporarily until contribution service
+ pDefinition.setClassLoaderId(URI.create("sca://./bootClassLoader"));
+ pDefinition.setScope(type.getImplementationScope());
+ // TODO get classloader id
+ ReflectiveIFProviderDefinition provider = new ReflectiveIFProviderDefinition();
+ Method destroyMethod = type.getDestroyMethod();
+ if (destroyMethod != null) {
+ provider.setDestroyMethod(destroyMethod.toString());
+ }
+ Method initMethod = type.getInitMethod();
+ if (initMethod != null) {
+ provider.setInitMethod(initMethod.toString());
+ }
+ provider.setImplementationClass(implementation.getImplementationClass().getName());
+ // TODO ctor arguments
+ // TODO set CDI source for ref, props, and callbacks
+ Map<String, JavaMappedReference> references = type.getReferences();
+ for (Map.Entry<String, JavaMappedReference> entry : references.entrySet()) {
+ JavaMappedReference reference = entry.getValue();
+ Member member = reference.getMember();
+ InjectionSource source = new InjectionSource();
+ source.setName(entry.getKey());
+ source.setValueType(REFERENCE);
+ MemberSite memberSite = new MemberSite();
+ memberSite.setName(member.getName());
+ if (member instanceof Method) {
+ memberSite.setElementType(ElementType.METHOD);
+ } else if (member instanceof Field) {
+ memberSite.setElementType(ElementType.FIELD);
+ } else {
+ throw new AssertionError("Illegal injection type");
+ }
+
+ InjectionSiteMapping mapping = new InjectionSiteMapping();
+ mapping.setSource(source);
+ mapping.setSite(memberSite);
+ provider.addInjectionSite(mapping);
+ }
+
+ pDefinition.setInstanceFactoryProviderDefinition(provider);
+ context.getPhysicalChangeSet().addComponentDefinition(pDefinition);
+ }
+
+ public PhysicalWireSourceDefinition generateWireSource(ComponentDefinition<JavaImplementation> definition,
+ ReferenceDefinition serviceDefinition,
+ boolean optimizable,
+ GeneratorContext context)
+ throws GenerationException {
+ JavaPhysicalWireSourceDefinition wireDefinition = new JavaPhysicalWireSourceDefinition();
+ wireDefinition.setUri(definition.getUri().resolve(serviceDefinition.getUri()));
+ wireDefinition.setOptimizable(optimizable);
+ return wireDefinition;
+ }
+
+ public PhysicalWireTargetDefinition generateWireTarget(ComponentDefinition<JavaImplementation> definition,
+ ServiceDefinition serviceDefinition,
+ GeneratorContext context)
+ throws GenerationException {
+ JavaPhysicalWireTargetDefinition wireDefinition = new JavaPhysicalWireTargetDefinition();
+ wireDefinition.setUri(definition.getUri().resolve(serviceDefinition.getUri()));
+ return wireDefinition;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaTargetInvoker.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaTargetInvoker.java
new file mode 100644
index 0000000000..102604c8fa
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/JavaTargetInvoker.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ComponentException;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.InvalidConversationSequenceException;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.extension.TargetInvokerExtension;
+import org.apache.tuscany.spi.model.Scope;
+
+/**
+ * Responsible for synchronously dispatching an invocation to a Java component implementation instance
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaTargetInvoker<T> extends TargetInvokerExtension {
+ protected Method operation;
+ private final AtomicComponent<T> component;
+ private final ScopeContainer scopeContainer;
+ protected InstanceWrapper<T> target;
+ protected boolean stateless;
+
+ public JavaTargetInvoker(Method operation,
+ AtomicComponent<T> component,
+ ScopeContainer scopeContainer
+ ) {
+ assert operation != null : "Operation method cannot be null";
+ this.operation = operation;
+ this.component = component;
+ this.scopeContainer = scopeContainer;
+ stateless = Scope.STATELESS == scopeContainer.getScope();
+ }
+
+ public Object invokeTarget(final Object payload, final short sequence, WorkContext workContext) throws InvocationTargetException {
+ Object contextId = workContext.getIdentifier(scopeContainer.getScope());
+ try {
+ InstanceWrapper<T> wrapper = getInstance(sequence, contextId);
+ Object instance = wrapper.getInstance();
+ Object ret;
+ if (payload != null && !payload.getClass().isArray()) {
+ ret = operation.invoke(instance, payload);
+ } else {
+ ret = operation.invoke(instance, (Object[]) payload);
+ }
+ scopeContainer.returnWrapper(component, wrapper, contextId);
+ if (sequence == END) {
+ // if end conversation, remove resource
+ scopeContainer.remove(component);
+ }
+ return ret;
+ } catch (IllegalAccessException e) {
+ throw new InvocationTargetException(e);
+ } catch (ComponentException e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+
+ @Override
+ public JavaTargetInvoker clone() throws CloneNotSupportedException {
+ try {
+ JavaTargetInvoker invoker = (JavaTargetInvoker) super.clone();
+ invoker.target = null;
+ return invoker;
+ } catch (CloneNotSupportedException e) {
+ return null; // will not happen
+ }
+ }
+
+ /**
+ * Resolves the target service instance or returns a cached one
+ */
+ protected InstanceWrapper<T> getInstance(short sequence, Object contextId) throws TargetException {
+ switch (sequence) {
+ case NONE:
+ if (cacheable) {
+ if (target == null) {
+ target = scopeContainer.getWrapper(component, contextId);
+ }
+ return target;
+ } else {
+ return scopeContainer.getWrapper(component, contextId);
+ }
+ case START:
+ assert !cacheable;
+ return scopeContainer.getWrapper(component, contextId);
+ case CONTINUE:
+ case END:
+ assert !cacheable;
+ return scopeContainer.getAssociatedWrapper(component, contextId);
+ default:
+ throw new InvalidConversationSequenceException("Unknown sequence type", String.valueOf(sequence));
+ }
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/TargetMethodNotFoundException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/TargetMethodNotFoundException.java
new file mode 100644
index 0000000000..427d38c6ec
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/TargetMethodNotFoundException.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.core.implementation.java;
+
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TargetMethodNotFoundException extends TargetInvokerCreationException {
+ private Operation operation;
+ private PhysicalOperationDefinition pOperation;
+
+ /**
+ * @deprecated
+ * @param operation
+ */
+ public TargetMethodNotFoundException(Operation operation) {
+ super("Target method not found for operation");
+ this.operation = operation;
+ }
+
+ public TargetMethodNotFoundException(PhysicalOperationDefinition operation) {
+ super("Target method not found for operation");
+ this.pOperation = operation;
+ }
+
+ public Operation getOperation() {
+ return operation;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/TypeNotFoundException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/TypeNotFoundException.java
new file mode 100644
index 0000000000..8a1f1c2560
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/java/TypeNotFoundException.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.core.implementation.java;
+
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TypeNotFoundException extends TargetInvokerCreationException {
+ private PhysicalOperationDefinition operation;
+
+ public TypeNotFoundException(PhysicalOperationDefinition operation, Throwable cause) {
+ super("Type not found for operation", cause);
+ this.operation = operation;
+ }
+
+ public PhysicalOperationDefinition getOperation() {
+ return operation;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessor.java
new file mode 100644
index 0000000000..5d90b49362
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessor.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.core.implementation.processor;
+
+import org.osoa.sca.annotations.AllowsPassByReference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorExtension;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Processes {@link AllowsPassByReference} on an implementation
+ *
+ * @version $Rev: 479093 $ $Date: 2006-11-25 12:34:41 +0530 (Sat, 25 Nov 2006) $
+ */
+public class AllowsPassByReferenceProcessor extends ImplementationProcessorExtension {
+
+ public <T> void visitClass(Class<T> clazz,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context)
+ throws ProcessingException {
+ AllowsPassByReference annotation = clazz.getAnnotation(AllowsPassByReference.class);
+ if (annotation == null) {
+ return;
+ } else {
+ // TODO implement
+ }
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/AmbiguousConstructorException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/AmbiguousConstructorException.java
new file mode 100644
index 0000000000..03d092880d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/AmbiguousConstructorException.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Thrown when constructor parameters cannot be unambiguously resolved to a property or reference
+ *
+ * @version $Rev$ $Date$
+ */
+public class AmbiguousConstructorException extends ProcessingException {
+
+ public AmbiguousConstructorException(String message) {
+ super(message);
+ }
+
+ public AmbiguousConstructorException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public AmbiguousConstructorException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessor.java
new file mode 100644
index 0000000000..04598199c5
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessor.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.core.implementation.processor;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorExtension;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+
+/**
+ * Handles processing of a constructor decorated with {@link org.osoa.sca.annotations.Constructor}
+ *
+ * @version $Rev$ $Date$
+ */
+@SuppressWarnings("unchecked")
+public class ConstructorProcessor extends ImplementationProcessorExtension {
+
+ private ImplementationProcessorService service;
+
+ public ConstructorProcessor(@Reference ImplementationProcessorService service) {
+ this.service = service;
+ }
+
+ public <T> void visitClass(Class<T> clazz,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException {
+ Constructor[] ctors = clazz.getConstructors();
+ boolean found = false;
+ for (Constructor constructor : ctors) {
+ if (constructor.getAnnotation(org.osoa.sca.annotations.Constructor.class) != null) {
+ if (found) {
+ String name = constructor.getDeclaringClass().getName();
+ throw new DuplicateConstructorException("Multiple constructors marked with @Constructor", name);
+ }
+ found = true;
+ }
+ }
+ }
+
+ public <T> void visitConstructor(Constructor<T> constructor,
+ PojoComponentType<JavaMappedService, JavaMappedReference,
+ JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException {
+ org.osoa.sca.annotations.Constructor annotation =
+ constructor.getAnnotation(org.osoa.sca.annotations.Constructor.class);
+ if (annotation == null) {
+ return;
+ }
+ ConstructorDefinition<?> definition = type.getConstructorDefinition();
+ if (definition != null && !definition.getConstructor().equals(constructor)) {
+ String name = constructor.getDeclaringClass().getName();
+ throw new DuplicateConstructorException("Multiple constructor definitions found", name);
+ } else if (definition == null) {
+ definition = new ConstructorDefinition(constructor);
+ }
+ Class<?>[] params = constructor.getParameterTypes();
+ String[] names = annotation.value();
+ Annotation[][] annotations = constructor.getParameterAnnotations();
+ List<String> injectionNames = definition.getInjectionNames();
+ for (int i = 0; i < params.length; i++) {
+ Class<?> param = params[i];
+ Annotation[] paramAnnotations = annotations[i];
+ try {
+ if (!service.processParam(param,
+ constructor.getGenericParameterTypes()[i],
+ paramAnnotations,
+ names,
+ i,
+ type,
+ injectionNames)) {
+ String name = (i < names.length) ? names[i] : "";
+ service.addName(injectionNames, i, name);
+ }
+ } catch (ProcessingException e) {
+ e.setMember(constructor);
+ throw e;
+ }
+ }
+ if (names.length != 0 && names[0].length() != 0 && names.length != params.length) {
+ throw new InvalidConstructorException("Names in @Constructor do not match number of parameters");
+ }
+ type.setConstructorDefinition(definition);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ContextProcessor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ContextProcessor.java
new file mode 100644
index 0000000000..a0d462b660
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ContextProcessor.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.core.implementation.processor;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.RequestContext;
+import org.osoa.sca.annotations.Context;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorExtension;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+import org.apache.tuscany.spi.implementation.java.Resource;
+
+import org.apache.tuscany.core.injection.RequestContextObjectFactory;
+import org.apache.tuscany.core.util.JavaIntrospectionHelper;
+
+/**
+ * Processes {@link @Context} 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 ContextProcessor extends ImplementationProcessorExtension {
+ private WorkContext workContext;
+
+ @Reference
+ public void setWorkContext(WorkContext workContext) {
+ this.workContext = workContext;
+ }
+
+ public void visitMethod(
+ Method method,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context)
+ throws ProcessingException {
+ if (method.getAnnotation(Context.class) == null) {
+ return;
+ }
+ if (method.getParameterTypes().length != 1) {
+ throw new IllegalContextException("Context setter must have one parameter", method.toString());
+ }
+ Class<?> paramType = method.getParameterTypes()[0];
+ if (ComponentContext.class.equals(paramType)) {
+ String name = JavaIntrospectionHelper.toPropertyName(method.getName());
+ Resource<ComponentContext> resource = new Resource<ComponentContext>(name, ComponentContext.class, method);
+ type.getResources().put(name, resource);
+ } else if (RequestContext.class.equals(paramType)) {
+ String name = JavaIntrospectionHelper.toPropertyName(method.getName());
+ Resource<RequestContext> resource = new Resource<RequestContext>(name, RequestContext.class, method);
+ resource.setObjectFactory(new RequestContextObjectFactory(workContext));
+ type.getResources().put(name, resource);
+ } else {
+ throw new UnknownContextTypeException(paramType.getName());
+ }
+ }
+
+ public void visitField(Field field,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException {
+ if (field.getAnnotation(Context.class) == null) {
+ return;
+ }
+ Class<?> paramType = field.getType();
+ if (ComponentContext.class.equals(paramType)) {
+ String name = field.getName();
+ Resource<ComponentContext> resource = new Resource<ComponentContext>(name, ComponentContext.class, field);
+ type.getResources().put(name, resource);
+ } else if (RequestContext.class.equals(paramType)) {
+ String name = field.getName();
+ name = JavaIntrospectionHelper.toPropertyName(name);
+ Resource<RequestContext> resource = new Resource<RequestContext>(name, RequestContext.class, field);
+ resource.setObjectFactory(new RequestContextObjectFactory(workContext));
+ type.getResources().put(name, resource);
+ } else {
+ throw new UnknownContextTypeException(paramType.getName());
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ConversationProcessor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ConversationProcessor.java
new file mode 100644
index 0000000000..9d81e15ba1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ConversationProcessor.java
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.osoa.sca.annotations.ConversationAttributes;
+import org.osoa.sca.annotations.ConversationID;
+import org.osoa.sca.annotations.Scope;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorExtension;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConversationProcessor extends ImplementationProcessorExtension {
+ private static final String SECONDS = " SECONDS";
+ private static final String MINUTES = " MINUTES";
+ private static final String HOURS = " HOURS";
+ private static final String DAYS = " DAYS";
+ private static final String YEARS = " YEARS";
+
+ public <T> void visitClass(Class<T> clazz,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException {
+
+ ConversationAttributes conversation = clazz.getAnnotation(ConversationAttributes.class);
+ if (conversation == null) {
+ return;
+ }
+ Scope scope = clazz.getAnnotation(Scope.class);
+ if (scope == null) {
+ // implicitly assume conversation
+ type.setImplementationScope(org.apache.tuscany.spi.model.Scope.CONVERSATION);
+ } else if (scope != null && !"CONVERSATION".equals(scope.value().toUpperCase())) {
+ throw new InvalidConversationalImplementation(
+ "Service is marked with @ConversationAttributes but the scope is not @Scope(\"CONVERSATION\")",
+ clazz.getName());
+ } else if (conversation != null) {
+ long maxAge;
+ long maxIdleTime;
+ String maxAgeVal = conversation.maxAge();
+ String maxIdleTimeVal = conversation.maxIdleTime();
+ if (maxAgeVal.length() > 0 && maxIdleTimeVal.length() > 0) {
+ throw new InvalidConversationalImplementation("Max idle time and age both specified", clazz.getName());
+ }
+ try {
+ if (maxAgeVal.length() > 0) {
+ maxAge = convertTimeMillis(maxAgeVal);
+ type.setMaxAge(maxAge);
+ }
+ } catch (NumberFormatException e) {
+ throw new InvalidConversationalImplementation("Invalid maximum age", clazz.getName(), e);
+ }
+ try {
+ if (maxIdleTimeVal.length() > 0) {
+ maxIdleTime = convertTimeMillis(maxIdleTimeVal);
+ type.setMaxIdleTime(maxIdleTime);
+ }
+ } catch (NumberFormatException e) {
+ throw new InvalidConversationalImplementation("Invalid maximum idle time", clazz.getName(), e);
+ }
+ }
+
+ }
+
+ public void visitMethod(Method method,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context)
+ throws ProcessingException {
+ ConversationID conversationID = method.getAnnotation(ConversationID.class);
+ if (conversationID == null) {
+ return;
+ }
+ type.setConversationIDMember(method);
+ }
+
+ public void visitField(Field field,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException {
+ ConversationID conversationID = field.getAnnotation(ConversationID.class);
+ if (conversationID == null) {
+ return;
+ }
+ type.setConversationIDMember(field);
+ }
+
+ protected long convertTimeMillis(String expr) throws NumberFormatException {
+ expr = expr.trim().toUpperCase();
+ int i = expr.lastIndexOf(SECONDS);
+ if (i >= 0) {
+ String units = expr.substring(0, i);
+ return Long.parseLong(units) * 1000;
+ }
+ i = expr.lastIndexOf(MINUTES);
+ if (i >= 0) {
+ String units = expr.substring(0, i);
+ return Long.parseLong(units) * 60000;
+ }
+
+ i = expr.lastIndexOf(HOURS);
+ if (i >= 0) {
+ String units = expr.substring(0, i);
+ return Long.parseLong(units) * 3600000;
+ }
+ i = expr.lastIndexOf(DAYS);
+ if (i >= 0) {
+ String units = expr.substring(0, i);
+ return Long.parseLong(units) * 86400000;
+ }
+ i = expr.lastIndexOf(YEARS);
+ if (i >= 0) {
+ String units = expr.substring(0, i);
+ return Long.parseLong(units) * 31556926000L;
+ }
+ return Long.parseLong(expr) * 1000; // assume seconds if no suffix specified
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DestroyProcessor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DestroyProcessor.java
new file mode 100644
index 0000000000..0b4e8eff76
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DestroyProcessor.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.core.implementation.processor;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import org.osoa.sca.annotations.Destroy;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorExtension;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Processes the {@link @Destroy} annotation on a component implementation and updates the component type with the
+ * decorated destructor method
+ *
+ * @version $Rev$ $Date$
+ */
+public class DestroyProcessor extends ImplementationProcessorExtension {
+
+ public void visitMethod(Method method,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context)
+ throws ProcessingException {
+ Destroy annotation = method.getAnnotation(Destroy.class);
+ if (annotation == null) {
+ return;
+ }
+ if (method.getParameterTypes().length != 0) {
+ throw new IllegalDestructorException("Destructor must not have argments", method.toString());
+ }
+ if (type.getDestroyMethod() != null) {
+ throw new DuplicateDestructorException("More than one destructor found on implementation");
+ }
+ if (Modifier.isProtected(method.getModifiers())) {
+ method.setAccessible(true);
+ }
+ type.setDestroyMethod(method);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateConstructorException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateConstructorException.java
new file mode 100644
index 0000000000..88db7ebb79
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateConstructorException.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Thrown when more than one component implementation constructor is annotated with {@link
+ * org.osoa.sca.annotations.Constructor}
+ *
+ * @version $Rev$ $Date$
+ */
+public class DuplicateConstructorException extends ProcessingException {
+
+ public DuplicateConstructorException(String message) {
+ super(message);
+ }
+
+ public DuplicateConstructorException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateDestructorException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateDestructorException.java
new file mode 100644
index 0000000000..6225bd6219
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateDestructorException.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Thrown when an implementation is annotated multiple times with {@link org.osoa.sca.annotations.Destroy}
+ *
+ * @version $Rev$ $Date$
+ */
+public class DuplicateDestructorException extends ProcessingException {
+
+ public DuplicateDestructorException(String message) {
+ super(message);
+ }
+
+ public DuplicateDestructorException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateInitException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateInitException.java
new file mode 100644
index 0000000000..105edee1a2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateInitException.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Thrown when an implementation is annotated multiple times with {@link @org.osoa.sca.annotations.Init}
+ *
+ * @version $Rev$ $Date$
+ */
+public class DuplicateInitException extends ProcessingException {
+
+ public DuplicateInitException(String message) {
+ super(message);
+ }
+
+ public DuplicateInitException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateReferenceException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateReferenceException.java
new file mode 100644
index 0000000000..5eae1461c2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateReferenceException.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Thrown when an implementation has more than one reference injection site with the same name
+ *
+ * @version $Rev$ $Date$
+ */
+public class DuplicateReferenceException extends ProcessingException {
+
+ public DuplicateReferenceException(String message) {
+ super(message);
+ }
+
+
+ public DuplicateReferenceException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateResourceException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateResourceException.java
new file mode 100644
index 0000000000..9dd718c03e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/DuplicateResourceException.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Thrown when an implementation has more than one resource injection site with the same name
+ *
+ * @version $Rev$ $Date$
+ */
+public class DuplicateResourceException extends ProcessingException {
+
+ public DuplicateResourceException(String message) {
+ super(message);
+ }
+
+ public DuplicateResourceException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessor.java
new file mode 100644
index 0000000000..cdf39013a1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessor.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.core.implementation.processor;
+
+import org.osoa.sca.annotations.EagerInit;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorExtension;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Handles processing of {@link org.osoa.sca.annotations.EagerInit}
+ *
+ * @version $Rev$ $Date$
+ */
+public class EagerInitProcessor extends ImplementationProcessorExtension {
+
+ public <T> void visitClass(Class<T> clazz,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException {
+ super.visitClass(clazz, type, context);
+ EagerInit annotation = clazz.getAnnotation(EagerInit.class);
+ if (annotation == null) {
+ Class<?> superClass = clazz.getSuperclass();
+ while (!Object.class.equals(superClass)) {
+ annotation = superClass.getAnnotation(EagerInit.class);
+ if (annotation != null) {
+ break;
+ }
+ superClass = superClass.getSuperclass();
+ }
+ if (annotation == null) {
+ return;
+ }
+ }
+ type.setInitLevel(50);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessor.java
new file mode 100644
index 0000000000..ab125d5ca1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessor.java
@@ -0,0 +1,548 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.implementation.processor;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Remotable;
+import org.osoa.sca.annotations.Service;
+
+import org.apache.tuscany.spi.databinding.extension.SimpleTypeMapperExtension;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.model.TypeInfo;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorExtension;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+import static org.apache.tuscany.core.util.JavaIntrospectionHelper.getAllInterfaces;
+import static org.apache.tuscany.core.util.JavaIntrospectionHelper.getAllPublicAndProtectedFields;
+import static org.apache.tuscany.core.util.JavaIntrospectionHelper.getAllUniquePublicProtectedMethods;
+import static org.apache.tuscany.core.util.JavaIntrospectionHelper.getBaseName;
+import static org.apache.tuscany.core.util.JavaIntrospectionHelper.toPropertyName;
+
+/**
+ * Heuristically evaluates an un-annotated Java implementation type to determine services, references, and properties
+ * according to the algorithm described in the SCA Java Client and Implementation Model Specification <p/> TODO
+ * Implement:
+ * <p/>
+ * When no service inteface is annotated, need to calculate a single service comprising all public methods that are not
+ * reference or property injection sites. If that service can be exactly mapped to an interface implemented by the class
+ * then the service interface will be defined in terms of that interface.
+ *
+ * @version $Rev$ $Date$
+ */
+public class HeuristicPojoProcessor extends ImplementationProcessorExtension {
+ private SimpleTypeMapperExtension typeMapper = new SimpleTypeMapperExtension();
+ private ImplementationProcessorService implService;
+
+ public HeuristicPojoProcessor(@Reference ImplementationProcessorService service) {
+ this.implService = service;
+ }
+
+ public <T> void visitEnd(
+ Class<T> clazz,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException {
+ Map<String, JavaMappedService> services = type.getServices();
+ if (services.isEmpty()) {
+ // heuristically determine the service
+ // TODO finish algorithm
+ Set<Class> interfaces = getAllInterfaces(clazz);
+ if (interfaces.size() == 0) {
+ // class is the interface
+ JavaMappedService service;
+ try {
+ service = implService.createService(clazz);
+ } catch (InvalidServiceContractException e) {
+ throw new ProcessingException(e);
+ }
+ type.getServices().put(service.getUri().getFragment(), service);
+ } else if (interfaces.size() == 1) {
+ JavaMappedService service;
+ try {
+ service = implService.createService(interfaces.iterator().next());
+ } catch (InvalidServiceContractException e) {
+ throw new ProcessingException(e);
+ }
+ type.getServices().put(service.getUri().getFragment(), service);
+ }
+ }
+ Set<Method> methods = getAllUniquePublicProtectedMethods(clazz);
+ if (!type.getReferences().isEmpty() || !type.getProperties().isEmpty()) {
+ // references and properties have been explicitly defined
+ if (type.getServices().isEmpty()) {
+ calculateServiceInterface(clazz, type, methods);
+ if (type.getServices().isEmpty()) {
+ throw new ServiceTypeNotFoundException(clazz.getName());
+ }
+ }
+ evaluateConstructor(type, clazz);
+ return;
+ }
+ calcPropRefs(methods, services, type, clazz);
+ evaluateConstructor(type, clazz);
+ }
+
+ private <T> void calcPropRefs(Set<Method> methods,
+ Map<String, JavaMappedService> services,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ Class<T> clazz) throws ProcessingException {
+ // heuristically determine the properties references
+ // make a first pass through all public methods with one param
+ for (Method method : methods) {
+ if (method.getParameterTypes().length != 1 || !Modifier.isPublic(method.getModifiers())
+ || !method.getName().startsWith("set")
+ || method.getReturnType() != void.class) {
+ continue;
+ }
+ if (!isInServiceInterface(method, services)) {
+ String name = toPropertyName(method.getName());
+ // avoid duplicate property or ref names
+ if (!type.getProperties().containsKey(name) && !type.getReferences().containsKey(name)) {
+ Class<?> param = method.getParameterTypes()[0];
+ Type genericType = method.getGenericParameterTypes()[0];
+ if (isReferenceType(genericType)) {
+ type.add(createReference(name, method, param));
+ } else {
+ type.add(createProperty(name, method, param));
+ }
+ }
+ }
+ }
+ // second pass for protected methods with one param
+ for (Method method : methods) {
+ if (method.getParameterTypes().length != 1 || !Modifier.isProtected(method.getModifiers())
+ || !method.getName().startsWith("set")
+ || method.getReturnType() != void.class) {
+ continue;
+ }
+ Class<?> param = method.getParameterTypes()[0];
+ String name = toPropertyName(method.getName());
+ // avoid duplicate property or ref names
+ if (!type.getProperties().containsKey(name) && !type.getReferences().containsKey(name)) {
+ if (isReferenceType(param)) {
+ type.add(createReference(name, method, param));
+ } else {
+ type.add(createProperty(name, method, param));
+ }
+ }
+ }
+ Set<Field> fields = getAllPublicAndProtectedFields(clazz);
+ for (Field field : fields) {
+ Class<?> paramType = field.getType();
+ if (isReferenceType(paramType)) {
+ type.add(createReference(field.getName(), field, paramType));
+ } else {
+ type.add(createProperty(field.getName(), field, paramType));
+ }
+ }
+ }
+
+ /**
+ * Determines the constructor to use based on the component type's references and properties
+ *
+ * @param type the component type
+ * @param clazz the implementation class corresponding to the component type
+ * @throws NoConstructorException if no suitable constructor is found
+ * @throws AmbiguousConstructorException if the parameters of a constructor cannot be unambiguously mapped to
+ * references and properties
+ */
+ @SuppressWarnings("unchecked")
+ private <T> void evaluateConstructor(
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ Class<T> clazz) throws ProcessingException {
+ // determine constructor if one is not annotated
+ ConstructorDefinition<?> definition = type.getConstructorDefinition();
+ Constructor constructor;
+ boolean explict = false;
+ if (definition != null
+ && definition.getConstructor().getAnnotation(org.osoa.sca.annotations.Constructor.class) != null) {
+ // the constructor was already defined explicitly
+ return;
+ } else if (definition != null) {
+ explict = true;
+ constructor = definition.getConstructor();
+ } else {
+ // no definition, heuristically determine constructor
+ Constructor[] constructors = clazz.getConstructors();
+ if (constructors.length == 0) {
+ throw new NoConstructorException("No public constructor for class", clazz.getName());
+ } else if (constructors.length == 1) {
+ constructor = constructors[0];
+ } else {
+ // FIXME multiple constructors, none yet done
+ Constructor<T> selected = null;
+ int sites = type.getProperties().size() + type.getReferences().size();
+ for (Constructor<T> ctor : constructors) {
+ if (ctor.getParameterTypes().length == 0) {
+ selected = ctor;
+ }
+ if (ctor.getParameterTypes().length == sites) {
+ // TODO finish
+ // selected = constructor;
+ // select constructor
+ // break;
+ }
+ }
+ if (selected == null) {
+ throw new NoConstructorException();
+ }
+ constructor = selected;
+ definition = new ConstructorDefinition<T>(selected);
+ type.setConstructorDefinition(definition);
+ // return;
+ }
+ definition = new ConstructorDefinition<T>(constructor);
+ type.setConstructorDefinition(definition);
+ }
+ Class[] params = constructor.getParameterTypes();
+ if (params.length == 0) {
+ return;
+ }
+ List<String> paramNames = definition.getInjectionNames();
+ Map<String, JavaMappedProperty<?>> props = type.getProperties();
+ Map<String, JavaMappedReference> refs = type.getReferences();
+ Annotation[][] annotations = constructor.getParameterAnnotations();
+ if (!explict) {
+ // the constructor wasn't defined by an annotation, so check to see if any of the params have an annotation
+ // which we can impute as explicitly defining the constructor, e.g. @Property, @Reference, or @Autowire
+ explict = implService.injectionAnnotationsPresent(annotations);
+ }
+ if (explict) {
+ for (int i = 0; i < params.length; i++) {
+ Class param = params[i];
+ implService.processParam(param,
+ constructor.getGenericParameterTypes()[i],
+ annotations[i],
+ new String[0],
+ i,
+ type,
+ paramNames);
+ }
+ } else {
+ if (!implService.areUnique(params)) {
+ throw new AmbiguousConstructorException("Cannot resolve non-unique parameter types, use @Constructor");
+ }
+ if (!calcPropRefUniqueness(props.values(), refs.values())) {
+ throw new AmbiguousConstructorException("Cannot resolve non-unique parameter types, use @Constructor");
+ }
+ boolean empty = props.size() + refs.size() == 0;
+ if (!empty) {
+ calcParamNames(params, props, refs, paramNames);
+ } else {
+ heuristicParamNames(params, refs, props, paramNames);
+
+ }
+ }
+ }
+
+ private void calcParamNames(Class[] params,
+ Map<String, JavaMappedProperty<?>> props,
+ Map<String, JavaMappedReference> refs,
+ List<String> paramNames)
+ throws AmbiguousConstructorException {
+ // the constructor param types must unambiguously match defined reference or property types
+ for (Class param : params) {
+ String name = findReferenceOrProperty(param, props, refs);
+ if (name == null) {
+ throw new AmbiguousConstructorException(param.getName());
+ }
+ paramNames.add(name);
+ }
+ }
+
+ private void heuristicParamNames(Class[] params,
+ Map<String, JavaMappedReference> refs,
+ Map<String, JavaMappedProperty<?>> props,
+ List<String> paramNames)
+ throws ProcessingException {
+ // heuristically determine refs and props from the parameter types
+ for (Class<?> param : params) {
+ String name = getBaseName(param).toLowerCase();
+ if (isReferenceType(param)) {
+ refs.put(name, createReference(name, null, param));
+ } else {
+ props.put(name, createProperty(name, null, param));
+ }
+ paramNames.add(name);
+ }
+ }
+
+ /**
+ * Returns true if the union of the given collections of properties and references have unique Java types
+ */
+ private boolean calcPropRefUniqueness(
+ Collection<JavaMappedProperty<?>> props,
+ Collection<JavaMappedReference> refs) {
+
+ Class[] classes = new Class[props.size() + refs.size()];
+ int i = 0;
+ for (JavaMappedProperty<?> property : props) {
+ classes[i] = property.getJavaType();
+ i++;
+ }
+ for (JavaMappedReference reference : refs) {
+ classes[i] = reference.getServiceContract().getInterfaceClass();
+ i++;
+ }
+ return implService.areUnique(classes);
+ }
+
+ /**
+ * Unambiguously finds the reference or property associated with the given type
+ *
+ * @return the name of the reference or property if found, null if not
+ * @throws AmbiguousConstructorException if the constructor parameter cannot be resolved to a property or reference
+ */
+ private String findReferenceOrProperty(
+ Class<?> type,
+ Map<String, JavaMappedProperty<?>> props,
+ Map<String, JavaMappedReference> refs) throws AmbiguousConstructorException {
+
+ String name = null;
+ for (JavaMappedProperty<?> property : props.values()) {
+ if (property.getJavaType().equals(type)) {
+ if (name != null) {
+ throw new AmbiguousConstructorException("Ambiguous property or reference for constructor type",
+ type.getName());
+ }
+ name = property.getName();
+ // do not break since ambiguities must be checked, i.e. more than one prop or ref of the same type
+ }
+ }
+ for (JavaMappedReference reference : refs.values()) {
+ if (reference.getServiceContract().getInterfaceClass().equals(type)) {
+ if (name != null) {
+ throw new AmbiguousConstructorException("Ambiguous property or reference for constructor type",
+ type.getName());
+ }
+ name = reference.getUri().getFragment();
+ // do not break since ambiguities must be checked, i.e. more than one prop or ref of the same type
+ }
+ }
+ return name;
+ }
+
+ /**
+ * Returns true if a given type is reference according to the SCA specification rules for determining reference
+ * types
+ */
+ private boolean isReferenceType(Type operationType) {
+ Class<?> rawType;
+ Class<?> referenceType = null;
+ if (operationType instanceof ParameterizedType) {
+ ParameterizedType parameterizedType = (ParameterizedType) operationType;
+ rawType = (Class<?>) parameterizedType.getRawType();
+ Type[] typeArgs = parameterizedType.getActualTypeArguments();
+ if (typeArgs.length == 1) {
+ referenceType = (Class<?>) typeArgs[0];
+ }
+ } else {
+ rawType = (Class<?>) operationType;
+ }
+ if (rawType.isArray()) {
+ referenceType = rawType.getComponentType();
+ } else if (Collection.class.isAssignableFrom(rawType) && referenceType == null) {
+ return true;
+ }
+ if (referenceType != null) {
+ return referenceType.getAnnotation(Remotable.class) != null
+ || referenceType.getAnnotation(Service.class) != null;
+ } else {
+ return rawType.getAnnotation(Remotable.class) != null || rawType.getAnnotation(Service.class) != null;
+ }
+ }
+
+ /**
+ * Returns true if the given operation is defined in the collection of service interfaces
+ */
+ private boolean isInServiceInterface(Method operation, Map<String, JavaMappedService> services) {
+ for (JavaMappedService service : services.values()) {
+ Class<?> clazz = service.getServiceContract().getInterfaceClass();
+ if (operation.getDeclaringClass().equals(clazz)) {
+ return true;
+ }
+ Method[] methods = service.getServiceContract().getInterfaceClass().getMethods();
+ for (Method method : methods) {
+ if (operation.getName().equals(method.getName())
+ && operation.getParameterTypes().length == method.getParameterTypes().length) {
+ Class<?>[] methodTypes = method.getParameterTypes();
+ for (int i = 0; i < operation.getParameterTypes().length; i++) {
+ Class<?> paramType = operation.getParameterTypes()[i];
+ if (!paramType.equals(methodTypes[i])) {
+ break;
+ } else if (i == operation.getParameterTypes().length - 1) {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Creates a mapped reference
+ *
+ * @param name the reference name
+ * @param member the injection site the reference maps to
+ * @param paramType the service interface of the reference
+ */
+ private JavaMappedReference createReference(String name, Member member, Class<?> paramType)
+ throws ProcessingException {
+ return implService.createReference(name, member, paramType);
+ }
+
+ /**
+ * Creates a mapped property
+ *
+ * @param name the property name
+ * @param member the injection site the reference maps to
+ * @param paramType the property type
+ */
+ private <T> JavaMappedProperty<T> createProperty(String name, Member member, Class<T> paramType) {
+ JavaMappedProperty<T> property = new JavaMappedProperty<T>();
+ property.setName(name);
+ property.setMember(member);
+ property.setJavaType(paramType);
+ TypeInfo xmlType = typeMapper.getXMLType(paramType);
+ if (xmlType != null) {
+ property.setXmlType(xmlType.getQName());
+ }
+
+ return property;
+ }
+
+ /**
+ * Populates a component type with a service whose interface type is determined by examining all implemented
+ * interfaces of the given class and chosing one whose operations match all of the class's non-property and
+ * non-reference methods
+ *
+ * @param clazz the class to examine
+ * @param type the component type
+ * @param methods all methods in the class to examine
+ */
+ private void calculateServiceInterface(
+ Class<?> clazz,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ Set<Method> methods) throws ProcessingException {
+ List<Method> nonPropRefMethods = new ArrayList<Method>();
+ // Map<String, JavaMappedService> services = type.getServices();
+ Map<String, JavaMappedReference> references = type.getReferences();
+ Map<String, JavaMappedProperty<?>> properties = type.getProperties();
+ // calculate methods that are not properties or references
+ for (Method method : methods) {
+ String name = toPropertyName(method.getName());
+ if (!references.containsKey(name) && !properties.containsKey(name)) {
+ nonPropRefMethods.add(method);
+ }
+ }
+ // determine if an implemented interface matches all of the non-property and non-reference methods
+ Class[] interfaces = clazz.getInterfaces();
+ if (interfaces.length == 0) {
+ return;
+ }
+ for (Class interfaze : interfaces) {
+ if (analyzeInterface(interfaze, nonPropRefMethods)) {
+ JavaMappedService service;
+ try {
+ service = implService.createService(interfaze);
+ } catch (InvalidServiceContractException e) {
+ throw new ProcessingException(e);
+ }
+ type.getServices().put(service.getUri().getFragment(), service);
+ }
+ }
+ }
+
+ /**
+ * Determines if the methods of a given interface match the given list of methods
+ *
+ * @param interfaze the interface to examine
+ * @param nonPropRefMethods the list of methods to match against
+ * @return true if the interface matches
+ */
+ private boolean analyzeInterface(Class<?> interfaze, List<Method> nonPropRefMethods) {
+ Method[] interfaceMethods = interfaze.getMethods();
+ if (nonPropRefMethods.size() != interfaceMethods.length) {
+ return false;
+ }
+ for (Method method : nonPropRefMethods) {
+ boolean found = false;
+ for (Method interfaceMethod : interfaceMethods) {
+ if (interfaceMethod.getName().equals(method.getName())) {
+ Class<?>[] interfaceParamTypes = interfaceMethod.getParameterTypes();
+ Class<?>[] methodParamTypes = method.getParameterTypes();
+ if (interfaceParamTypes.length == methodParamTypes.length) {
+ if (interfaceParamTypes.length == 0) {
+ found = true;
+ } else {
+ for (int i = 0; i < methodParamTypes.length; i++) {
+ Class<?> param = methodParamTypes[i];
+ if (!param.equals(interfaceParamTypes[i])) {
+ break;
+ }
+ if (i == methodParamTypes.length - 1) {
+ found = true;
+ }
+ }
+ }
+ }
+ if (found) {
+ break;
+ }
+ }
+ }
+ if (!found) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+}
+
+/*
+ * 1) public setter methods that are not included in any service interface 2) protected setter methods 3) public or
+ * protected fields unless there is a setter method for the same name If the type associated with the member is an array
+ * or a java.util.Collection, then the basetype will be the element type of the array or the parameterized type of the
+ * Collection, otherwise the basetype will be the member type. If the basetype is an interface with an @Remotable or
+ * @Service annotation then the member will be defined as a reference, otherwise it will be defined as a property.
+ *
+ *
+ */
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalCallbackReferenceException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalCallbackReferenceException.java
new file mode 100644
index 0000000000..4581faa872
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalCallbackReferenceException.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Denotes an illegcal use of {@link org.osoa.sca.annotations.Callback} on a reference
+ *
+ * @version $Rev$ $Date$
+ */
+public class IllegalCallbackReferenceException extends ProcessingException {
+
+ public IllegalCallbackReferenceException(String message) {
+ super(message);
+ }
+
+ public IllegalCallbackReferenceException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalContextException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalContextException.java
new file mode 100644
index 0000000000..8c56cade83
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalContextException.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Denotes an illegal signature for a method decorated with {@link org.osoa.sca.annotations.Context}
+ *
+ * @version $Rev$ $Date$
+ */
+public class IllegalContextException extends ProcessingException {
+
+ public IllegalContextException(String message) {
+ super(message);
+ }
+
+ public IllegalContextException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalDestructorException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalDestructorException.java
new file mode 100644
index 0000000000..fee42ea5c8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalDestructorException.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Denotes an illegal signature for a method decorated with {@link org.osoa.sca.annotations.Destroy}
+ *
+ * @version $Rev$ $Date$
+ */
+public class IllegalDestructorException extends ProcessingException {
+
+ public IllegalDestructorException(String message) {
+ super(message);
+ }
+
+ public IllegalDestructorException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalInitException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalInitException.java
new file mode 100644
index 0000000000..219074b785
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalInitException.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Denotes an illegal signature for a method decorated with {@link @org.osoa.sca.annotations.Init}
+ *
+ * @version $Rev$ $Date$
+ */
+public class IllegalInitException extends ProcessingException {
+ public IllegalInitException(String message) {
+ super(message);
+ }
+
+ public IllegalInitException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalReferenceException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalReferenceException.java
new file mode 100644
index 0000000000..11137bcaba
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalReferenceException.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Denotes an illegal reference definition in a component type
+ *
+ * @version $Rev$ $Date$
+ */
+public class IllegalReferenceException extends ProcessingException {
+
+ public IllegalReferenceException(String message) {
+ super(message);
+ }
+
+ public IllegalReferenceException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalResourceException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalResourceException.java
new file mode 100644
index 0000000000..e25c1174e2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalResourceException.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Denotes an illegal resource definition in a component type
+ *
+ * @version $Rev$ $Date$
+ */
+public class IllegalResourceException extends ProcessingException {
+
+ public IllegalResourceException(String message) {
+ super(message);
+ }
+
+ public IllegalResourceException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalServiceDefinitionException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalServiceDefinitionException.java
new file mode 100644
index 0000000000..1d9079636a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/IllegalServiceDefinitionException.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Denotes an illegal use of the {@link @org.osoa.sca.annotations.Service} annotation
+ *
+ * @version $Rev$ $Date$
+ */
+public class IllegalServiceDefinitionException extends ProcessingException {
+
+ public IllegalServiceDefinitionException(String message) {
+ super(message);
+ }
+
+ public IllegalServiceDefinitionException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceImpl.java
new file mode 100644
index 0000000000..ccc947f58a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceImpl.java
@@ -0,0 +1,384 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.implementation.processor;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.util.Collection;
+import java.util.List;
+
+import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Remotable;
+
+import org.apache.tuscany.spi.databinding.extension.SimpleTypeMapperExtension;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.model.TypeInfo;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.implementation.java.DuplicatePropertyException;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+import org.apache.tuscany.spi.model.Multiplicity;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+import org.apache.tuscany.api.annotation.Resource;
+import org.apache.tuscany.core.idl.java.IllegalCallbackException;
+import static org.apache.tuscany.core.util.JavaIntrospectionHelper.getBaseName;
+
+/**
+ * The default implementation of an <code>ImplementationProcessorService</code>
+ *
+ * @version $Rev$ $Date$
+ */
+public class ImplementationProcessorServiceImpl implements ImplementationProcessorService {
+ private JavaInterfaceProcessorRegistry registry;
+ private SimpleTypeMapperExtension typeMapper = new SimpleTypeMapperExtension();
+
+ public ImplementationProcessorServiceImpl(@Reference JavaInterfaceProcessorRegistry registry) {
+ this.registry = registry;
+ }
+
+ public JavaMappedService createService(Class<?> interfaze) throws InvalidServiceContractException {
+ JavaMappedService service = new JavaMappedService();
+ // create a relative URI
+ service.setUri(URI.create("#" + interfaze.getSimpleName()));
+ service.setRemotable(interfaze.getAnnotation(Remotable.class) != null);
+ ServiceContract<?> contract = registry.introspect(interfaze);
+ service.setServiceContract(contract);
+ return service;
+ }
+
+ public void processCallback(Class<?> interfaze, ServiceContract<?> contract) throws IllegalCallbackException {
+ Callback callback = interfaze.getAnnotation(Callback.class);
+ if (callback != null && !Void.class.equals(callback.value())) {
+ Class<?> callbackClass = callback.value();
+ contract.setCallbackClass(callbackClass);
+ contract.setCallbackName(getBaseName(callbackClass));
+ } else if (callback != null && Void.class.equals(callback.value())) {
+ throw new IllegalCallbackException("No callback interface specified on annotation", interfaze.getName());
+ }
+ }
+
+ public boolean areUnique(Class[] collection) {
+ if (collection.length == 0) {
+ return true;
+ }
+ return areUnique(collection, 0);
+ }
+
+ public void addName(List<String> names, int pos, String name) {
+ if (names.size() < pos) {
+ for (int i = 0; i < pos; i++) {
+ names.add(i, "");
+ }
+ names.add(name);
+ } else if (names.size() > pos) {
+ names.remove(pos);
+ names.add(pos, name);
+ } else {
+ names.add(pos, name);
+ }
+ }
+
+ public boolean processParam(
+ Class<?> param,
+ Type genericParam,
+ Annotation[] paramAnnotations,
+ String[] constructorNames,
+ int pos,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ List<String> injectionNames) throws ProcessingException {
+ boolean processed = false;
+ for (Annotation annot : paramAnnotations) {
+ if (Property.class.equals(annot.annotationType())) {
+ processed = true;
+ processProperty(annot, constructorNames, pos, type, param, genericParam, injectionNames);
+ } else if (Reference.class.equals(annot.annotationType())) {
+ processed = true;
+ processReference(annot, constructorNames, pos, type, param, genericParam, injectionNames);
+ } else if (Resource.class.equals(annot.annotationType())) {
+ processed = true;
+ processResource((Resource) annot, constructorNames, pos, type, param, injectionNames);
+ }
+ }
+ return processed;
+ }
+
+ public boolean injectionAnnotationsPresent(Annotation[][] annots) {
+ for (Annotation[] annotations : annots) {
+ for (Annotation annotation : annotations) {
+ Class<? extends Annotation> annotType = annotation.annotationType();
+ if (annotType.equals(Property.class)
+ || annotType.equals(Reference.class)
+ || annotType.equals(Resource.class)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public JavaMappedReference createReference(String name, Member member, Class<?> paramType)
+ throws ProcessingException {
+ JavaMappedReference reference = new JavaMappedReference();
+ reference.setUri(URI.create("#" + name));
+ reference.setMember(member);
+ reference.setRequired(false);
+ ServiceContract contract;
+ try {
+ contract = registry.introspect(paramType);
+ } catch (InvalidServiceContractException e1) {
+ throw new ProcessingException(e1);
+ }
+ try {
+ processCallback(paramType, contract);
+ } catch (IllegalCallbackException e) {
+ throw new ProcessingException(e);
+ }
+ reference.setServiceContract(contract);
+ return reference;
+ }
+
+ /**
+ * Determines if all the members of a collection have unique types
+ *
+ * @param collection the collection to analyze
+ * @param start the position in the collection to start
+ * @return true if the types are unique
+ */
+ private boolean areUnique(Class[] collection, int start) {
+ Object compare = collection[start];
+ for (int i = start + 1; i < collection.length; i++) {
+ if (compare.equals(collection[i])) {
+ return false;
+ }
+ }
+ if (start + 1 < collection.length) {
+ return areUnique(collection, start + 1);
+ } else {
+ return true;
+ }
+ }
+
+ /**
+ * Processes parameter metadata for a constructor parameter
+ *
+ * @param annot the parameter annotation
+ * @param constructorNames the parameter names as specified in an {@link org.osoa.sca.annotations.Constructor}
+ * annotation
+ * @param pos the position of the parameter in the constructor's parameter list
+ * @param type the component type associated with the implementation being processed
+ * @param param the parameter type
+ * @param explicitNames the collection of injection names to update
+ * @throws ProcessingException
+ */
+ @SuppressWarnings("unchecked")
+ private void processProperty(
+ Annotation annot,
+ String[] constructorNames,
+ int pos,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ Class<?> param,
+ Type genericParam,
+ List<String> explicitNames) throws ProcessingException {
+ // the param is marked as a property
+ Property propAnnot = (Property) annot;
+ JavaMappedProperty property = new JavaMappedProperty();
+ Class<?> baseType = getBaseType(param, genericParam);
+ if (param.isArray() || Collection.class.isAssignableFrom(param)) {
+ property.setMany(true);
+ }
+ property.setJavaType(baseType);
+ String name = propAnnot.name();
+ if (name == null || name.length() == 0) {
+ if (constructorNames.length < pos + 1 || constructorNames[pos] == null
+ || constructorNames[pos].length() == 0) {
+ throw new InvalidPropertyException("No name specified for property parameter " + (pos + 1));
+ }
+ name = constructorNames[pos];
+ } else if (pos < constructorNames.length && constructorNames[pos] != null
+ && constructorNames[pos].length() != 0 && !name.equals(constructorNames[pos])) {
+ String paramNum = String.valueOf(pos + 1);
+ throw new InvalidConstructorException("Name specified by @Constructor does not match property name",
+ paramNum);
+ }
+ if (type.getProperties().get(name) != null) {
+ throw new DuplicatePropertyException(name);
+ }
+ property.setName(name);
+ property.setRequired(propAnnot.required());
+
+ TypeInfo typeInfo = typeMapper.getXMLType(property.getJavaType());
+ if (typeInfo != null) {
+ property.setXmlType(typeInfo.getQName());
+ }
+ type.getProperties().put(name, property);
+ addName(explicitNames, pos, name);
+ }
+
+ /**
+ * Processes reference metadata for a constructor parameter
+ *
+ * @param annot the parameter annotation
+ * @param constructorNames the parameter names as specified in an {@link org.osoa.sca.annotations.Constructor}
+ * annotation
+ * @param pos the position of the parameter in the constructor's parameter list
+ * @param type the component type associated with the implementation being processed
+ * @param param the parameter type
+ * @param explicitNames the collection of injection names to update
+ * @throws ProcessingException
+ */
+ private void processReference(
+ Annotation annot,
+ String[] constructorNames,
+ int pos,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ Class<?> param,
+ Type genericParam,
+ List<String> explicitNames) throws ProcessingException {
+
+ // TODO multiplicity
+ // the param is marked as a reference
+ Reference refAnnotation = (Reference) annot;
+ JavaMappedReference reference = new JavaMappedReference();
+ String name = refAnnotation.name();
+ if (name == null || name.length() == 0) {
+ if (constructorNames.length == 0 || constructorNames[0].length() == 0) {
+ name = "_ref" + pos;
+ } else if (constructorNames.length < pos + 1 || constructorNames[pos] == null
+ || constructorNames[pos].length() == 0) {
+ throw new InvalidReferenceException("No name specified for reference parameter " + (pos + 1));
+ } else {
+ name = constructorNames[pos];
+ }
+ } else if (pos < constructorNames.length && constructorNames[pos] != null
+ && constructorNames[pos].length() != 0 && !name.equals(constructorNames[pos])) {
+ String paramNum = String.valueOf(pos + 1);
+ throw new InvalidConstructorException("Name specified by @Constructor does not match reference name",
+ paramNum);
+ }
+ if (type.getReferences().get(name) != null) {
+ throw new DuplicateReferenceException(name);
+ }
+ reference.setUri(URI.create("#" + name));
+ boolean required = refAnnotation.required();
+ reference.setRequired(required);
+ try {
+ Class<?> rawType = param;
+ if (rawType.isArray() || Collection.class.isAssignableFrom(rawType)) {
+ if (required) {
+ reference.setMultiplicity(Multiplicity.ONE_N);
+ } else {
+ reference.setMultiplicity(Multiplicity.ZERO_N);
+ }
+ } else {
+ if (required) {
+ reference.setMultiplicity(Multiplicity.ONE_ONE);
+ } else {
+ reference.setMultiplicity(Multiplicity.ZERO_ONE);
+ }
+ }
+ Class<?> baseType = getBaseType(rawType, genericParam);
+ ServiceContract<?> contract = registry.introspect(baseType);
+ reference.setServiceContract(contract);
+ } catch (InvalidServiceContractException e) {
+ throw new ProcessingException(e);
+ }
+ type.getReferences().put(name, reference);
+ addName(explicitNames, pos, name);
+ }
+
+ /**
+ * Processes resource metadata for a constructor parameter
+ *
+ * @param resourceAnnot the resource annotation
+ * @param constructorNames the parameter names as specified in an {@link org.osoa.sca.annotations.Constructor}
+ * annotation
+ * @param pos the position of the parameter in the constructor's parameter list
+ * @param type the component type associated with the implementation being processed
+ * @param param the parameter type
+ * @param explicitNames the collection of injection names to update
+ * @throws ProcessingException
+ */
+ private <T> void processResource(
+ Resource resourceAnnot,
+ String[] constructorNames,
+ int pos,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ Class<T> param,
+ List<String> explicitNames) throws ProcessingException {
+
+ String name = resourceAnnot.name();
+ if (name == null || name.length() == 0) {
+ if (constructorNames.length < pos + 1 || constructorNames[pos] == null
+ || constructorNames[pos].length() == 0) {
+ String paramNum = String.valueOf(pos + 1);
+ throw new InvalidResourceException("No name specified for resource parameter", paramNum);
+ }
+ name = constructorNames[pos];
+ } else if (pos < constructorNames.length && constructorNames[pos] != null
+ && constructorNames[pos].length() != 0 && !name.equals(constructorNames[pos])) {
+ String paramNum = String.valueOf(pos + 1);
+ throw new InvalidConstructorException("Name specified by @Constructor does not match resource name",
+ paramNum);
+ }
+ if (type.getResources().get(name) != null) {
+ throw new DuplicateResourceException(name);
+ }
+ org.apache.tuscany.spi.implementation.java.Resource<T> resource =
+ new org.apache.tuscany.spi.implementation.java.Resource<T>(name, param, null);
+ resource.setOptional(resourceAnnot.optional());
+ String mappedName = resourceAnnot.mappedName();
+ if (mappedName.length() > 0) {
+ resource.setMappedName(mappedName);
+ }
+ type.add(resource);
+ addName(explicitNames, pos, name);
+ }
+
+ protected static Class<?> getBaseType(Class<?> cls, Type genericType) {
+ if (cls.isArray()) {
+ return cls.getComponentType();
+ } else if (Collection.class.isAssignableFrom(cls)) {
+ if (genericType == cls) {
+ return Object.class;
+ } else {
+ ParameterizedType parameterizedType = (ParameterizedType) genericType;
+ Type baseType = parameterizedType.getActualTypeArguments()[0];
+ if (baseType instanceof Class) {
+ return (Class<?>) baseType;
+ } else if (baseType instanceof ParameterizedType) {
+ return (Class<?>) ((ParameterizedType) baseType).getRawType();
+ } else {
+ return null;
+ }
+ }
+ } else {
+ return cls;
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InitProcessor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InitProcessor.java
new file mode 100644
index 0000000000..d78632d496
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InitProcessor.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.core.implementation.processor;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import org.osoa.sca.annotations.Init;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorExtension;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Processes the {@link @Init} annotation on a component implementation and updates the component type with the
+ * decorated initializer method
+ *
+ * @version $Rev$ $Date$
+ */
+public class InitProcessor extends ImplementationProcessorExtension {
+
+ public void visitMethod(Method method,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context)
+ throws ProcessingException {
+ Init annotation = method.getAnnotation(Init.class);
+ if (annotation == null) {
+ return;
+ }
+ if (method.getParameterTypes().length != 0) {
+ throw new IllegalInitException("Initializer must not have argments", method.toString());
+ }
+ if (type.getInitMethod() != null) {
+ throw new DuplicateInitException("More than one initializer found on implementaton");
+ }
+ if (Modifier.isProtected(method.getModifiers())) {
+ method.setAccessible(true);
+ }
+ type.setInitMethod(method);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidConstructorException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidConstructorException.java
new file mode 100644
index 0000000000..a2dd3f09c4
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidConstructorException.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Denotes an invalid constructor definition, e.g. when the number of injection names specified in {@link
+ * org.osoa.sca.annotations.Constructor} do not match the number of actual constructor parameters
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidConstructorException extends ProcessingException {
+
+ public InvalidConstructorException(String message) {
+ super(message);
+ }
+
+ public InvalidConstructorException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidConversationalImplementation.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidConversationalImplementation.java
new file mode 100644
index 0000000000..28bd65200e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidConversationalImplementation.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Raised when an implementation specifies improper conversational metadata
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidConversationalImplementation extends ProcessingException {
+
+ public InvalidConversationalImplementation(String message) {
+ super(message);
+ }
+
+ public InvalidConversationalImplementation(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public InvalidConversationalImplementation(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public InvalidConversationalImplementation(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidPropertyException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidPropertyException.java
new file mode 100644
index 0000000000..5d4c245764
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidPropertyException.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Denotes an invalid usage of {@link org.osoa.sca.annotations.Property}
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidPropertyException extends ProcessingException {
+
+ public InvalidPropertyException(String message) {
+ super(message);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidReferenceException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidReferenceException.java
new file mode 100644
index 0000000000..8fbc07aa1c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidReferenceException.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Denotes an invalid usage of {@link org.osoa.sca.annotations.Reference}
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidReferenceException extends ProcessingException {
+
+ public InvalidReferenceException(String message) {
+ super(message);
+ }
+
+ public InvalidReferenceException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public InvalidReferenceException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidResourceException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidResourceException.java
new file mode 100644
index 0000000000..4ed6d93994
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidResourceException.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Denotes an invalid usage of {@link @org.apache.tuscany.api.annotation.Resource}
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidResourceException extends ProcessingException {
+
+ public InvalidResourceException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidServiceType.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidServiceType.java
new file mode 100644
index 0000000000..f3d0367661
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/InvalidServiceType.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Thrown when a service type specified by an {@link org.osoa.sca.annotations.Service} annotation is invalid, e.g. it is
+ * not an interface
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidServiceType extends ProcessingException {
+
+ public InvalidServiceType(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/MonitorProcessor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/MonitorProcessor.java
new file mode 100644
index 0000000000..f8d560504b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/MonitorProcessor.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.core.implementation.processor;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.AbstractPropertyProcessor;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+
+import org.apache.tuscany.api.annotation.Monitor;
+import org.apache.tuscany.core.injection.SingletonObjectFactory;
+import org.apache.tuscany.host.MonitorFactory;
+
+/**
+ * Processes an {@link @Monitor} annotation, updating the component type with corresponding {@link
+ * org.apache.tuscany.spi.implementation.java.JavaMappedProperty}
+ *
+ * @version $Rev$ $Date$
+ */
+public class MonitorProcessor extends AbstractPropertyProcessor<Monitor> {
+ private MonitorFactory monitorFactory;
+
+ public MonitorProcessor(@Reference MonitorFactory factory, @Reference ImplementationProcessorService service) {
+ super(Monitor.class, service);
+ this.monitorFactory = factory;
+ }
+
+ protected String getName(Monitor annotation) {
+ return null;
+ }
+
+ protected <T> void initProperty(JavaMappedProperty<T> property,
+ Monitor annotation,
+ DeploymentContext context) {
+ Class<T> javaType = property.getJavaType();
+ property.setDefaultValueFactory(new SingletonObjectFactory<T>(monitorFactory.getMonitor(javaType)));
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/NoConstructorException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/NoConstructorException.java
new file mode 100644
index 0000000000..f36b7900a4
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/NoConstructorException.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Thrown when a suitable constructor for a component implementation cannot be found
+ *
+ * @version $Rev$ $Date$
+ */
+public class NoConstructorException extends ProcessingException {
+
+ public NoConstructorException() {
+ }
+
+ public NoConstructorException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/PropertyProcessor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/PropertyProcessor.java
new file mode 100644
index 0000000000..206c937b05
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/PropertyProcessor.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.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.databinding.extension.SimpleTypeMapperExtension;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.model.TypeInfo;
+import org.apache.tuscany.spi.implementation.java.AbstractPropertyProcessor;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Processes an {@link @Property} annotation, updating the component type with corresponding {@link JavaMappedProperty}
+ *
+ * @version $Rev$ $Date$
+ */
+public class PropertyProcessor extends AbstractPropertyProcessor<Property> {
+ private SimpleTypeMapperExtension typeMapper = new SimpleTypeMapperExtension();
+
+ public PropertyProcessor(@Reference ImplementationProcessorService service) {
+ super(Property.class, service);
+ }
+
+ protected String getName(Property annotation) {
+ return annotation.name();
+ }
+
+ protected <T> void initProperty(JavaMappedProperty<T> property,
+ Property annotation,
+ DeploymentContext context) {
+ property.setRequired(annotation.required());
+ TypeInfo type = typeMapper.getXMLType(property.getJavaType());
+ if (type != null) {
+ property.setXmlType(type.getQName());
+ }
+ }
+
+ public <T> void visitConstructor(Constructor<T> constructor,
+ PojoComponentType<JavaMappedService, JavaMappedReference,
+ JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException {
+ // override since heuristic pojo processor evalautes properties
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessor.java
new file mode 100644
index 0000000000..9ecc1c768e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessor.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.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.util.Collection;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorExtension;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+import org.apache.tuscany.spi.model.Multiplicity;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+import static org.apache.tuscany.core.util.JavaIntrospectionHelper.toPropertyName;
+
+/**
+ * Processes an {@link @Reference} annotation, updating the component type with corresponding {@link
+ * org.apache.tuscany.spi.implementation.java.JavaMappedReference}
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReferenceProcessor extends ImplementationProcessorExtension {
+
+ private JavaInterfaceProcessorRegistry regsitry;
+
+ public ReferenceProcessor(@Reference JavaInterfaceProcessorRegistry registry) {
+ this.regsitry = registry;
+ }
+
+ public void visitMethod(
+ Method method,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException {
+ Reference annotation = method.getAnnotation(Reference.class);
+ if (annotation == null) {
+ return; // Not a reference annotation.
+ }
+ if (method.getParameterTypes().length != 1) {
+ throw new IllegalReferenceException("Setter must have one parameter", method.toString());
+ }
+ String name = null;
+ if (annotation.name() != null && annotation.name().length() > 0) {
+ name = annotation.name();
+ }
+ boolean required = annotation.required();
+ if (name == null) {
+ name = toPropertyName(method.getName());
+ }
+ if (type.getReferences().get(name) != null) {
+ throw new DuplicateReferenceException(name);
+ }
+
+ JavaMappedReference reference = new JavaMappedReference();
+ reference.setMember(method);
+ reference.setRequired(required);
+ reference.setUri(URI.create("#" + name));
+ ServiceContract contract;
+ try {
+ Class<?> rawType = method.getParameterTypes()[0];
+ if (rawType.isArray() || Collection.class.isAssignableFrom(rawType)) {
+ if (required) {
+ reference.setMultiplicity(Multiplicity.ONE_N);
+ } else {
+ reference.setMultiplicity(Multiplicity.ZERO_N);
+ }
+ } else {
+ if (required) {
+ reference.setMultiplicity(Multiplicity.ONE_ONE);
+ } else {
+ reference.setMultiplicity(Multiplicity.ZERO_ONE);
+ }
+ }
+ Class<?> baseType = getBaseType(rawType, method.getGenericParameterTypes()[0]);
+ contract = regsitry.introspect(baseType);
+ } catch (InvalidServiceContractException e) {
+ throw new ProcessingException(e);
+ }
+ reference.setServiceContract(contract);
+ type.getReferences().put(name, reference);
+ }
+
+ public void visitField(
+ Field field,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException {
+ Reference annotation = field.getAnnotation(Reference.class);
+ if (annotation == null) {
+ return;
+ }
+ String name = field.getName();
+ if (annotation.name() != null) {
+ name = annotation.name();
+ }
+ boolean required = annotation.required();
+ if (name.length() == 0) {
+ name = field.getName();
+ }
+ if (type.getReferences().get(name) != null) {
+ throw new DuplicateReferenceException(name);
+ }
+ JavaMappedReference reference = new JavaMappedReference();
+ reference.setMember(field);
+ reference.setRequired(required);
+ reference.setUri(URI.create("#" + name));
+ ServiceContract contract;
+ try {
+ Class<?> rawType = field.getType();
+ if (rawType.isArray() || Collection.class.isAssignableFrom(rawType)) {
+ if (required) {
+ reference.setMultiplicity(Multiplicity.ONE_N);
+ } else {
+ reference.setMultiplicity(Multiplicity.ZERO_N);
+ }
+ } else {
+ if (required) {
+ reference.setMultiplicity(Multiplicity.ONE_ONE);
+ } else {
+ reference.setMultiplicity(Multiplicity.ZERO_ONE);
+ }
+ }
+ Class<?> baseType = getBaseType(rawType, field.getGenericType());
+ contract = regsitry.introspect(baseType);
+ } catch (InvalidServiceContractException e) {
+ throw new ProcessingException(e);
+ }
+ reference.setServiceContract(contract);
+ type.getReferences().put(name, reference);
+ }
+
+ public <T> void visitConstructor(
+ Constructor<T> constructor,
+ PojoComponentType<JavaMappedService,
+ JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException {
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ResourceProcessor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ResourceProcessor.java
new file mode 100644
index 0000000000..2db36652d0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ResourceProcessor.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.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorExtension;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+import org.apache.tuscany.spi.implementation.java.Resource;
+
+import static org.apache.tuscany.core.util.JavaIntrospectionHelper.toPropertyName;
+
+/**
+ * Processes an {@link @Resource} annotation, updating the component type with corresponding {@link
+ * org.apache.tuscany.spi.implementation.java.Resource}
+ *
+ * @version $Rev$ $Date$
+ */
+public class ResourceProcessor extends ImplementationProcessorExtension {
+
+ public ResourceProcessor() {
+ }
+
+ public void visitMethod(
+ Method method,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context)
+ throws ProcessingException {
+ org.apache.tuscany.api.annotation.Resource annotation =
+ method.getAnnotation(org.apache.tuscany.api.annotation.Resource.class);
+ if (annotation == null) {
+ return;
+ }
+ if (method.getParameterTypes().length != 1) {
+ throw new IllegalResourceException("Resource setter must have one parameter", method.toString());
+ }
+ Class<?> resourceType = method.getParameterTypes()[0];
+
+ String name = annotation.name();
+ if (name.length() < 1) {
+ name = toPropertyName(method.getName());
+ }
+ if (type.getResources().get(name) != null) {
+ throw new DuplicateResourceException(name);
+ }
+
+ String mappedName = annotation.mappedName();
+ Resource<?> resource = createResource(name, resourceType, method);
+ resource.setOptional(annotation.optional());
+ if (mappedName.length() > 0) {
+ resource.setMappedName(mappedName);
+ }
+ type.add(resource);
+ }
+
+ public void visitField(
+ Field field,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException {
+
+ org.apache.tuscany.api.annotation.Resource annotation =
+ field.getAnnotation(org.apache.tuscany.api.annotation.Resource.class);
+ if (annotation == null) {
+ return;
+ }
+ String name = annotation.name();
+ if (name.length() < 1) {
+ name = field.getName();
+ }
+ if (type.getResources().get(name) != null) {
+ throw new DuplicateResourceException(name);
+ }
+
+ Class<?> fieldType = field.getType();
+ String mappedName = annotation.mappedName();
+
+ Resource<?> resource = createResource(name, fieldType, field);
+ resource.setOptional(annotation.optional());
+ if (mappedName.length() > 0) {
+ resource.setMappedName(mappedName);
+ }
+ type.add(resource);
+ }
+
+ public <T> Resource<T> createResource(String name, Class<T> type, Member member) {
+ return new Resource<T>(name, type, member);
+ }
+
+ public <T> void visitConstructor(
+ Constructor<T> constructor,
+ PojoComponentType<JavaMappedService, JavaMappedReference,
+ JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException {
+
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ScopeProcessor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ScopeProcessor.java
new file mode 100644
index 0000000000..efd0e25cd3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ScopeProcessor.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorExtension;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+import org.apache.tuscany.spi.model.Scope;
+
+/**
+ * Processes the {@link Scope} annotation and updates the component type with the corresponding implmentation scope
+ *
+ * @version $Rev$ $Date$
+ */
+public class ScopeProcessor extends ImplementationProcessorExtension {
+
+ public <T> void visitClass(Class<T> clazz,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context)
+ throws ProcessingException {
+ org.osoa.sca.annotations.Scope annotation = clazz.getAnnotation(org.osoa.sca.annotations.Scope.class);
+ if (annotation == null) {
+ type.setImplementationScope(Scope.STATELESS);
+ return;
+ }
+ String name = annotation.value();
+ Scope scope;
+ if ("COMPOSITE".equals(name)) {
+ scope = Scope.COMPOSITE;
+ } else if ("SESSION".equals(name)) {
+ scope = Scope.SESSION;
+ } else if ("CONVERSATION".equals(name)) {
+ scope = Scope.CONVERSATION;
+ } else if ("REQUEST".equals(name)) {
+ scope = Scope.REQUEST;
+ } else if ("SYSTEM".equals(name)) {
+ scope = Scope.SYSTEM;
+ } else {
+ scope = new Scope(name);
+ }
+ type.setImplementationScope(scope);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ServiceProcessor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ServiceProcessor.java
new file mode 100644
index 0000000000..8d6e72cae3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ServiceProcessor.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.core.implementation.processor;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Set;
+
+import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Remotable;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorExtension;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+import static org.apache.tuscany.core.util.JavaIntrospectionHelper.getAllInterfaces;
+import static org.apache.tuscany.core.util.JavaIntrospectionHelper.toPropertyName;
+
+/**
+ * Processes an {@link org.osoa.sca.annotations.Service} annotation and updates the component type with corresponding
+ * {@link JavaMappedService}s. Also processes related {@link org.osoa.sca.annotations.Callback} annotations.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ServiceProcessor extends ImplementationProcessorExtension {
+
+ private ImplementationProcessorService implService;
+
+ public ServiceProcessor(@Reference ImplementationProcessorService implService) {
+ this.implService = implService;
+ }
+
+ public <T> void visitClass(Class<T> clazz,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException {
+ org.osoa.sca.annotations.Service annotation = clazz.getAnnotation(org.osoa.sca.annotations.Service.class);
+ if (annotation == null) {
+ // scan intefaces for remotable
+ Set<Class> interfaces = getAllInterfaces(clazz);
+ for (Class<?> interfaze : interfaces) {
+ if (interfaze.isAnnotationPresent(Remotable.class) || interfaze.isAnnotationPresent(Callback.class)) {
+ JavaMappedService service;
+ try {
+ service = implService.createService(interfaze);
+ } catch (InvalidServiceContractException e) {
+ throw new ProcessingException(e);
+ }
+ type.getServices().put(service.getUri().getFragment(), service);
+ }
+ }
+ return;
+ }
+ Class<?>[] interfaces = annotation.interfaces();
+ if (interfaces.length == 0) {
+ Class<?> interfaze = annotation.value();
+ if (Void.class.equals(interfaze)) {
+ throw new IllegalServiceDefinitionException("No interfaces specified");
+ } else {
+ interfaces = new Class<?>[1];
+ interfaces[0] = interfaze;
+ }
+ }
+ for (Class<?> interfaze : interfaces) {
+ if (!interfaze.isInterface()) {
+ throw new InvalidServiceType("Service must be an interface", interfaze.getName());
+ }
+ JavaMappedService service;
+ try {
+ service = implService.createService(interfaze);
+ } catch (InvalidServiceContractException e) {
+ throw new ProcessingException(e);
+ }
+ type.getServices().put(service.getUri().getFragment(), service);
+ }
+ }
+
+
+ public void visitMethod(
+ Method method,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException {
+
+ Callback annotation = method.getAnnotation(Callback.class);
+ if (annotation == null) {
+ return;
+ }
+ if (method.getParameterTypes().length != 1) {
+ throw new IllegalCallbackReferenceException("Setter must have one parameter", method.toString());
+ }
+ String name = toPropertyName(method.getName());
+ JavaMappedService callbackService = null;
+ Class<?> callbackClass = method.getParameterTypes()[0];
+ for (JavaMappedService service : type.getServices().values()) {
+ ServiceContract serviceContract = service.getServiceContract();
+ if (serviceContract.getCallbackClass().equals(callbackClass)) {
+ callbackService = service;
+ }
+ }
+ if (callbackService == null) {
+ throw new IllegalCallbackReferenceException("Callback type does not match a service callback interface");
+ }
+ callbackService.setCallbackReferenceName(name);
+ callbackService.setCallbackMember(method);
+ }
+
+ public void visitField(Field field,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException {
+
+ Callback annotation = field.getAnnotation(Callback.class);
+ if (annotation == null) {
+ return;
+ }
+ String name = field.getName();
+ JavaMappedService callbacksService = null;
+ Class<?> callbackClass = field.getType();
+ for (JavaMappedService service : type.getServices().values()) {
+ ServiceContract serviceContract = service.getServiceContract();
+ if (serviceContract.getCallbackClass().equals(callbackClass)) {
+ callbacksService = service;
+ }
+ }
+ if (callbacksService == null) {
+ throw new IllegalCallbackReferenceException("Callback type does not match a service callback interface");
+ }
+ callbacksService.setCallbackReferenceName(name);
+ callbacksService.setCallbackMember(field);
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ServiceTypeNotFoundException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ServiceTypeNotFoundException.java
new file mode 100644
index 0000000000..8a0d4afc3d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/ServiceTypeNotFoundException.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+/**
+ * Thrown when a service interface cannot be determined based on a heuristic evaluation of an implementation
+ *
+ * @version $Rev$ $Date$
+ */
+public class ServiceTypeNotFoundException extends ProcessingException {
+
+ public ServiceTypeNotFoundException(String message) {
+ super(message);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/UnknownContextTypeException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/UnknownContextTypeException.java
new file mode 100644
index 0000000000..a7868349a6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/processor/UnknownContextTypeException.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.core.implementation.processor;
+
+/**
+ * Thrown when a method or field marked with {@link org.osoa.sca.annotations.Context} takes an unknown type
+ *
+ * @version $Rev$ $Date$
+ */
+public class UnknownContextTypeException extends IllegalContextException {
+
+ public UnknownContextTypeException(String message) {
+ super(message);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/builder/SystemComponentBuilder.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/builder/SystemComponentBuilder.java
new file mode 100644
index 0000000000..ad2e586e95
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/builder/SystemComponentBuilder.java
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.system.builder;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.Map;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.builder.BuilderConfigException;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentBuilderExtension;
+import org.apache.tuscany.spi.host.ResourceHost;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.Resource;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.PropertyValue;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.system.component.SystemAtomicComponentImpl;
+import org.apache.tuscany.core.implementation.system.model.SystemImplementation;
+import org.apache.tuscany.core.injection.MethodEventInvoker;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.injection.ResourceObjectFactory;
+
+/**
+ * Produces system atomic components from a component definition
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class SystemComponentBuilder extends ComponentBuilderExtension<SystemImplementation> {
+ private ResourceHost host;
+
+ protected Class<SystemImplementation> getImplementationType() {
+ return SystemImplementation.class;
+ }
+
+ @Reference
+ public void setHost(ResourceHost host) {
+ this.host = host;
+ }
+
+ @SuppressWarnings("unchecked")
+ public AtomicComponent build(ComponentDefinition<SystemImplementation> definition, DeploymentContext context)
+ throws BuilderConfigException {
+
+ PojoComponentType<ServiceDefinition, JavaMappedReference, JavaMappedProperty<?>> componentType =
+ definition.getImplementation().getComponentType();
+
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setGroupId(context.getGroupId());
+ if (definition.getInitLevel() != null) {
+ configuration.setInitLevel(definition.getInitLevel());
+ } else {
+ configuration.setInitLevel(componentType.getInitLevel());
+ }
+ Method initMethod = componentType.getInitMethod();
+ if (initMethod != null) {
+ configuration.setInitInvoker(new MethodEventInvoker<Object>(initMethod));
+ }
+ Method destroyMethod = componentType.getDestroyMethod();
+ if (destroyMethod != null) {
+ configuration.setDestroyInvoker(new MethodEventInvoker<Object>(destroyMethod));
+ }
+ // setup property injection sites
+ for (JavaMappedProperty<?> property : componentType.getProperties().values()) {
+ configuration.addPropertySite(property.getName(), property.getMember());
+ }
+ // setup reference injection sites
+ for (JavaMappedReference reference : componentType.getReferences().values()) {
+ Member member = reference.getMember();
+ if (member != null) {
+ // could be null if the reference is mapped to a constructor
+ configuration.addReferenceSite(reference.getUri().getFragment(), member);
+ }
+ }
+
+ for (Resource resource : componentType.getResources().values()) {
+ Member member = resource.getMember();
+ if (member != null) {
+ // could be null if the resource is mapped to a constructor
+ configuration.addResourceSite(resource.getName(), member);
+ }
+ }
+
+ // setup constructor injection
+ ConstructorDefinition<?> ctorDef = componentType.getConstructorDefinition();
+ Constructor<?> constr = ctorDef.getConstructor();
+ PojoObjectFactory<?> instanceFactory = new PojoObjectFactory(constr);
+ configuration.setInstanceFactory(instanceFactory);
+ configuration.getConstructorParamNames().addAll(ctorDef.getInjectionNames());
+ for (Class<?> clazz : constr.getParameterTypes()) {
+ configuration.addConstructorParamType(clazz);
+ }
+ configuration.setName(definition.getUri());
+ SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration);
+ // handle properties
+ Map<String, PropertyValue<?>> propertyValues = definition.getPropertyValues();
+ processProperties(propertyValues, componentType.getProperties().values(), component);
+
+ // handle resources
+ for (Resource resource : componentType.getResources().values()) {
+ String name = resource.getName();
+ boolean optional = resource.isOptional();
+ Class<Object> type = (Class<Object>) resource.getType();
+ ResourceObjectFactory<Object> factory;
+ String mappedName = resource.getMappedName();
+ if (mappedName == null) {
+ // by type
+ factory = new ResourceObjectFactory<Object>(type, optional, host);
+ } else {
+ factory = new ResourceObjectFactory<Object>(type, mappedName, optional, host);
+ }
+ component.addResourceFactory(name, factory);
+
+ }
+ return component;
+ }
+
+ private void processProperties(Map<String, PropertyValue<?>> propertyValues,
+ Collection<JavaMappedProperty<?>> properties,
+ SystemAtomicComponentImpl component) {
+ for (JavaMappedProperty<?> property : properties) {
+ PropertyValue value = propertyValues.get(property.getName());
+ ObjectFactory<?> factory;
+ if (value != null) {
+ factory = value.getValueFactory();
+ } else {
+ factory = property.getDefaultValueFactory();
+ }
+ if (factory != null) {
+ component.addPropertyFactory(property.getName(), factory);
+ }
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/builder/SystemPhysicalComponentBuilder.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/builder/SystemPhysicalComponentBuilder.java
new file mode 100644
index 0000000000..dc37987221
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/builder/SystemPhysicalComponentBuilder.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.core.implementation.system.builder;
+
+import java.net.URI;
+
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Service;
+import org.osoa.sca.annotations.Init;
+
+import org.apache.tuscany.core.component.InstanceFactoryProvider;
+import org.apache.tuscany.core.component.instancefactory.IFProviderBuilderRegistry;
+import org.apache.tuscany.core.implementation.POJOPhysicalComponentBuilder;
+import org.apache.tuscany.core.implementation.system.component.SystemComponent;
+import org.apache.tuscany.core.implementation.system.model.SystemPhysicalComponentDefinition;
+import org.apache.tuscany.core.implementation.system.model.SystemPhysicalWireSourceDefinition;
+import org.apache.tuscany.core.implementation.system.model.SystemPhysicalWireTargetDefinition;
+import org.apache.tuscany.core.model.physical.instancefactory.InjectionSource;
+import static org.apache.tuscany.core.model.physical.instancefactory.InjectionSource.ValueSourceType.REFERENCE;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.builder.WiringException;
+import org.apache.tuscany.spi.builder.physical.PhysicalComponentBuilder;
+import org.apache.tuscany.spi.builder.physical.PhysicalComponentBuilderRegistry;
+import org.apache.tuscany.spi.builder.physical.WireAttacher;
+import org.apache.tuscany.spi.builder.physical.WireAttacherRegistry;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.physical.InstanceFactoryProviderDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition;
+import org.apache.tuscany.spi.services.classloading.ClassLoaderRegistry;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+@Service(interfaces = {PhysicalComponentBuilder.class, WireAttacher.class})
+public class SystemPhysicalComponentBuilder<T>
+ extends POJOPhysicalComponentBuilder<SystemPhysicalComponentDefinition<T>, SystemComponent<T>>
+ implements WireAttacher<SystemComponent, SystemPhysicalWireSourceDefinition, SystemPhysicalWireTargetDefinition> {
+
+ public SystemPhysicalComponentBuilder(
+ @Reference(name = "builderRegistry")PhysicalComponentBuilderRegistry builderRegistry,
+ @Reference(name = "wireAttacherRegistry")WireAttacherRegistry wireAttacherRegistry,
+ @Reference(name = "scopeRegistry")ScopeRegistry scopeRegistry,
+ @Reference(name = "providerBuilders")IFProviderBuilderRegistry providerBuilders,
+ @Reference(name = "classloaderRegistry")ClassLoaderRegistry classLoaderRegistry) {
+ super(builderRegistry, wireAttacherRegistry, scopeRegistry, providerBuilders, classLoaderRegistry);
+ }
+
+ @Init
+ public void init() {
+ builderRegistry.register(SystemPhysicalComponentDefinition.class, this);
+ wireAttacherRegistry.register(SystemPhysicalWireSourceDefinition.class, this);
+ wireAttacherRegistry.register(SystemPhysicalWireTargetDefinition.class, this);
+ }
+
+ public SystemComponent<T> build(SystemPhysicalComponentDefinition<T> definition) throws BuilderException {
+ URI componentId = definition.getComponentId();
+ int initLevel = definition.getInitLevel();
+ URI groupId = definition.getGroupId();
+ ClassLoader classLoader = classLoaderRegistry.getClassLoader(definition.getClassLoaderId());
+
+ // get the scope container for this component
+ Scope scope = definition.getScope();
+ ScopeContainer<?> scopeContainer = scopeRegistry.getScopeContainer(scope);
+
+ // create the InstanceFactoryProvider based on the definition in the model
+ InstanceFactoryProviderDefinition<T> providerDefinition = definition.getInstanceFactoryProviderDefinition();
+ InstanceFactoryProvider<T> provider = providerBuilders.build(providerDefinition, classLoader);
+
+ return new SystemComponent<T>(componentId, provider, scopeContainer, groupId, initLevel, -1, -1);
+ }
+
+ public void attachToSource(SystemComponent source,
+ SystemPhysicalWireSourceDefinition sourceDefinition, Component target,
+ PhysicalWireTargetDefinition targetDefinition, Wire wire
+ ) throws WiringException {
+ assert target instanceof AtomicComponent;
+ AtomicComponent<?> targetComponent = (AtomicComponent<?>) target;
+ URI sourceUri = sourceDefinition.getUri();
+ InjectionSource referenceSource = new InjectionSource(REFERENCE, sourceUri.getFragment());
+ ObjectFactory<?> factory = targetComponent.createObjectFactory();
+ source.setObjectFactory(referenceSource, factory);
+ }
+
+ public void attachToTarget(Component source, PhysicalWireSourceDefinition sourceDefinition, SystemComponent component,
+ SystemPhysicalWireTargetDefinition targetDefinition, Wire wire
+ ) throws WiringException {
+ // nothing to do here as the wire will always be optimized
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentImpl.java
new file mode 100644
index 0000000000..f8462b154c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentImpl.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.core.implementation.system.component;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+import org.apache.tuscany.core.implementation.PojoAtomicComponent;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.wire.OptimizedWireObjectFactory;
+
+/**
+ * Default implementation of a system atomic context
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class SystemAtomicComponentImpl extends PojoAtomicComponent {
+
+ public SystemAtomicComponentImpl(PojoConfiguration configuration) {
+ super(configuration);
+ scope = Scope.COMPOSITE;
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, Operation operation) {
+ return null;
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, PhysicalOperationDefinition operation)
+ throws TargetInvokerCreationException {
+ return null;
+ }
+
+ protected <B> ObjectFactory<B> createWireFactory(Class<B> interfaze, Wire wire) {
+ return new OptimizedWireObjectFactory<B>(interfaze, wire);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/component/SystemComponent.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/component/SystemComponent.java
new file mode 100644
index 0000000000..09aad9b607
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/component/SystemComponent.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.core.implementation.system.component;
+
+import java.net.URI;
+
+import org.apache.tuscany.core.component.InstanceFactoryProvider;
+import org.apache.tuscany.core.implementation.PojoComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+
+/**
+ * @version $Rev$ $Date$
+ * @param <T> the implementation class for the defined component
+ */
+public class SystemComponent<T> extends PojoComponent<T> {
+ public SystemComponent(URI componentId,
+ InstanceFactoryProvider<T> provider,
+ ScopeContainer<?> scopeContainer,
+ URI groupId,
+ int initLevel,
+ int maxIdleTime,
+ int maxAge) {
+ super(componentId, provider, scopeContainer, groupId, initLevel, maxIdleTime, maxAge);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/generator/SystemPhysicalComponentGenerator.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/generator/SystemPhysicalComponentGenerator.java
new file mode 100644
index 0000000000..1033bafe5c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/generator/SystemPhysicalComponentGenerator.java
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.system.generator;
+
+import java.lang.annotation.ElementType;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.util.Map;
+
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.generator.ComponentGenerator;
+import org.apache.tuscany.spi.generator.GenerationException;
+import org.apache.tuscany.spi.generator.GeneratorContext;
+import org.apache.tuscany.spi.generator.GeneratorRegistry;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition;
+
+import org.apache.tuscany.core.implementation.system.model.SystemImplementation;
+import org.apache.tuscany.core.implementation.system.model.SystemPhysicalComponentDefinition;
+import org.apache.tuscany.core.model.physical.instancefactory.InjectionSiteMapping;
+import org.apache.tuscany.core.model.physical.instancefactory.InjectionSource;
+import org.apache.tuscany.core.model.physical.instancefactory.MemberSite;
+import org.apache.tuscany.core.model.physical.instancefactory.ReflectiveIFProviderDefinition;
+import org.apache.tuscany.core.model.physical.java.JavaPhysicalWireSourceDefinition;
+import org.apache.tuscany.core.model.physical.java.JavaPhysicalWireTargetDefinition;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+public class SystemPhysicalComponentGenerator implements ComponentGenerator<ComponentDefinition<SystemImplementation>> {
+
+
+ public SystemPhysicalComponentGenerator(@Reference GeneratorRegistry registry) {
+ registry.register(SystemImplementation.class, this);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void generate(ComponentDefinition<SystemImplementation> definition, GeneratorContext context) {
+ SystemImplementation implementation = definition.getImplementation();
+ // TODO not a safe cast
+ PojoComponentType<JavaMappedService, JavaMappedReference, Property<?>> type = implementation.getComponentType();
+ SystemPhysicalComponentDefinition pDefinition = new SystemPhysicalComponentDefinition();
+ pDefinition.setComponentId(definition.getUri());
+ // set the classloader id temporarily until multiparent classloading is in palce
+ pDefinition.setClassLoaderId(URI.create("sca://./bootClassLoader"));
+ pDefinition.setScope(type.getImplementationScope());
+ // TODO get classloader id
+ ReflectiveIFProviderDefinition provider = new ReflectiveIFProviderDefinition();
+ Method destroyMethod = type.getDestroyMethod();
+ if (destroyMethod != null) {
+ provider.setDestroyMethod(destroyMethod.toString());
+ }
+ Method initMethod = type.getInitMethod();
+ if (initMethod != null) {
+ provider.setInitMethod(initMethod.toString());
+ }
+ provider.setImplementationClass(implementation.getImplementationClass().getName());
+ // TODO ctor arguments
+ // TODO set CDI source for ref, props, and callbacks
+ Map<String, JavaMappedReference> references = type.getReferences();
+ for (Map.Entry<String, JavaMappedReference> entry : references.entrySet()) {
+ JavaMappedReference reference = entry.getValue();
+ Member member = reference.getMember();
+ InjectionSource source = new InjectionSource();
+ source.setName(entry.getKey());
+ source.setValueType(InjectionSource.ValueSourceType.REFERENCE);
+ MemberSite memberSite = new MemberSite();
+ memberSite.setName(member.getName());
+ if (member instanceof Method) {
+ memberSite.setElementType(ElementType.METHOD);
+ } else if (member instanceof Field) {
+ memberSite.setElementType(ElementType.FIELD);
+ } else {
+ throw new AssertionError("Illegal injection type");
+ }
+
+ InjectionSiteMapping mapping = new InjectionSiteMapping();
+ mapping.setSource(source);
+ mapping.setSite(memberSite);
+ provider.addInjectionSite(mapping);
+ }
+
+ pDefinition.setInstanceFactoryProviderDefinition(provider);
+ context.getPhysicalChangeSet().addComponentDefinition(pDefinition);
+ }
+
+ public PhysicalWireSourceDefinition generateWireSource(ComponentDefinition<SystemImplementation> definition,
+ ReferenceDefinition serviceDefinition,
+ boolean optimizable, GeneratorContext context)
+ throws GenerationException {
+ JavaPhysicalWireSourceDefinition wireDefinition = new JavaPhysicalWireSourceDefinition();
+ wireDefinition.setUri(definition.getUri());
+ wireDefinition.setOptimizable(true);
+ return wireDefinition;
+ }
+
+ public PhysicalWireTargetDefinition generateWireTarget(ComponentDefinition<SystemImplementation> definition,
+ ServiceDefinition serviceDefinition,
+ GeneratorContext context)
+ throws GenerationException {
+ JavaPhysicalWireTargetDefinition wireDefinition = new JavaPhysicalWireTargetDefinition();
+ wireDefinition.setUri(definition.getUri());
+ return wireDefinition;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/loader/SystemComponentTypeLoader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/loader/SystemComponentTypeLoader.java
new file mode 100644
index 0000000000..05fbd42e22
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/loader/SystemComponentTypeLoader.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.core.implementation.system.loader;
+
+import java.net.URL;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentTypeLoaderExtension;
+import org.apache.tuscany.spi.implementation.java.IntrospectionRegistry;
+import org.apache.tuscany.spi.implementation.java.Introspector;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.Scope;
+
+import org.apache.tuscany.core.implementation.system.model.SystemImplementation;
+import org.apache.tuscany.core.util.JavaIntrospectionHelper;
+
+/**
+ * Loads a system component type
+ *
+ * @version $Rev$ $Date$
+ */
+public class SystemComponentTypeLoader extends ComponentTypeLoaderExtension<SystemImplementation> {
+ private Introspector introspector;
+
+ public SystemComponentTypeLoader() {
+ }
+
+ public SystemComponentTypeLoader(Introspector introspector) {
+ this.introspector = introspector;
+ }
+
+ public SystemComponentTypeLoader(LoaderRegistry loaderRegistry, Introspector introspector) {
+ super(loaderRegistry);
+ this.introspector = introspector;
+ }
+
+ @Reference
+ public void setIntrospector(IntrospectionRegistry introspector) {
+ this.introspector = introspector;
+ }
+
+ public void load(
+ SystemImplementation implementation,
+ DeploymentContext deploymentContext) throws LoaderException {
+ Class<?> implClass = implementation.getImplementationClass();
+ URL sidefile = implClass.getResource(JavaIntrospectionHelper.getBaseName(implClass) + ".componentType");
+ PojoComponentType componentType;
+ if (sidefile == null) {
+ componentType = loadByIntrospection(implementation, deploymentContext);
+ } else {
+ componentType = loadFromSidefile(sidefile, deploymentContext);
+ }
+ // this means system components are always composite scoped
+ componentType.setImplementationScope(Scope.COMPOSITE);
+ implementation.setComponentType(componentType);
+ }
+
+ protected Class<SystemImplementation> getImplementationClass() {
+ return SystemImplementation.class;
+ }
+
+ protected PojoComponentType loadByIntrospection(SystemImplementation implementation, DeploymentContext context)
+ throws ProcessingException {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> componentType =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Class<?> implClass = implementation.getImplementationClass();
+ introspector.introspect(implClass, componentType, context);
+ return componentType;
+ }
+
+
+ protected PojoComponentType loadFromSidefile(URL url, DeploymentContext deploymentContext) throws LoaderException {
+ return loaderRegistry.load(null, url, PojoComponentType.class, deploymentContext);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/loader/SystemCompositeComponentTypeLoader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/loader/SystemCompositeComponentTypeLoader.java
new file mode 100644
index 0000000000..7a6e1b5c83
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/loader/SystemCompositeComponentTypeLoader.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.core.implementation.system.loader;
+
+import java.net.URI;
+import java.net.URL;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentTypeLoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+
+import org.apache.tuscany.core.deployer.ChildDeploymentContext;
+import org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation;
+
+/**
+ * Loads a system composite component type
+ *
+ * @version $Rev$ $Date$
+ */
+public class SystemCompositeComponentTypeLoader extends ComponentTypeLoaderExtension<SystemCompositeImplementation> {
+ public SystemCompositeComponentTypeLoader() {
+ }
+
+ public SystemCompositeComponentTypeLoader(LoaderRegistry loaderRegistry) {
+ super(loaderRegistry);
+ }
+
+ protected Class<SystemCompositeImplementation> getImplementationClass() {
+ return SystemCompositeImplementation.class;
+ }
+
+ public void load(
+ SystemCompositeImplementation implementation,
+ DeploymentContext deploymentContext)
+ throws LoaderException {
+ URL scdlLocation = implementation.getScdlLocation();
+ if (scdlLocation == null) {
+ throw new LoaderException("SCDL location not found");
+ }
+ ClassLoader cl = implementation.getClassLoader();
+ URI componentId = deploymentContext.getComponentId();
+ DeploymentContext childContext = new ChildDeploymentContext(deploymentContext,
+ cl,
+ scdlLocation,
+ componentId,
+ deploymentContext.isAutowire());
+ CompositeComponentType componentType = loadFromSidefile(scdlLocation, childContext);
+ implementation.setComponentType(componentType);
+ }
+
+
+ protected CompositeComponentType loadFromSidefile(URL url, DeploymentContext context) throws LoaderException {
+ return loaderRegistry.load(null, url, CompositeComponentType.class, context);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/loader/SystemImplementationLoader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/loader/SystemImplementationLoader.java
new file mode 100644
index 0000000000..f2dd88bfcc
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/loader/SystemImplementationLoader.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.core.implementation.system.loader;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.LoaderUtil;
+import org.apache.tuscany.spi.loader.UnrecognizedElementException;
+import org.apache.tuscany.spi.model.ModelObject;
+
+import org.apache.tuscany.core.implementation.system.model.SystemImplementation;
+
+/**
+ * Loads information for a system implementation
+ *
+ * @version $Rev$ $Date$
+ */
+public class SystemImplementationLoader extends LoaderExtension<SystemImplementation> {
+ public static final QName SYSTEM_IMPLEMENTATION =
+ new QName("http://tuscany.apache.org/xmlns/sca/system/2.0-alpha", "implementation.system");
+
+ public SystemImplementationLoader(@Reference LoaderRegistry registry) {
+ super(registry);
+ }
+
+ public SystemImplementation load(
+ ModelObject object, XMLStreamReader reader,
+ DeploymentContext deploymentContext)
+ throws XMLStreamException, LoaderException {
+ assert SYSTEM_IMPLEMENTATION.equals(reader.getName());
+ SystemImplementation implementation = new SystemImplementation();
+ String implClass = reader.getAttributeValue(null, "class");
+ Class<?> implementationClass = LoaderUtil.loadClass(implClass, deploymentContext.getClassLoader());
+ implementation.setImplementationClass(implementationClass);
+ registry.loadComponentType(implementation, deploymentContext);
+ while (true) {
+ int code = reader.next();
+ if (code == XMLStreamConstants.START_ELEMENT) {
+ throw new UnrecognizedElementException(reader.getName());
+ } else if (code == XMLStreamConstants.END_ELEMENT) {
+ return implementation;
+ }
+ }
+ }
+
+ public QName getXMLType() {
+ return SYSTEM_IMPLEMENTATION;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/model/SystemCompositeImplementation.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/model/SystemCompositeImplementation.java
new file mode 100644
index 0000000000..e634609c5b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/model/SystemCompositeImplementation.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.core.implementation.system.model;
+
+import java.net.URL;
+
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.Implementation;
+
+/**
+ * Represents a system composite type
+ *
+ * @version $Rev$ $Date$
+ */
+public class SystemCompositeImplementation extends Implementation<CompositeComponentType> {
+ private URL scdlLocation;
+ private ClassLoader classLoader;
+
+ public SystemCompositeImplementation() {
+ }
+
+ public SystemCompositeImplementation(CompositeComponentType componentType) {
+ super(componentType);
+ }
+
+ public URL getScdlLocation() {
+ return scdlLocation;
+ }
+
+ public void setScdlLocation(URL scdlLocation) {
+ this.scdlLocation = scdlLocation;
+ }
+
+ public ClassLoader getClassLoader() {
+ return classLoader;
+ }
+
+ public void setClassLoader(ClassLoader classLoader) {
+ this.classLoader = classLoader;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/model/SystemImplementation.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/model/SystemImplementation.java
new file mode 100644
index 0000000000..ce48ed3fe5
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/model/SystemImplementation.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.core.implementation.system.model;
+
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.AtomicImplementation;
+
+/**
+ * Represents the system composite implementation
+ *
+ * @version $Rev$ $Date$
+ */
+public class SystemImplementation extends AtomicImplementation<PojoComponentType> {
+ private Class<?> implementationClass;
+
+ public SystemImplementation(PojoComponentType componentType, Class<?> implementationClass) {
+ super(componentType);
+ this.implementationClass = implementationClass;
+ }
+
+ public SystemImplementation() {
+ }
+
+ public SystemImplementation(Class<?> implementationClass) {
+ this.implementationClass = implementationClass;
+ }
+
+ public Class<?> getImplementationClass() {
+ return implementationClass;
+ }
+
+ public void setImplementationClass(Class<?> implementationClass) {
+ this.implementationClass = implementationClass;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/model/SystemPhysicalComponentDefinition.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/model/SystemPhysicalComponentDefinition.java
new file mode 100644
index 0000000000..1d2c818896
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/model/SystemPhysicalComponentDefinition.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.core.implementation.system.model;
+
+import org.apache.tuscany.core.component.InstanceFactoryProvider;
+import org.apache.tuscany.spi.model.physical.PhysicalComponentDefinition;
+import org.apache.tuscany.spi.model.physical.POJOComponentDefinition;
+
+/**
+ * @version $Rev$ $Date$
+ * @param <T> the implementation class for the defined component
+ */
+public class SystemPhysicalComponentDefinition<T> extends POJOComponentDefinition<T> {
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/model/SystemPhysicalWireSourceDefinition.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/model/SystemPhysicalWireSourceDefinition.java
new file mode 100644
index 0000000000..fcb5f7ae36
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/model/SystemPhysicalWireSourceDefinition.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.core.implementation.system.model;
+
+import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition;
+
+/**
+ * Models a System physical wire source definition.
+ *
+ * @version $Revision$ $Date: 2007-02-28 06:29:37 +0000 (Wed, 28 Feb
+ * 2007) $
+ */
+public class SystemPhysicalWireSourceDefinition extends PhysicalWireSourceDefinition {
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/model/SystemPhysicalWireTargetDefinition.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/model/SystemPhysicalWireTargetDefinition.java
new file mode 100644
index 0000000000..947ed21d0d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/implementation/system/model/SystemPhysicalWireTargetDefinition.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.core.implementation.system.model;
+
+import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition;
+
+/**
+ * Models a Java physical wire target definition.
+ *
+ * @version $Revision$ $Date: 2007-02-28 06:29:37 +0000 (Wed, 28 Feb
+ * 2007) $
+ */
+public class SystemPhysicalWireTargetDefinition extends PhysicalWireTargetDefinition {
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ArrayMultiplicityObjectFactory.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ArrayMultiplicityObjectFactory.java
new file mode 100644
index 0000000000..1a441dcf87
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ArrayMultiplicityObjectFactory.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.core.injection;
+
+import java.lang.reflect.Array;
+import java.util.List;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+
+/**
+ * Resolves targets configured in a multiplicity by delegating to object factories and returning an <code>Array</code>
+ * containing object instances
+ *
+ * @version $Rev$ $Date$
+ */
+public class ArrayMultiplicityObjectFactory implements ObjectFactory<Object> {
+
+ private ObjectFactory[] factories;
+
+ private Class interfaceType;
+
+ public ArrayMultiplicityObjectFactory(Class interfaceType, List<ObjectFactory<?>> factories) {
+ assert interfaceType != null : "Interface type was null";
+ assert factories != null : "Object factories were null";
+ this.interfaceType = interfaceType;
+ this.factories = factories.toArray(new ObjectFactory[factories.size()]);
+ }
+
+ public Object getInstance() throws ObjectCreationException {
+ Object array = Array.newInstance(interfaceType, factories.length);
+ for (int i = 0; i < factories.length; i++) {
+ Array.set(array, i, factories[i].getInstance());
+ }
+ return array;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory.java
new file mode 100644
index 0000000000..519397e9ff
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory.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.core.injection;
+
+import java.util.List;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.ProxyService;
+
+/**
+ * Returns proxy instance for a wire callback
+ *
+ * @version $Rev$ $Date$
+ */
+public class CallbackWireObjectFactory implements ObjectFactory {
+ private ProxyService proxyService;
+ private Class<?> interfaze;
+ private List<Wire> wires;
+
+ public CallbackWireObjectFactory(Class<?> interfaze, ProxyService proxyService, List<Wire> wires) {
+ this.interfaze = interfaze;
+ this.proxyService = proxyService;
+ this.wires = wires;
+ }
+
+ public Object getInstance() throws ObjectCreationException {
+ return proxyService.createCallbackProxy(interfaze, wires);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory2.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory2.java
new file mode 100644
index 0000000000..27494ece2e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory2.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.core.injection;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.wire.ProxyService;
+
+/**
+ * Returns proxy instance for a wire callback
+ *
+ * @version $Rev$ $Date$
+ */
+public class CallbackWireObjectFactory2<T> implements ObjectFactory {
+ private ProxyService proxyService;
+ private Class<T> interfaze;
+
+ public CallbackWireObjectFactory2(Class<T> interfaze, ProxyService proxyService) {
+ this.interfaze = interfaze;
+ this.proxyService = proxyService;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public T getInstance() throws ObjectCreationException {
+ return (T) proxyService.createCallbackProxy(interfaze);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ContextInjector.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ContextInjector.java
new file mode 100644
index 0000000000..a422500f3c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ContextInjector.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.core.injection;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+
+/**
+ * Implementations inject a pre-configured context type (interface) on an instance.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ContextInjector<S, T> extends Injector<T> {
+
+ void setContext(S context) throws ObjectCreationException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ConversationIDObjectFactory.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ConversationIDObjectFactory.java
new file mode 100644
index 0000000000..8dbc0a3a83
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ConversationIDObjectFactory.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.core.injection;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
+
+public class ConversationIDObjectFactory implements ObjectFactory<String> {
+
+ private WorkContext workContext;
+
+ public ConversationIDObjectFactory(WorkContext workContext) {
+ this.workContext = workContext;
+ }
+
+ public String getInstance() {
+ return (String)workContext.getIdentifier(Scope.CONVERSATION);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/EventInvoker.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/EventInvoker.java
new file mode 100644
index 0000000000..af2382b36a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/EventInvoker.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.core.injection;
+
+/**
+ * Performs an invocation on an instance
+ *
+ * @version $Rev$ $Date$
+ */
+public interface EventInvoker<T> {
+
+ /**
+ * Performs the invocation on a given instance
+ *
+ * @throws ObjectCallbackException
+ */
+ void invokeEvent(T instance) throws ObjectCallbackException;
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/FieldInjector.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/FieldInjector.java
new file mode 100644
index 0000000000..e9f8f42aa1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/FieldInjector.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.core.injection;
+
+import java.lang.reflect.Field;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+
+/**
+ * Injects a value created by an {@link org.apache.tuscany.spi.ObjectFactory} on a given field
+ *
+ * @version $Rev$ $Date$
+ */
+public class FieldInjector<T> implements Injector<T> {
+
+ private final Field field;
+
+ private final ObjectFactory<?> objectFactory;
+
+ /**
+ * Create an injector and have it use the given <code>ObjectFactory</code> to inject a value on the instance using
+ * the reflected <code>Field</code>
+ */
+ public FieldInjector(Field field, ObjectFactory<?> objectFactory) {
+ this.field = field;
+ this.field.setAccessible(true);
+ this.objectFactory = objectFactory;
+ }
+
+ /**
+ * Inject a new value on the given isntance
+ */
+ public void inject(T instance) throws ObjectCreationException {
+ try {
+ field.set(instance, objectFactory.getInstance());
+ } catch (IllegalAccessException e) {
+ throw new AssertionError("Field is not accessible [" + field + "]");
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/InjectionRuntimeException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/InjectionRuntimeException.java
new file mode 100644
index 0000000000..c5f037d931
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/InjectionRuntimeException.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.core.injection;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * Root unchecked exception for the injection package
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class InjectionRuntimeException extends TuscanyRuntimeException {
+
+ public InjectionRuntimeException() {
+ super();
+ }
+
+ public InjectionRuntimeException(String message) {
+ super(message);
+ }
+
+
+ protected InjectionRuntimeException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public InjectionRuntimeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ protected InjectionRuntimeException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+
+ public InjectionRuntimeException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/Injector.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/Injector.java
new file mode 100644
index 0000000000..c2125d8212
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/Injector.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.core.injection;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+
+/**
+ * Implementations inject a pre-configured value on an instance
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Injector<T> {
+
+ /**
+ * Inject a value on the given instance
+ */
+ void inject(T instance) throws ObjectCreationException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/InvalidAccessorException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/InvalidAccessorException.java
new file mode 100644
index 0000000000..2e7ff0e754
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/InvalidAccessorException.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.core.injection;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public class InvalidAccessorException extends InjectionRuntimeException {
+
+ public InvalidAccessorException(String message) {
+ super(message);
+ }
+
+ public InvalidAccessorException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/InvalidResourceTypeException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/InvalidResourceTypeException.java
new file mode 100644
index 0000000000..1a3eaf4d1a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/InvalidResourceTypeException.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.core.injection;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+
+/**
+ * Denotes an invalid resource type, i.e. that is not a component
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidResourceTypeException extends ObjectCreationException {
+
+ public InvalidResourceTypeException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/JNDIObjectFactory.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/JNDIObjectFactory.java
new file mode 100644
index 0000000000..0189d8245b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/JNDIObjectFactory.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.core.injection;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+
+/**
+ * An implementation of ObjectFactory that creates instances by looking them up in a JNDI context.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JNDIObjectFactory<T> implements ObjectFactory<T> {
+ private final Context context;
+ private final String name;
+
+ public JNDIObjectFactory(Context context, String name) {
+ this.context = context;
+ this.name = name;
+ }
+
+
+ @SuppressWarnings("unchecked")
+ public T getInstance() throws ObjectCreationException {
+ try {
+ return (T) context.lookup(name);
+ } catch (NamingException e) {
+ throw new ObjectCreationException(e);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ListMultiplicityObjectFactory.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ListMultiplicityObjectFactory.java
new file mode 100644
index 0000000000..b261bcda53
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ListMultiplicityObjectFactory.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.core.injection;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+
+/**
+ * Resolves targets configured in a multiplicity by delegating to object factories and returning an <code>List</code>
+ * containing object instances
+ *
+ * @version $Rev$ $Date$
+ */
+public class ListMultiplicityObjectFactory implements ObjectFactory<List> {
+
+ private ObjectFactory[] factories;
+
+ public ListMultiplicityObjectFactory(List<ObjectFactory<?>> factories) {
+ assert factories != null : "Object factories were null";
+ this.factories = factories.toArray(new ObjectFactory[factories.size()]);
+ }
+
+ public List getInstance() throws ObjectCreationException {
+ List<Object> list = new ArrayList<Object>();
+ for (ObjectFactory factory : factories) {
+ list.add(factory.getInstance());
+ }
+ return list;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/MethodEventInvoker.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/MethodEventInvoker.java
new file mode 100644
index 0000000000..e43a1e1fa6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/MethodEventInvoker.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.core.injection;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * Performs an wire on a method of a given instance
+ *
+ * @version $Rev$ $Date$
+ */
+public class MethodEventInvoker<T> implements EventInvoker<T> {
+ private final Method method;
+
+ /**
+ * Intantiates an invoker for the given method
+ */
+ public MethodEventInvoker(Method method) {
+ assert method != null;
+ this.method = method;
+ }
+
+ public void invokeEvent(T instance) throws ObjectCallbackException {
+ try {
+ method.invoke(instance, (Object[]) null);
+ } catch (IllegalArgumentException e) {
+ String name = method.getName();
+ throw new ObjectCallbackException("Exception thrown by callback method [" + name + "]", e.getCause());
+ } catch (IllegalAccessException e) {
+ String name = method.getName();
+ throw new AssertionError("Method is not accessible [" + name + "]");
+ } catch (InvocationTargetException e) {
+ String name = method.getName();
+ throw new ObjectCallbackException("Exception thrown by callback method [" + name + "]", e.getCause());
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/MethodInjector.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/MethodInjector.java
new file mode 100644
index 0000000000..258f0817dd
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/MethodInjector.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.core.injection;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+
+/**
+ * Injects a value created by an {@link org.apache.tuscany.spi.ObjectFactory} using a given method
+ *
+ * @version $Rev$ $Date$
+ */
+public class MethodInjector<T> implements Injector<T> {
+ private final Method method;
+ private final ObjectFactory<?> objectFactory;
+
+ public MethodInjector(Method method, ObjectFactory<?> objectFactory) {
+ assert method != null;
+ assert objectFactory != null;
+ this.method = method;
+ this.method.setAccessible(true);
+ this.objectFactory = objectFactory;
+ }
+
+ public void inject(T instance) throws ObjectCreationException {
+ try {
+ method.invoke(instance, objectFactory.getInstance());
+ } catch (IllegalAccessException e) {
+ throw new AssertionError("Method is not accessible [" + method + "]");
+ } catch (IllegalArgumentException e) {
+ throw new ObjectCreationException("Exception thrown by setter", method.getName(), e);
+ } catch (InvocationTargetException e) {
+ throw new ObjectCreationException("Exception thrown by setter", method.getName(), e);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/NoAccessorException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/NoAccessorException.java
new file mode 100644
index 0000000000..b3109074e3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/NoAccessorException.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.core.injection;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public class NoAccessorException extends InjectionRuntimeException {
+ public NoAccessorException() {
+ }
+
+ public NoAccessorException(String message) {
+ super(message);
+ }
+
+ public NoAccessorException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public NoAccessorException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/NoMultiplicityTypeException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/NoMultiplicityTypeException.java
new file mode 100644
index 0000000000..a86451525b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/NoMultiplicityTypeException.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.core.injection;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class NoMultiplicityTypeException extends InjectionRuntimeException {
+
+ public NoMultiplicityTypeException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ObjectCallbackException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ObjectCallbackException.java
new file mode 100644
index 0000000000..ff830aab4b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ObjectCallbackException.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.core.injection;
+
+/**
+ * Denotes an error when invoking on an object
+ *
+ * @version $Rev$ $Date$
+ */
+public class ObjectCallbackException extends InjectionRuntimeException {
+
+ public ObjectCallbackException() {
+ super();
+ }
+
+ public ObjectCallbackException(String message) {
+ super(message);
+ }
+
+ public ObjectCallbackException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public ObjectCallbackException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ObjectCallbackException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/PojoObjectFactory.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/PojoObjectFactory.java
new file mode 100644
index 0000000000..d36af74de5
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/PojoObjectFactory.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.core.injection;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+
+/**
+ * Creates new instances of a Java class
+ *
+ * @version $Rev$ $Date$
+ * @see org.apache.tuscany.core.injection.Injector
+ */
+public class PojoObjectFactory<T> implements ObjectFactory<T> {
+
+ private final Constructor<T> ctr;
+ private ObjectFactory[] initializerFactories;
+
+ /**
+ * Creates the object factory
+ *
+ * @param ctr the constructor to use when instantiating a new object
+ */
+ public PojoObjectFactory(Constructor<T> ctr) {
+ assert ctr != null;
+ this.ctr = ctr;
+ initializerFactories = new ObjectFactory[ctr.getParameterTypes().length];
+ }
+
+ /**
+ * Creates the object factory
+ *
+ * @param ctr the constructor to use when instantiating a new object
+ * @param factories an ordered list of <code>ObjectFactory</code>s to use for returning constructor parameters
+ */
+ public PojoObjectFactory(Constructor<T> ctr, List<ObjectFactory> factories) {
+ assert ctr != null;
+ int params = ctr.getParameterTypes().length;
+ assert params == factories.size();
+ this.ctr = ctr;
+ initializerFactories = new ObjectFactory[params];
+ int i = 0;
+ for (ObjectFactory factory : factories) {
+ initializerFactories[i] = factory;
+ i++;
+ }
+ }
+
+ /**
+ * Returns the ordered array of <code>ObjectFactory</code>s use in creating constructor parameters
+ */
+ public ObjectFactory[] getInitializerFactories() {
+ return initializerFactories;
+ }
+
+ /**
+ * Sets an <code>ObjectFactory</code>s to use in creating constructor parameter
+ *
+ * @param pos the constructor parameter position
+ * @param factory the object factory
+ */
+ public void setInitializerFactory(int pos, ObjectFactory factory) {
+ assert pos < initializerFactories.length;
+ initializerFactories[pos] = factory;
+ }
+
+ /**
+ * Creates a new instance of an object
+ */
+ public T getInstance() throws ObjectCreationException {
+ int size = initializerFactories.length;
+ Object[] initargs = new Object[size];
+ // create the constructor arg array
+ for (int i = 0; i < size; i++) {
+ ObjectFactory<?> objectFactory = initializerFactories[i];
+ if (objectFactory == null) {
+ // this can happen if a reference is optional
+ initargs[i] = null;
+ } else {
+ initargs[i] = objectFactory.getInstance();
+ }
+ }
+ try {
+ ctr.setAccessible(true);
+ return ctr.newInstance(initargs);
+ } catch (IllegalArgumentException e) {
+ String name = ctr.getName();
+ throw new ObjectCreationException("Exception thrown by constructor", name, e);
+ } catch (InstantiationException e) {
+ String name = ctr.getDeclaringClass().getName();
+ throw new AssertionError("Class is not instantiable [" + name + "]");
+ } catch (IllegalAccessException e) {
+ String name = ctr.getName();
+ throw new AssertionError("Constructor is not accessible [" + name + "]");
+ } catch (InvocationTargetException e) {
+ String name = ctr.getName();
+ throw new ObjectCreationException("Exception thrown by constructor", name, e);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/RequestContextObjectFactory.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/RequestContextObjectFactory.java
new file mode 100644
index 0000000000..92a422a968
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/RequestContextObjectFactory.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.core.injection;
+
+import org.osoa.sca.RequestContext;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.component.WorkContext;
+
+import org.apache.tuscany.core.implementation.composite.ManagedRequestContext;
+
+/**
+ * Creates instances of {@link org.apache.tuscany.core.implementation.composite.ManagedRequestContext} for injection on
+ * component implementation instances
+ *
+ * @version $Rev$ $Date$
+ */
+public class RequestContextObjectFactory implements ObjectFactory<RequestContext> {
+ private WorkContext workContext;
+
+ public RequestContextObjectFactory(WorkContext workContext) {
+ assert workContext != null;
+ this.workContext = workContext;
+ }
+
+ public ManagedRequestContext getInstance() throws ObjectCreationException {
+ return new ManagedRequestContext(workContext);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ResourceNotFoundException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ResourceNotFoundException.java
new file mode 100644
index 0000000000..ed3ac20631
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ResourceNotFoundException.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.core.injection;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+
+/**
+ * Denotes an exception thrown when a runtime resource is not found
+ *
+ * @version $Rev$ $Date$
+ */
+public class ResourceNotFoundException extends ObjectCreationException {
+
+ public ResourceNotFoundException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ResourceObjectFactory.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ResourceObjectFactory.java
new file mode 100644
index 0000000000..bb2f335506
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/ResourceObjectFactory.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.core.injection;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.host.ResourceHost;
+import org.apache.tuscany.spi.host.ResourceResolutionException;
+
+/**
+ * Resolves a runtime resource to be injected on a field or method of a Java component type marked with {@link
+ * org.apache.tuscany.api.annotation.Resource}. If the mapped name of the resource is an absolute URI such as
+ * <code>sca://localhost</code> or <code>jndi://localhost</code> the host container namespace is searched; otherwise the
+ * URI is assumed to be relative and the parent composite is searched. If a mapped name is not provided, i.e. resolution
+ * is by type, the parent composite is first searched followed by the host namespace.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ResourceObjectFactory<T> implements ObjectFactory<T> {
+
+ private Class<T> type;
+ private String mappedName;
+ private ResourceHost host;
+ private boolean optional;
+
+ /**
+ * Instantiates a factory that resolves resources by type
+ *
+ * @param type the type of the resource to inject
+ * @param optional true if an error should be thrown if the resource is not found
+ * @param host the runtime resource provider
+ */
+ public ResourceObjectFactory(Class<T> type, boolean optional, ResourceHost host) {
+ this(type, null, optional, host);
+ }
+
+ /**
+ * Instantiates a factory that resolves resources by mapped name
+ *
+ * @param type the type of the resource to inject
+ * @param mappedName the resource name
+ * @param optional true if an error should be thrown if the resource is not found
+ * @param host the runtime resource provider
+ */
+ public ResourceObjectFactory(Class<T> type, String mappedName, boolean optional, ResourceHost host) {
+ this.type = type;
+ this.host = host;
+ this.mappedName = mappedName;
+ this.optional = optional;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public T getInstance() throws ObjectCreationException {
+ try {
+ T resource;
+ if (mappedName == null) {
+ resource = host.resolveResource(type);
+ if (!optional && resource == null) {
+ throw new ResourceNotFoundException("Resource not found", type.getName());
+ }
+ } else {
+ resource = host.resolveResource(type, mappedName);
+ if (!optional && resource == null) {
+ throw new ResourceNotFoundException("Resource not found", mappedName);
+ }
+ }
+ return resource;
+ } catch (ResourceResolutionException e) {
+ throw new ObjectCreationException(e);
+ }
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/SingletonObjectFactory.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/SingletonObjectFactory.java
new file mode 100644
index 0000000000..713c1ae54f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/injection/SingletonObjectFactory.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.core.injection;
+
+import org.apache.tuscany.spi.ObjectFactory;
+
+/**
+ * Implementation of ObjectFactory that returns a single instance, typically an immutable type.
+ *
+ * @version $Rev$ $Date$
+ */
+public class SingletonObjectFactory<T> implements ObjectFactory<T> {
+ private final T instance;
+
+ public SingletonObjectFactory(T instance) {
+ this.instance = instance;
+ }
+
+ public T getInstance() {
+ return instance;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/ComponentLoader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/ComponentLoader.java
new file mode 100644
index 0000000000..541decd96b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/ComponentLoader.java
@@ -0,0 +1,361 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.loader;
+
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.net.URL;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.ParserConfigurationException;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.w3c.dom.Document;
+import static org.osoa.sca.Constants.SCA_NS;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.QualifiedName;
+import org.apache.tuscany.spi.databinding.extension.DOMHelper;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.InvalidReferenceException;
+import org.apache.tuscany.spi.loader.InvalidValueException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.LoaderUtil;
+import org.apache.tuscany.spi.loader.MissingImplementationException;
+import org.apache.tuscany.spi.loader.MissingReferenceException;
+import org.apache.tuscany.spi.loader.MissingRequiredPropertyException;
+import org.apache.tuscany.spi.loader.PropertyObjectFactory;
+import org.apache.tuscany.spi.loader.ReferenceMultiplicityViolationException;
+import org.apache.tuscany.spi.loader.UndefinedPropertyException;
+import org.apache.tuscany.spi.loader.UndefinedReferenceException;
+import org.apache.tuscany.spi.loader.UnrecognizedElementException;
+import org.apache.tuscany.spi.model.BindingDefinition;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.Multiplicity;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.PropertyValue;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import org.apache.tuscany.core.binding.local.LocalBindingDefinition;
+import org.apache.tuscany.core.deployer.ChildDeploymentContext;
+import org.apache.tuscany.core.property.SimplePropertyObjectFactory;
+
+/**
+ * Loads a component definition from an XML-based assembly file
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentLoader extends LoaderExtension<ComponentDefinition<?>> {
+ private static final QName COMPONENT = new QName(SCA_NS, "component");
+ private static final QName PROPERTY = new QName(SCA_NS, "property");
+ private static final QName REFERENCE = new QName(SCA_NS, "reference");
+
+ private static final String PROPERTY_FILE_ATTR = "file";
+ private static final String PROPERTY_NAME_ATTR = "name";
+ private static final String PROPERTY_SOURCE_ATTR = "source";
+
+ private PropertyObjectFactory propertyFactory;
+
+ @Constructor
+ public ComponentLoader(@Reference LoaderRegistry registry, @Reference PropertyObjectFactory propertyFactory) {
+ super(registry);
+ this.propertyFactory = propertyFactory;
+ }
+
+ public QName getXMLType() {
+ return COMPONENT;
+ }
+
+ @SuppressWarnings("unchecked")
+ public ComponentDefinition<?> load(ModelObject object, XMLStreamReader reader, DeploymentContext context)
+ throws XMLStreamException, LoaderException {
+ assert COMPONENT.equals(reader.getName());
+ String name = reader.getAttributeValue(null, "name");
+ String initLevel = reader.getAttributeValue(null, "initLevel");
+ String autowireAttr = reader.getAttributeValue(null, "autowire");
+ boolean autowire;
+ if (autowireAttr == null) {
+ autowire = context.isAutowire();
+ } else {
+ autowire = Boolean.parseBoolean(autowireAttr);
+ }
+ String runtimeAttr = reader.getAttributeValue(null, "runtimeId");
+ URI runtimeId;
+ if (runtimeAttr != null) {
+ try {
+ runtimeId = new URI(runtimeAttr);
+ } catch (URISyntaxException e) {
+ throw new InvalidValueException(runtimeAttr, "runtimeId", e);
+ }
+ } else {
+ runtimeId = null;
+ }
+
+ URI componentId = URI.create(context.getComponentId() + "/").resolve(name);
+ ClassLoader loader = context.getClassLoader();
+ URL location = context.getScdlLocation();
+ // xcv test
+ DeploymentContext childContext = new ChildDeploymentContext(context, loader, location, componentId, autowire);
+ Implementation<?> impl = loadImplementation(reader, childContext);
+ registry.loadComponentType(impl, childContext);
+
+ ComponentDefinition<Implementation<?>> componentDefinition =
+ new ComponentDefinition<Implementation<?>>(componentId, impl);
+ componentDefinition.setAutowire(autowire);
+ componentDefinition.setRuntimeId(runtimeId);
+ if (initLevel != null) {
+ if (initLevel.length() == 0) {
+ componentDefinition.setInitLevel(0);
+ } else {
+ try {
+ componentDefinition.setInitLevel(Integer.valueOf(initLevel));
+ } catch (NumberFormatException e) {
+ throw new InvalidValueException(initLevel, "initValue", e);
+ }
+ }
+ }
+
+ while (true) {
+ switch (reader.next()) {
+ case START_ELEMENT:
+ QName qname = reader.getName();
+ if (PROPERTY.equals(qname)) {
+ loadProperty(reader, componentDefinition, childContext);
+ } else if (REFERENCE.equals(qname)) {
+ loadReference(reader, componentDefinition, childContext);
+ } else {
+ throw new UnrecognizedElementException(qname);
+ }
+ reader.next();
+ break;
+ case END_ELEMENT:
+ if (reader.getName().equals(COMPONENT)) {
+ populatePropertyValues(componentDefinition);
+ ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ (ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>) componentDefinition
+ .getImplementation().getComponentType();
+
+ for (ReferenceDefinition ref : type.getReferences().values()) {
+ // add reference target definitions if autowire is enabled for references that are not
+ // explicitly configured with autowire by the component
+ if (!componentDefinition.getReferenceTargets().containsKey(ref.getUri().getFragment())) {
+ if (autowire) {
+ ReferenceTarget referenceTarget = new ReferenceTarget();
+ String compName = componentDefinition.getUri().toString();
+ URI refName = URI.create(compName + ref.getUri().toString());
+ referenceTarget.setReferenceName(refName);
+ referenceTarget.setAutowire(autowire);
+ componentDefinition.add(referenceTarget);
+ }
+ }
+ }
+ validate(componentDefinition);
+ return componentDefinition;
+ }
+ break;
+ }
+ }
+ }
+
+ protected Implementation<?> loadImplementation(XMLStreamReader reader, DeploymentContext context)
+ throws XMLStreamException, LoaderException {
+ reader.nextTag();
+ ModelObject o = registry.load(null, reader, context);
+ if (!(o instanceof Implementation)) {
+ throw new MissingImplementationException();
+ }
+ return (Implementation<?>) o;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void loadProperty(XMLStreamReader reader, ComponentDefinition<?> definition, DeploymentContext context)
+ throws XMLStreamException, LoaderException {
+ String name = reader.getAttributeValue(null, PROPERTY_NAME_ATTR);
+ Implementation<?> implementation = definition.getImplementation();
+ ComponentType<?, ?, ?> componentType = implementation.getComponentType();
+ Property<Type> property = (Property<Type>) componentType.getProperties().get(name);
+ if (property == null) {
+ throw new UndefinedPropertyException(name);
+ }
+ PropertyValue<Type> propertyValue;
+ String source = reader.getAttributeValue(null, PROPERTY_SOURCE_ATTR);
+ String file = reader.getAttributeValue(null, PROPERTY_FILE_ATTR);
+ if (source != null || file != null) {
+ propertyValue = new PropertyValue<Type>(name, source, file);
+ propertyValue.setValue(property.getDefaultValue());
+ LoaderUtil.skipToEndElement(reader);
+ } else {
+ try {
+ DocumentBuilder documentBuilder = DOMHelper.newDocumentBuilder();
+ Document value = PropertyUtils.createPropertyValue(reader, property.getXmlType(), documentBuilder);
+ propertyValue = new PropertyValue<Type>(name, value);
+ } catch (ParserConfigurationException e) {
+ throw new LoaderException(e);
+ }
+ }
+ ObjectFactory<Type> objectFactory = propertyFactory.createObjectFactory(property, propertyValue);
+ propertyValue.setValueFactory(objectFactory);
+ definition.add(propertyValue);
+ }
+
+ protected void loadReference(XMLStreamReader reader,
+ ComponentDefinition<?> componentDefinition,
+ DeploymentContext context) throws XMLStreamException, LoaderException {
+ String name = reader.getAttributeValue(null, "name");
+ if (name == null) {
+ throw new InvalidReferenceException("No name specified");
+ }
+ String target = reader.getAttributeValue(null, "target");
+ boolean autowire = Boolean.parseBoolean(reader.getAttributeValue(null, "autowire"));
+ URI componentId = context.getComponentId();
+ List<URI> uris = new ArrayList<URI>();
+ if (target != null) {
+ StringTokenizer tokenizer = new StringTokenizer(target);
+ while (tokenizer.hasMoreTokens()) {
+ String token = tokenizer.nextToken();
+ QualifiedName qName = new QualifiedName(token);
+ uris.add(componentId.resolve(qName.getFragment()));
+ }
+ }
+
+ Implementation<?> impl = componentDefinition.getImplementation();
+ ComponentType<?, ?, ?> componentType = impl.getComponentType();
+ if (!componentType.getReferences().containsKey(name)) {
+ throw new UndefinedReferenceException(name);
+ }
+ if (componentType instanceof CompositeComponentType) {
+ if (uris.size() != 1) {
+ // FIXME not yet implemented
+ throw new UnsupportedOperationException();
+ }
+ ReferenceDefinition definition = componentType.getReferences().get(name);
+ if (definition.getBindings().isEmpty()) {
+ // TODO JFM allow selection of a default binding
+ LocalBindingDefinition binding = new LocalBindingDefinition(uris.get(0));
+ definition.addBinding(binding);
+ } else {
+ for (BindingDefinition binding : definition.getBindings()) {
+ binding.setTargetUri(uris.get(0));
+ }
+ }
+ } else {
+ ReferenceTarget referenceTarget = componentDefinition.getReferenceTargets().get(name);
+ if (referenceTarget == null) {
+ referenceTarget = new ReferenceTarget();
+ referenceTarget.setReferenceName(componentId.resolve('#' + name));
+ referenceTarget.setAutowire(autowire);
+ componentDefinition.add(referenceTarget);
+ }
+ for (URI uri : uris) {
+ referenceTarget.addTarget(uri);
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void populatePropertyValues(ComponentDefinition<Implementation<?>> componentDefinition)
+ throws MissingRequiredPropertyException {
+ ComponentType componentType = componentDefinition.getImplementation().getComponentType();
+ if (componentType != null) {
+ Map<String, Property<?>> properties = componentType.getProperties();
+ Map<String, PropertyValue<?>> propertyValues = componentDefinition.getPropertyValues();
+
+ for (Property<?> aProperty : properties.values()) {
+ if (propertyValues.get(aProperty.getName()) == null) {
+ if (aProperty.isRequired()) {
+ throw new MissingRequiredPropertyException(aProperty.getName());
+ } else if (aProperty.getDefaultValue() != null) {
+ PropertyValue propertyValue = new PropertyValue();
+ propertyValue.setName(aProperty.getName());
+ propertyValue.setValue(aProperty.getDefaultValue());
+ propertyValue.setValueFactory(new SimplePropertyObjectFactory(aProperty,
+ propertyValue.getValue()));
+ propertyValues.put(aProperty.getName(), propertyValue);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Validates a component definition, ensuring all component type configuration elements are satisfied
+ */
+ protected void validate(ComponentDefinition<Implementation<?>> definition) throws LoaderException {
+ // validate refererences
+ Implementation<?> implementation = definition.getImplementation();
+ ComponentType<?, ?, ?> type = implementation.getComponentType();
+ if (type == null) {
+ return;
+ }
+ for (ReferenceDefinition referenceDef : type.getReferences().values()) {
+ if (!referenceDef.isRequired()) {
+ continue;
+ }
+ String name = referenceDef.getUri().getFragment();
+ ReferenceTarget target = definition.getReferenceTargets().get(name);
+ if (target == null) {
+ throw new MissingReferenceException(name);
+ }
+ if (target.isAutowire()) {
+ // autowire targets are not set yet
+ continue;
+ }
+ int count = target.getTargets().size();
+ Multiplicity multiplicity = referenceDef.getMultiplicity();
+ switch (multiplicity) {
+ case ZERO_N:
+ break;
+ case ZERO_ONE:
+ if (count > 1) {
+ throw new ReferenceMultiplicityViolationException(name, multiplicity, count);
+ }
+ break;
+ case ONE_ONE:
+ if (count != 1) {
+ throw new ReferenceMultiplicityViolationException(name, multiplicity, count);
+ }
+ break;
+ case ONE_N:
+ if (count < 1) {
+ throw new ReferenceMultiplicityViolationException(name, multiplicity, count);
+ }
+ break;
+ }
+
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/ComponentTypeElementLoader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/ComponentTypeElementLoader.java
new file mode 100644
index 0000000000..beb0bc2731
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/ComponentTypeElementLoader.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.core.loader;
+
+import javax.xml.namespace.QName;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ComponentTypeElementLoader extends LoaderExtension<ComponentType> {
+ public static final QName COMPONENT_TYPE = new QName(SCA_NS, "componentType");
+
+ @Constructor
+ public ComponentTypeElementLoader(@Reference LoaderRegistry registry) {
+ super(registry);
+ }
+
+ public QName getXMLType() {
+ return COMPONENT_TYPE;
+ }
+
+ @SuppressWarnings("unchecked")
+ public ComponentType load(ModelObject object, XMLStreamReader reader, DeploymentContext context)
+ throws XMLStreamException, LoaderException {
+ assert COMPONENT_TYPE.equals(reader.getName());
+ ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> componentType;
+ if (object != null) {
+ assert object instanceof ComponentType;
+ // a specialized component type was passed in
+ componentType = (ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>) object;
+ } else {
+ componentType = new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ }
+
+ while (true) {
+ switch (reader.next()) {
+ case START_ELEMENT:
+ ModelObject o = registry.load(componentType, reader, context);
+ if (o instanceof ServiceDefinition) {
+ componentType.add((ServiceDefinition) o);
+ } else if (o instanceof ReferenceDefinition) {
+ componentType.add((ReferenceDefinition) o);
+ } else if (o instanceof Property) {
+ componentType.add((Property<?>) o);
+ }
+ break;
+ case END_ELEMENT:
+ return componentType;
+ }
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/DependencyLoader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/DependencyLoader.java
new file mode 100644
index 0000000000..a4d1cd1440
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/DependencyLoader.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.core.loader;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.UnrecognizedElementException;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.services.artifact.Artifact;
+
+import org.apache.tuscany.core.implementation.composite.Dependency;
+
+/**
+ * Loader for handling <dependency> elements.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DependencyLoader extends LoaderExtension<Dependency> {
+ private static final String NS = "http://tuscany.apache.org/xmlns/sca/2.0-alpha";
+ private static final QName DEPENDENCY = new QName(NS, "dependency");
+ private static final QName GROUP = new QName(NS, "group");
+ private static final QName NAME = new QName(NS, "name");
+ private static final QName VERSION = new QName(NS, "version");
+ private static final QName CLASSIFIER = new QName(NS, "classifier");
+ private static final QName TYPE = new QName(NS, "type");
+
+ public DependencyLoader(@Reference LoaderRegistry registry) {
+ super(registry);
+ }
+
+ public QName getXMLType() {
+ return DEPENDENCY;
+ }
+
+ public Dependency load(
+ ModelObject object,
+ XMLStreamReader reader,
+ DeploymentContext deploymentContext)
+ throws XMLStreamException, LoaderException {
+
+ Artifact artifact = new Artifact();
+ while (reader.nextTag() == XMLStreamConstants.START_ELEMENT) {
+ QName name = reader.getName();
+ String text = reader.getElementText();
+ if (GROUP.equals(name)) {
+ artifact.setGroup(text);
+ } else if (NAME.equals(name)) {
+ artifact.setName(text);
+ } else if (VERSION.equals(name)) {
+ artifact.setVersion(text);
+ } else if (CLASSIFIER.equals(name)) {
+ artifact.setClassifier(text);
+ } else if (TYPE.equals(name)) {
+ artifact.setType(text);
+ } else {
+ throw new UnrecognizedElementException(name);
+ }
+ }
+ Dependency dependency = new Dependency();
+ dependency.setArtifact(artifact);
+ return dependency;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/IncludeLoader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/IncludeLoader.java
new file mode 100644
index 0000000000..e10a93bbc0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/IncludeLoader.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.core.loader;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.LoaderUtil;
+import org.apache.tuscany.spi.loader.MissingIncludeException;
+import org.apache.tuscany.spi.loader.MissingResourceException;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.Include;
+import org.apache.tuscany.spi.model.ModelObject;
+
+import org.apache.tuscany.core.deployer.ChildDeploymentContext;
+
+/**
+ * Loader that handles &lt;include&gt; elements.
+ *
+ * @version $Rev$ $Date$
+ */
+public class IncludeLoader extends LoaderExtension<Include> {
+ private static final QName INCLUDE = new QName(SCA_NS, "include");
+
+ @Constructor
+ public IncludeLoader(@Reference LoaderRegistry registry) {
+ super(registry);
+ }
+
+ public QName getXMLType() {
+ return INCLUDE;
+ }
+
+ public Include load(ModelObject object, XMLStreamReader reader, DeploymentContext deploymentContext)
+ throws XMLStreamException, LoaderException {
+
+ assert INCLUDE.equals(reader.getName());
+ String name = reader.getAttributeValue(null, "name");
+ String scdlLocation = reader.getAttributeValue(null, "scdlLocation");
+ String scdlResource = reader.getAttributeValue(null, "scdlResource");
+ LoaderUtil.skipToEndElement(reader);
+
+ ClassLoader cl = deploymentContext.getClassLoader();
+ URL url;
+ if (scdlLocation != null) {
+ try {
+ url = new URL(deploymentContext.getScdlLocation(), scdlLocation);
+ } catch (MalformedURLException e) {
+ throw new MissingResourceException(scdlLocation, name, e);
+ }
+ } else if (scdlResource != null) {
+ url = cl.getResource(scdlResource);
+ if (url == null) {
+ throw new MissingResourceException(scdlResource, name);
+ }
+ } else {
+ throw new MissingIncludeException("No SCDL location or resource specified", name);
+ }
+
+ // when we include, the componentId remains that of the parent
+ URI componentId = deploymentContext.getComponentId();
+ boolean autowire = deploymentContext.isAutowire();
+ DeploymentContext childContext = new ChildDeploymentContext(deploymentContext, cl, url, componentId, autowire);
+ CompositeComponentType composite;
+ composite = loadFromSidefile(url, childContext);
+
+ Include include = new Include();
+ include.setName(name);
+ include.setScdlLocation(url);
+ include.setIncluded(composite);
+ return include;
+ }
+
+ protected CompositeComponentType loadFromSidefile(URL url, DeploymentContext context) throws LoaderException {
+ return registry.load(null, url, CompositeComponentType.class, context);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/JNDIPropertyFactory.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/JNDIPropertyFactory.java
new file mode 100644
index 0000000000..8759377840
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/JNDIPropertyFactory.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.core.loader;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.PropertyObjectFactory;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.PropertyValue;
+
+import org.apache.tuscany.core.injection.JNDIObjectFactory;
+
+/**
+ * A StAXPropertyFactory that creates property values by looking them up in the default JNDI InitialContext. <p/> This
+ * can be used to locate resources in a J2EE environment and inject them as configuration properties. For example, to
+ * access a database a component could write: <code> &at;Property DataSource myDB; </code> and configure with <code>
+ * &lt;properties&gt; &lt;v:myDb&gt;java:comp/env/jdbc/MyDatabase&lt;/v:myDB&gt; &lt;/properties&gt; </code>
+ *
+ * @version $Rev$ $Date$
+ */
+public class JNDIPropertyFactory implements PropertyObjectFactory {
+ public <T> ObjectFactory<T> createObjectFactory(Property<T> property, PropertyValue<T> value)
+ throws LoaderException {
+ String text = value.getValue().getDocumentElement().getTextContent();
+ try {
+ Context context = new InitialContext();
+ return new JNDIObjectFactory<T>(context, text);
+ } catch (NamingException e) {
+ throw new LoaderException(e);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/LoaderExceptionFormatter.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/LoaderExceptionFormatter.java
new file mode 100644
index 0000000000..26ec72ecb6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/LoaderExceptionFormatter.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.core.loader;
+
+import java.io.PrintWriter;
+
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.loader.LoaderException;
+
+import org.apache.tuscany.host.monitor.ExceptionFormatter;
+import org.apache.tuscany.host.monitor.FormatterRegistry;
+
+/**
+ * Formats {@link org.apache.tuscany.spi.loader.LoaderException} events
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+public class LoaderExceptionFormatter implements ExceptionFormatter {
+ private FormatterRegistry factory;
+
+ public LoaderExceptionFormatter(@Reference FormatterRegistry factory) {
+ this.factory = factory;
+ factory.register(this);
+ }
+
+ public boolean canFormat(Class<?> type) {
+ return LoaderException.class.isAssignableFrom(type);
+ }
+
+ @Destroy
+ public void destroy() {
+ factory.unregister(this);
+ }
+
+ public PrintWriter write(PrintWriter writer, Throwable exception) {
+ assert exception instanceof LoaderException;
+ LoaderException e = (LoaderException) exception;
+ e.appendBaseMessage(writer);
+ if (e.getLine() != LoaderException.UNDEFINED) {
+ writer.write("\nLine: " + e.getLine() + "\n");
+ writer.write("Column: " + e.getColumn() + "\n");
+ } else {
+ writer.write("\n");
+ }
+ return writer;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/LoaderRegistryImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/LoaderRegistryImpl.java
new file mode 100644
index 0000000000..57fd1da870
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/LoaderRegistryImpl.java
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.osoa.sca.annotations.EagerInit;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.ComponentTypeLoader;
+import org.apache.tuscany.spi.loader.InvalidConfigurationException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.StAXElementLoader;
+import org.apache.tuscany.spi.loader.UnrecognizedComponentTypeException;
+import org.apache.tuscany.spi.loader.UnrecognizedElementException;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * The default implementation of a loader registry
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+public class LoaderRegistryImpl implements LoaderRegistry {
+ private Monitor monitor;
+ private final Map<QName, StAXElementLoader<? extends ModelObject>> loaders =
+ new HashMap<QName, StAXElementLoader<? extends ModelObject>>();
+ private final Map<Class<? extends Implementation<?>>,
+ ComponentTypeLoader<? extends Implementation<?>>> componentTypeLoaders =
+ new HashMap<Class<? extends Implementation<?>>, ComponentTypeLoader<? extends Implementation<?>>>();
+
+ public LoaderRegistryImpl(@org.apache.tuscany.api.annotation.Monitor Monitor monitor) {
+ this.monitor = monitor;
+ }
+
+ public <T extends ModelObject> void registerLoader(QName element, StAXElementLoader<T> loader) {
+ monitor.registeringLoader(element);
+ loaders.put(element, loader);
+ }
+
+ public <T extends ModelObject> void unregisterLoader(QName element, StAXElementLoader<T> loader) {
+ monitor.unregisteringLoader(element);
+ loaders.remove(element);
+ }
+
+ public ModelObject load(
+ ModelObject object,
+ XMLStreamReader reader,
+ DeploymentContext deploymentContext) throws XMLStreamException, LoaderException {
+ QName name = reader.getName();
+ monitor.elementLoad(name);
+ StAXElementLoader<? extends ModelObject> loader = loaders.get(name);
+ if (loader == null) {
+ throw new UnrecognizedElementException(name);
+ }
+ return loader.load(object, reader, deploymentContext);
+ }
+
+ public <MO extends ModelObject> MO load(
+ ModelObject object,
+ URL url,
+ Class<MO> type,
+ DeploymentContext ctx) throws LoaderException {
+ try {
+ XMLStreamReader reader;
+ InputStream is;
+ is = url.openStream();
+ try {
+ XMLInputFactory factory = ctx.getXmlFactory();
+ reader = factory.createXMLStreamReader(is);
+ try {
+ reader.nextTag();
+ QName name = reader.getName();
+ ModelObject mo = load(object, reader, ctx);
+ if (type.isInstance(mo)) {
+ return type.cast(mo);
+ } else {
+ UnrecognizedElementException e = new UnrecognizedElementException(name);
+ e.setResourceURI(url.toString());
+ throw e;
+ }
+ } catch (LoaderException 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 (IOException e) {
+ LoaderException sfe = new LoaderException(e);
+ sfe.setResourceURI(url.toString());
+ throw sfe;
+ } catch (XMLStreamException e) {
+ throw new InvalidConfigurationException("Invalid or missing resource", url.toString(), e);
+ }
+ }
+
+ public <I extends Implementation<?>> void registerLoader(Class<I> key, ComponentTypeLoader<I> loader) {
+ componentTypeLoaders.put(key, loader);
+ }
+
+ public <I extends Implementation<?>> void unregisterLoader(Class<I> key) {
+ componentTypeLoaders.remove(key);
+ }
+
+ @SuppressWarnings("unchecked")
+ public <I extends Implementation<?>> void loadComponentType(I implementation,
+ DeploymentContext deploymentContext)
+ throws LoaderException {
+ Class<I> key = (Class<I>) implementation.getClass();
+ ComponentTypeLoader<I> loader = (ComponentTypeLoader<I>) componentTypeLoaders.get(key);
+ if (loader == null) {
+ throw new UnrecognizedComponentTypeException(key);
+ }
+ loader.load(implementation, deploymentContext);
+ }
+
+ public static interface Monitor {
+ /**
+ * Event emitted when a StAX element loader is registered.
+ *
+ * @param xmlType the QName of the element the loader will handle
+ */
+ void registeringLoader(QName xmlType);
+
+ /**
+ * Event emitted when a StAX element loader is unregistered.
+ *
+ * @param xmlType the QName of the element the loader will handle
+ */
+ void unregisteringLoader(QName xmlType);
+
+ /**
+ * Event emitted when a request is made to load an element.
+ *
+ * @param xmlType the QName of the element that should be loaded
+ */
+ void elementLoad(QName xmlType);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/PolicySetLoader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/PolicySetLoader.java
new file mode 100644
index 0000000000..66d2a87593
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/PolicySetLoader.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.core.loader;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.namespace.QName;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.LoaderUtil;
+import org.apache.tuscany.spi.model.IntentMap;
+import org.apache.tuscany.spi.model.IntentName;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.PolicySet;
+import org.apache.tuscany.spi.model.PolicySetReference;
+import org.apache.tuscany.spi.model.Qualifier;
+import org.apache.tuscany.spi.model.WSPolicyAttachment;
+
+/**
+ * Loads a PolicySet definition from an SCDL file.
+ *
+ * @version $Rev$ $Date$
+ */
+public class PolicySetLoader extends LoaderExtension<PolicySet> {
+
+ private static final String WSPOLICY_NAMESPACE = "http://schemas.xmlsoap.org/ws/2004/09/policy";
+
+ private static final QName POLICYSET = new QName(SCA_NS, "policySet");
+
+ private static final QName INTENTMAP = new QName(SCA_NS, "intentMap");
+
+ private static final QName QUALIFIER = new QName(SCA_NS, "qualifier");
+
+ private static final QName POLICYSETREFERENCE = new QName(SCA_NS, "policySetReference");
+
+ private static final QName WSPOLICYATTACHMENT = new QName(WSPOLICY_NAMESPACE, "PolicyAttachment");
+
+ @Constructor
+ public PolicySetLoader(@Reference LoaderRegistry registry) {
+ super(registry);
+
+ }
+
+ @Override
+ public QName getXMLType() {
+ return POLICYSET;
+ }
+
+ public PolicySet load(ModelObject object, XMLStreamReader reader,
+ DeploymentContext deploymentContext)
+ throws XMLStreamException {
+ assert POLICYSET.equals(reader.getName());
+ String name = reader.getAttributeValue(null, "name");
+ String provides = reader.getAttributeValue(null, "provides");
+ String appliesTo = reader.getAttributeValue(null, "appliesTo");
+ PolicySet policySet = new PolicySet(new QName(SCA_NS, name), parseIntentName(provides));
+ String[] appliesToArtifact = split(appliesTo);
+ for (String artifact : appliesToArtifact) {
+ policySet.addAppliedArtifacts(new QName(SCA_NS, artifact));
+ }
+ while (true) {
+ switch (reader.next()) {
+ case START_ELEMENT:
+ QName qname = reader.getName();
+ if (INTENTMAP.equals(qname)) {
+ policySet.addIntentMap(loadIntentMap(reader, deploymentContext));
+ } else if (POLICYSETREFERENCE.equals(qname)) {
+ policySet.addPolicySetReference(loadPolicyReference(reader, deploymentContext));
+ } else if (WSPOLICYATTACHMENT.equals(qname)) {
+ policySet.addWsPolicyAttachment(loadWSPolicyAttachment(reader, deploymentContext));
+ }
+
+ reader.next();
+ break;
+ case END_ELEMENT:
+ if (reader.getName().equals(POLICYSET)) {
+ return policySet;
+ }
+ break;
+ }
+ }
+
+ }
+
+ private PolicySetReference loadPolicyReference(XMLStreamReader reader, DeploymentContext deploymentContext)
+ throws XMLStreamException {
+ assert POLICYSETREFERENCE.equals(reader.getName());
+ String name = reader.getAttributeValue(null, "name");
+ LoaderUtil.skipToEndElement(reader);
+ return new PolicySetReference(new QName(SCA_NS, name));
+ }
+
+ private IntentMap loadIntentMap(XMLStreamReader reader, DeploymentContext deploymentContext)
+ throws XMLStreamException {
+ assert INTENTMAP.equals(reader.getName());
+ String defaultIntentAttr = reader.getAttributeValue(null, "default");
+ String provides = reader.getAttributeValue(null, "provides");
+ IntentMap intentMap = new IntentMap(defaultIntentAttr, java.util.Arrays.asList(split(provides)));
+ //parentPolicySet.addIntentMap(intentMap);
+
+ while (true) {
+ switch (reader.next()) {
+ case START_ELEMENT:
+ QName qname = reader.getName();
+ if (QUALIFIER.equals(qname)) {
+ intentMap.addQualifier(loadQualifier(reader, deploymentContext));
+ }
+ reader.next();
+ break;
+ case END_ELEMENT:
+ if (reader.getName().equals(INTENTMAP)) {
+ return intentMap;
+ }
+ }
+ }
+
+ }
+
+ private Qualifier loadQualifier(XMLStreamReader reader, DeploymentContext deploymentContext)
+ throws XMLStreamException {
+ assert QUALIFIER.equals(reader.getName());
+ String name = reader.getAttributeValue(null, "name");
+ Qualifier qualifier = new Qualifier(name);
+ while (true) {
+ switch (reader.next()) {
+ case START_ELEMENT:
+ QName qname = reader.getName();
+ if (INTENTMAP.equals(qname)) {
+ qualifier.setIntentMap(loadIntentMap(reader, deploymentContext));
+ } else if (WSPOLICYATTACHMENT.equals(qname)) {
+ qualifier.addWsPolicyAttachment(loadWSPolicyAttachment(reader, deploymentContext));
+ }
+ reader.next();
+ break;
+ case END_ELEMENT:
+ if (reader.getName().equals(QUALIFIER)) {
+ return qualifier;
+ }
+ }
+ }
+
+ }
+
+ private WSPolicyAttachment loadWSPolicyAttachment(XMLStreamReader reader, DeploymentContext deploymentContext)
+ throws XMLStreamException {
+ return new WSPolicyAttachment();
+ }
+
+ /**
+ * Split a string to string array separated by " "
+ */
+ private static String[] split(String string) {
+ if (string == null) {
+ return new String[0];
+ }
+ String[] intents = string.split("[ ]+");
+ return intents;
+ }
+
+ private static List<IntentName> parseIntentName(String attributes) {
+ String[] intents = split(attributes);
+ List<IntentName> result = new ArrayList<IntentName>(intents.length);
+ for (String intent : intents) {
+ result.add(new IntentName(intent));
+ }
+ return result;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/PropertyLoader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/PropertyLoader.java
new file mode 100644
index 0000000000..ac39c135d9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/PropertyLoader.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.core.loader;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.w3c.dom.Document;
+import static org.osoa.sca.Constants.SCA_NS;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.Property;
+
+/**
+ * Loads a property from an XML-based assembly file
+ *
+ * @version $Rev$ $Date$
+ */
+public class PropertyLoader extends LoaderExtension<Property> {
+ public static final String PROPERTY_NAME_ATTR = "name";
+ public static final String PROPERTY_TYPE_ATTR = "type";
+ public static final String PROPERTY_MANY_ATTR = "many";
+ public static final String REQUIRED_ATTR = "override";
+
+ public static final QName PROPERTY = new QName(SCA_NS, "property");
+ private final DocumentBuilder documentBuilder;
+
+ @Constructor
+ public PropertyLoader(@Reference LoaderRegistry registry) {
+ super(registry);
+ try {
+ documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ } catch (ParserConfigurationException e) {
+ // we should be able to construct the default DocumentBuilder
+ throw new AssertionError(e);
+ }
+ }
+
+ public QName getXMLType() {
+ return PROPERTY;
+ }
+
+ public Property<?> load(ModelObject object, XMLStreamReader reader,
+ DeploymentContext ctx)
+ throws XMLStreamException, LoaderException {
+ assert PROPERTY.equals(reader.getName());
+ String name = reader.getAttributeValue(null, PROPERTY_NAME_ATTR);
+ String typeName = reader.getAttributeValue(null, PROPERTY_TYPE_ATTR);
+ QName xmlType = null;
+ if (typeName != null) {
+ int index = typeName.indexOf(':');
+ if (index != -1) {
+ String prefix = typeName.substring(0, index);
+ String localName = typeName.substring(index + 1);
+ String ns = reader.getNamespaceURI(prefix);
+ xmlType = new QName(ns, localName, prefix);
+ }
+ }
+ boolean many = Boolean.parseBoolean(reader.getAttributeValue(null, PROPERTY_MANY_ATTR));
+ String required = reader.getAttributeValue(null, REQUIRED_ATTR);
+ Document value = PropertyUtils.createPropertyValue(reader, xmlType, documentBuilder);
+
+ Property<?> property = new Property();
+ property.setRequired(Boolean.parseBoolean(required));
+ property.setName(name);
+ property.setXmlType(xmlType);
+ property.setMany(many);
+
+ property.setDefaultValue(value);
+ return property;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/PropertyUtils.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/PropertyUtils.java
new file mode 100644
index 0000000000..57c1e1b5f4
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/PropertyUtils.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public final class PropertyUtils {
+
+ private PropertyUtils() {
+ }
+
+ public static Document createPropertyValue(XMLStreamReader reader, QName type, DocumentBuilder builder)
+ throws XMLStreamException {
+ Document doc = builder.newDocument();
+
+ // root element has no namespace and local name "value"
+ Element root = doc.createElementNS(null, "value");
+ if (type != null) {
+ Attr xsi = doc.createAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:xsi");
+ xsi.setValue(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
+ root.setAttributeNodeNS(xsi);
+
+ String prefix = type.getPrefix();
+ if (prefix == null || prefix.length() == 0) {
+ prefix = "ns";
+ }
+ Attr typeXmlns = doc.createAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:" + prefix);
+ typeXmlns.setValue(type.getNamespaceURI());
+ root.setAttributeNodeNS(typeXmlns);
+
+ Attr xsiType = doc.createAttributeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "xsi:type");
+ xsiType.setValue(prefix + ":" + type.getLocalPart());
+ root.setAttributeNodeNS(xsiType);
+ }
+ doc.appendChild(root);
+
+ loadPropertyValue(reader, root);
+ return doc;
+ }
+
+ /**
+ * 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
+ *
+ */
+ public static void loadPropertyValue(XMLStreamReader reader, Node 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 = document.createElementNS(name.getNamespaceURI(), name.getLocalPart());
+
+ // add the attributes for this element
+ int count = reader.getAttributeCount();
+ for (int i = 0; i < count; i++) {
+ String ns = reader.getAttributeNamespace(i);
+ String localPart = reader.getAttributeLocalName(i);
+ String value = reader.getAttributeValue(i);
+ child.setAttributeNS(ns, localPart, value);
+ }
+
+ // push the new element and make it the current one
+ current.appendChild(child);
+ current = child;
+ 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/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/ReferenceLoader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/ReferenceLoader.java
new file mode 100644
index 0000000000..54183d1c72
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/ReferenceLoader.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.core.loader;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.xml.namespace.QName;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.UnrecognizedElementException;
+import org.apache.tuscany.spi.model.BindingDefinition;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.Multiplicity;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+/**
+ * Loads a reference from an XML-based assembly file
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReferenceLoader extends LoaderExtension<ReferenceDefinition> {
+ public static final QName REFERENCE = new QName(SCA_NS, "reference");
+ private static final Map<String, Multiplicity> MULTIPLICITY = new HashMap<String, Multiplicity>(4);
+
+ static {
+ MULTIPLICITY.put("0..1", Multiplicity.ZERO_ONE);
+ MULTIPLICITY.put("1..1", Multiplicity.ONE_ONE);
+ MULTIPLICITY.put("0..n", Multiplicity.ZERO_N);
+ MULTIPLICITY.put("1..n", Multiplicity.ONE_N);
+ }
+
+ @Constructor
+ public ReferenceLoader(@Reference LoaderRegistry registry) {
+ super(registry);
+ }
+
+ public QName getXMLType() {
+ return REFERENCE;
+ }
+
+ public ReferenceDefinition load(ModelObject object, XMLStreamReader reader, DeploymentContext context)
+ throws XMLStreamException, LoaderException {
+ assert REFERENCE.equals(reader.getName());
+ String name = reader.getAttributeValue(null, "name");
+ String multiplicityVal = reader.getAttributeValue(null, "multiplicity");
+ Multiplicity multiplicity = multiplicity(multiplicityVal, Multiplicity.ONE_ONE);
+ ReferenceDefinition referenceDefinition = new ReferenceDefinition();
+ referenceDefinition.setMultiplicity(multiplicity);
+ referenceDefinition.setUri(context.getComponentId().resolve('#' + name));
+ while (true) {
+ switch (reader.next()) {
+ case START_ELEMENT:
+ ModelObject o = registry.load(null, reader, context);
+ if (o instanceof ServiceContract) {
+ referenceDefinition.setServiceContract((ServiceContract) o);
+ } else if (o instanceof BindingDefinition) {
+ referenceDefinition.addBinding((BindingDefinition) o);
+ } else {
+ throw new UnrecognizedElementException(reader.getName());
+ }
+ break;
+ case END_ELEMENT:
+ return referenceDefinition;
+ }
+ }
+ }
+
+ /**
+ * Convert a "multiplicity" attribute to the equivalent enum value.
+ *
+ * @param multiplicity the attribute to convert
+ * @param def the default value
+ * @return the enum equivalent
+ */
+ private static Multiplicity multiplicity(String multiplicity, Multiplicity def) {
+ return multiplicity == null ? def : MULTIPLICITY.get(multiplicity);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/ServiceLoader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/ServiceLoader.java
new file mode 100644
index 0000000000..c5be797cda
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/ServiceLoader.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.core.loader;
+
+import java.net.URI;
+import javax.xml.namespace.QName;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.QualifiedName;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.UnrecognizedElementException;
+import org.apache.tuscany.spi.model.BindingDefinition;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+/**
+ * Loads a service definition from an XML-based assembly file
+ *
+ * @version $Rev$ $Date$
+ */
+public class ServiceLoader extends LoaderExtension<ServiceDefinition> {
+ private static final QName SERVICE = new QName(SCA_NS, "service");
+
+ @Constructor
+ public ServiceLoader(@Reference LoaderRegistry registry) {
+ super(registry);
+ }
+
+ public QName getXMLType() {
+ return SERVICE;
+ }
+
+ public ServiceDefinition load(ModelObject object, XMLStreamReader reader, DeploymentContext context)
+ throws XMLStreamException, LoaderException {
+ assert SERVICE.equals(reader.getName());
+ String name = reader.getAttributeValue(null, "name");
+ URI compositeId = context.getComponentId();
+ URI componentBase = URI.create(compositeId + "/");
+ ServiceDefinition def = new ServiceDefinition();
+ def.setUri(compositeId.resolve('#' + name));
+
+ URI targetUri = null;
+ String promote = reader.getAttributeValue(null, "promote");
+ if (promote != null) {
+ QualifiedName qName = new QualifiedName(promote);
+ targetUri = componentBase.resolve(qName.getFragment());
+ }
+ while (true) {
+ int i = reader.next();
+ switch (i) {
+ case START_ELEMENT:
+ ModelObject o = registry.load(null, reader, context);
+ if (o instanceof ServiceContract) {
+ def.setServiceContract((ServiceContract) o);
+ } else if (o instanceof BindingDefinition) {
+ def.addBinding((BindingDefinition) o);
+ } else {
+ throw new UnrecognizedElementException(reader.getName());
+ }
+ break;
+ case END_ELEMENT:
+ if (SERVICE.equals(reader.getName())) {
+ if (targetUri != null) {
+ def.setTarget(targetUri);
+ }
+ return def;
+ }
+ break;
+ }
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/StringParserPropertyFactory.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/StringParserPropertyFactory.java
new file mode 100644
index 0000000000..eda09d6f11
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/StringParserPropertyFactory.java
@@ -0,0 +1,191 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import java.beans.PropertyEditor;
+import java.beans.PropertyEditorManager;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.PropertyObjectFactory;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.PropertyValue;
+
+import org.apache.tuscany.core.injection.SingletonObjectFactory;
+
+/**
+ * Implementation of StAXPropertyFactory that interprets the XML as
+ *
+ * @version $Rev$ $Date$
+ */
+public class StringParserPropertyFactory implements PropertyObjectFactory {
+
+ public <T> ObjectFactory<T> createObjectFactory(Property<T> property, PropertyValue<T> value)
+ throws LoaderException {
+ String text = value.getValue().getDocumentElement().getTextContent();
+ return new SingletonObjectFactory<T>(createInstance(text, property.getJavaType()));
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> T createInstance(String text, Class<T> type) throws LoaderException {
+ // Class<T> type = property.getJavaType();
+ assert type != null : "property type is null";
+
+ // degenerate case where property type is a String
+ if (String.class.equals(type)) {
+ return type.cast(text);
+ }
+
+ // special handler to convert hexBinary to a byte[]
+ if (byte[].class.equals(type)) {
+ byte[] instance = new byte[text.length() >> 1];
+ for (int i = 0; i < instance.length; i++) {
+ instance[i] =
+ (byte) (Character.digit(text.charAt(i << 1), 16) << 4 | Character.digit(text
+ .charAt((i << 1) + 1), 16));
+ }
+ return type.cast(instance);
+ }
+
+ // does this type have a static valueOf(String) method?
+ try {
+ Method valueOf = type.getMethod("valueOf", String.class);
+ if (Modifier.isStatic(valueOf.getModifiers())) {
+ try {
+ return type.cast(valueOf.invoke(null, text));
+ } catch (IllegalAccessException e) {
+ throw new AssertionError("getMethod returned an inaccessible method");
+ } catch (InvocationTargetException e) {
+ // FIXME we should throw something better
+ throw new LoaderException(e.getCause());
+ }
+ }
+ } catch (NoSuchMethodException e) {
+ // try something else
+ }
+
+ // does this type have a constructor that takes a String?
+ try {
+ Constructor<T> ctr = type.getConstructor(String.class);
+ return ctr.newInstance(text);
+ } catch (NoSuchMethodException e) {
+ // try something else
+ } catch (IllegalAccessException e) {
+ throw new AssertionError("getConstructor returned an inaccessible method");
+ } catch (InstantiationException e) {
+ throw new LoaderException("Property type cannot be instantiated: " + type.getName());
+ } catch (InvocationTargetException e) {
+ // FIXME we should throw something better
+ throw new LoaderException(e.getCause());
+ }
+
+ // do we have a property editor for it?
+ PropertyEditor editor = PropertyEditorManager.findEditor(type);
+ if (editor != null) {
+ try {
+ editor.setAsText(text);
+ return (T) editor.getValue();
+ } catch (IllegalArgumentException e) {
+ // FIXME we should throw something better
+ throw new LoaderException(e);
+
+ }
+ }
+
+ // FIXME we should throw something better
+ throw new LoaderException("Do not have a way to parse a String into a " + type.getName());
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> ObjectFactory<T> createObjectFactory(String text, Property<T> property)
+ throws XMLStreamException, LoaderException {
+ Class<T> type = property.getJavaType();
+ assert type != null : "property type is null";
+
+ // degenerate case where property type is a String
+ if (String.class.equals(type)) {
+ return new SingletonObjectFactory<T>(type.cast(text));
+ }
+
+ // special handler to convert hexBinary to a byte[]
+ if (byte[].class.equals(type)) {
+ byte[] instance = new byte[text.length() >> 1];
+ for (int i = 0; i < instance.length; i++) {
+ instance[i] =
+ (byte) (Character.digit(text.charAt(i << 1), 16) << 4 | Character.digit(text
+ .charAt((i << 1) + 1), 16));
+ }
+ return new SingletonObjectFactory<T>(type.cast(instance));
+ }
+
+ // does this type have a static valueOf(String) method?
+ try {
+ Method valueOf = type.getMethod("valueOf", String.class);
+ if (Modifier.isStatic(valueOf.getModifiers())) {
+ try {
+ return new SingletonObjectFactory<T>(type.cast(valueOf.invoke(null, text)));
+ } catch (IllegalAccessException e) {
+ throw new AssertionError("getMethod returned an inaccessible method");
+ } catch (InvocationTargetException e) {
+ // FIXME we should throw something better
+ throw new LoaderException(e.getCause());
+ }
+ }
+ } catch (NoSuchMethodException e) {
+ // try something else
+ }
+
+ // does this type have a constructor that takes a String?
+ try {
+ Constructor<T> ctr = type.getConstructor(String.class);
+ return new SingletonObjectFactory<T>(ctr.newInstance(text));
+ } catch (NoSuchMethodException e) {
+ // try something else
+ } catch (IllegalAccessException e) {
+ throw new AssertionError("getConstructor returned an inaccessible method");
+ } catch (InstantiationException e) {
+ throw new LoaderException("Property type cannot be instantiated: " + type.getName());
+ } catch (InvocationTargetException e) {
+ // FIXME we should throw something better
+ throw new LoaderException(e.getCause());
+ }
+
+ // do we have a property editor for it?
+ PropertyEditor editor = PropertyEditorManager.findEditor(type);
+ if (editor != null) {
+ try {
+ editor.setAsText(text);
+ return new SingletonObjectFactory<T>((T) editor.getValue());
+ } catch (IllegalArgumentException e) {
+ // FIXME we should throw something better
+ throw new LoaderException(e);
+
+ }
+ }
+
+ // FIXME we should throw something better
+ throw new LoaderException("Do not have a way to parse a String into a " + type.getName());
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/WireLoader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/WireLoader.java
new file mode 100644
index 0000000000..9c60790111
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/loader/WireLoader.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.core.loader;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import javax.xml.namespace.QName;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.QualifiedName;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.InvalidWireException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.WireDefinition;
+
+/**
+ * Loads a wire from an XML-based assembly file
+ *
+ * @version $Rev: 465084 $ $Date: 2006-10-18 04:00:49 +0530 (Wed, 18 Oct 2006) $
+ */
+public class WireLoader extends LoaderExtension<WireDefinition> {
+ private static final QName WIRE = new QName(SCA_NS, "wire");
+ private static final QName SOURCE_URI = new QName(SCA_NS, "source.uri");
+ private static final QName TARGET_URI = new QName(SCA_NS, "target.uri");
+
+ @Constructor
+ public WireLoader(@Reference LoaderRegistry registry) {
+ super(registry);
+ }
+
+ public QName getXMLType() {
+ return WIRE;
+ }
+
+ public WireDefinition load(
+ ModelObject object,
+ XMLStreamReader reader,
+ DeploymentContext deploymentContext) throws XMLStreamException, LoaderException {
+ assert WIRE.equals(reader.getName());
+ WireDefinition wireDefn;
+ URI sourceURI = null;
+ URI targetURI = null;
+ String uriString;
+ while (true) {
+ switch (reader.next()) {
+ case START_ELEMENT:
+ try {
+ if (reader.getName().equals(SOURCE_URI)) {
+ uriString = reader.getElementText();
+ if (uriString != null && uriString.trim().length() > 0) {
+ QualifiedName name = new QualifiedName(uriString);
+ if (name.getPortName() == null) {
+ sourceURI = new URI(uriString);
+ } else {
+ sourceURI = new URI(name.getPartName() + "#" + name.getPortName());
+ }
+ } else {
+ throw new InvalidWireException("Wire source not defined");
+ }
+ } else if (reader.getName().equals(TARGET_URI)) {
+ uriString = reader.getElementText();
+ if (uriString != null && uriString.trim().length() > 0) {
+ QualifiedName name = new QualifiedName(uriString);
+ if (name.getPortName() == null) {
+ targetURI = new URI(uriString);
+ } else {
+ targetURI = new URI(name.getPartName() + "#" + name.getPortName());
+ }
+ } else {
+ throw new InvalidWireException("Wire target not defined");
+ }
+ } else {
+ QName name = reader.getName();
+ throw new InvalidWireException("Unrecognized element in wire ", name.toString());
+ }
+ } catch (URISyntaxException e) {
+ throw new InvalidWireException("Invalid wire uri", e);
+ }
+
+ reader.next();
+ break;
+ case END_ELEMENT:
+ if (reader.getName().equals(WIRE)) {
+ if (sourceURI != null && targetURI != null) {
+ wireDefn = new WireDefinition();
+ wireDefn.setSource(sourceURI);
+ wireDefn.setTarget(targetURI);
+ } else {
+ throw new InvalidWireException("Incomplete wire definition");
+ }
+ return wireDefn;
+ }
+ }
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/AbstractMarshallerExtension.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/AbstractMarshallerExtension.java
new file mode 100644
index 0000000000..cf06d99d18
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/AbstractMarshallerExtension.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.core.marshaller;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.marshaller.ModelMarshaller;
+import org.apache.tuscany.spi.marshaller.ModelMarshallerRegistry;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * Abstract marshaller that supports marshaller registry.
+ *
+ * @version $Revision$ $Date: 2007-03-03 12:17:30 +0000 (Sat, 03 Mar
+ * 2007) $
+ * @param <MD>
+ */
+@EagerInit
+public abstract class AbstractMarshallerExtension<MD extends ModelObject> implements ModelMarshaller<MD> {
+
+ // Private Model marshaller registry
+ protected ModelMarshallerRegistry registry;
+
+ /**
+ * Injects the model marshaller registry.
+ *
+ * @param registry Model marshaller registry.
+ */
+ @Reference
+ public final void setMarshallerRegistry(ModelMarshallerRegistry registry) {
+
+ this.registry = registry;
+
+ Class<MD> marshallerType = getModelObjectType();
+ QName marshallerQName = getModelObjectQName();
+
+ registry.registerMarshaller(marshallerType, marshallerQName, this);
+
+ }
+
+ /**
+ * Gets the qualified name of the XML fragment for the marshalled model
+ * object.
+ *
+ * @return Qualified name of the XML fragment.
+ */
+ protected abstract QName getModelObjectQName();
+
+ /**
+ * Retursn the type of the model object.
+ *
+ * @return Model object type.
+ */
+ protected abstract Class<MD> getModelObjectType();
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/DefaultModelMarshallerRegistry.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/DefaultModelMarshallerRegistry.java
new file mode 100644
index 0000000000..4b4326605b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/DefaultModelMarshallerRegistry.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.marshaller;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.spi.marshaller.MarshalException;
+import org.apache.tuscany.spi.marshaller.ModelMarshaller;
+import org.apache.tuscany.spi.marshaller.ModelMarshallerRegistry;
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * Default map-based implementation of the model marshaller registry.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultModelMarshallerRegistry implements ModelMarshallerRegistry {
+
+ // Marshaller registry
+ private final Map<Class<? extends ModelObject>, ModelMarshaller> marshallerRegistry =
+ new ConcurrentHashMap<Class<? extends ModelObject>, ModelMarshaller>();
+
+ // Unmarshaller registry
+ private final Map<QName, ModelMarshaller> unmarshallerRegistry = new ConcurrentHashMap<QName, ModelMarshaller>();
+
+ /**
+ * Registers a model object marshaller.
+ *
+ * @param <MD> Model object type.
+ * @param modelClass Model obejct class.
+ * @param qname Qualified name of the root element of the marshalled XML.
+ * @param marshaller Model object marshaller.
+ */
+ public <MD extends ModelObject> void registerMarshaller(Class<MD> modelClass,
+ QName qname,
+ ModelMarshaller<MD> marshaller) {
+ marshallerRegistry.put(modelClass, marshaller);
+ unmarshallerRegistry.put(qname, marshaller);
+ }
+
+ /**
+ * Marshalls a model object.
+ *
+ * @param modelObject Model object to be marshalled.
+ * @param writer Writer to which marshalled information is written.
+ */
+ @SuppressWarnings("unchecked")
+ public void marshall(ModelObject modelObject, XMLStreamWriter writer) throws MarshalException {
+
+ ModelMarshaller marshaller = marshallerRegistry.get(modelObject.getClass());
+ if (marshaller == null) {
+ throw new MarshalException("No marshaller defined for " + modelObject.getClass());
+ }
+ marshaller.marshal(modelObject, writer);
+
+ }
+
+ /**
+ * Unmarshalls an XML stream to a model object.
+ *
+ * @param reader Reader from which marshalled information is read.
+ * @return Model object from the marshalled stream.
+ */
+ public ModelObject unmarshall(XMLStreamReader reader) throws MarshalException {
+
+ QName qname = reader.getName();
+
+ ModelMarshaller marshaller = unmarshallerRegistry.get(qname);
+ if (marshaller == null) {
+ throw new MarshalException("No marshaller defined for " + qname);
+ }
+ return marshaller.unmarshal(reader);
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/PhysicalChangeSetMarshaller.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/PhysicalChangeSetMarshaller.java
new file mode 100644
index 0000000000..758c5acda7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/PhysicalChangeSetMarshaller.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.marshaller;
+
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.END_DOCUMENT;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.spi.marshaller.MarshalException;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.physical.PhysicalChangeSet;
+import org.apache.tuscany.spi.model.physical.PhysicalComponentDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireDefinition;
+
+/**
+ * Marshaller for physical changeset.
+ *
+ * @version $Revision$ $Date: 2007-03-10 13:21:21 +0000 (Sat, 10 Mar
+ * 2007) $
+ */
+public class PhysicalChangeSetMarshaller extends AbstractMarshallerExtension<PhysicalChangeSet> {
+
+ // Core marshaller namespace
+ public static final String CORE_NS = "http://tuscany.apache.org/xmlns/marshaller/1.0-SNAPSHOT";
+
+ // Core marshaller prefix
+ public static final String CORE_PREFIX = "core";
+
+ // QName for the root element
+ public static final QName QNAME = new QName(CORE_NS, "changeSet", CORE_PREFIX);
+
+ // Local part for wire
+ public static final String WIRE = "wire";
+
+ // Local part for component
+ public static final String COMPONENT = "component";
+
+ /**
+ * Marshalls a physical change set to the xml writer.
+ */
+ public void marshal(PhysicalChangeSet modelObject, XMLStreamWriter writer) throws MarshalException {
+
+ try {
+ writer.writeStartDocument();
+ writer.writeStartElement(QNAME.getPrefix(), QNAME.getLocalPart(), QNAME.getNamespaceURI());
+ writer.writeNamespace(CORE_PREFIX, CORE_NS);
+ for (PhysicalComponentDefinition pcd : modelObject.getComponentDefinitions()) {
+ registry.marshall(pcd, writer);
+ }
+ for (PhysicalWireDefinition pcd : modelObject.getWireDefinitions()) {
+ registry.marshall(pcd, writer);
+ }
+ writer.writeEndElement();
+ writer.writeEndDocument();
+ } catch (XMLStreamException ex) {
+ throw new MarshalException(ex);
+ }
+
+ }
+
+ /**
+ * Unmarshalls a physical change set from the xml reader.
+ */
+ public PhysicalChangeSet unmarshal(XMLStreamReader reader) throws MarshalException {
+
+ try {
+ PhysicalChangeSet changeSet = new PhysicalChangeSet();
+ while (true) {
+ switch (reader.next()) {
+ case START_ELEMENT:
+ String name = reader.getName().getLocalPart();
+ ModelObject modelObject = registry.unmarshall(reader);
+ if (COMPONENT.equals(name)) {
+ changeSet.addComponentDefinition((PhysicalComponentDefinition)modelObject);
+ } else if (WIRE.equals(name)) {
+ changeSet.addWireDefinition((PhysicalWireDefinition)modelObject);
+ }
+ break;
+ case END_DOCUMENT:
+ return changeSet;
+ }
+ }
+ } catch (XMLStreamException ex) {
+ throw new MarshalException(ex);
+ }
+
+ }
+
+ @Override
+ protected QName getModelObjectQName() {
+ return QNAME;
+ }
+
+ @Override
+ protected Class<PhysicalChangeSet> getModelObjectType() {
+ return PhysicalChangeSet.class;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/PhysicalOperationDefinitionMarshaller.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/PhysicalOperationDefinitionMarshaller.java
new file mode 100644
index 0000000000..8e4dbef240
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/PhysicalOperationDefinitionMarshaller.java
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.marshaller;
+
+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.spi.marshaller.MarshalException;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+
+import static org.apache.tuscany.core.marshaller.PhysicalChangeSetMarshaller.CORE_NS;
+import static org.apache.tuscany.core.marshaller.PhysicalChangeSetMarshaller.CORE_PREFIX;
+
+/**
+ * Marshaller for physical operation definition.
+ *
+ * @version $Revision$ $Date: 2007-03-03 11:36:03 +0000 (Sat, 03 Mar
+ * 2007) $
+ */
+public class PhysicalOperationDefinitionMarshaller extends AbstractMarshallerExtension<PhysicalOperationDefinition> {
+
+ // Operation name attribute
+ public static final String NAME = "name";
+
+ // Callback attribute
+ public static final String CALLBACK = "callback";
+
+ // Return
+ public static final String RETURN_TYPE = "returnType";
+
+ // argument
+ public static final String PARAMETER = "parameter";
+
+ // Conversation sequence
+ public static final String CONVERSATION_SEQUENCE = "conversationSequence";
+
+ // QName for the root element
+ public static final QName QNAME = new QName(CORE_NS, "operation", CORE_PREFIX);
+
+ /**
+ * Marshalls a physical operation to the xml writer.
+ */
+ public void marshal(PhysicalOperationDefinition modelObject, XMLStreamWriter writer) throws MarshalException {
+
+ try {
+ writer.writeStartElement(QNAME.getPrefix(), QNAME.getLocalPart(), QNAME.getNamespaceURI());
+ writer.writeAttribute(NAME, modelObject.getName());
+ writer.writeAttribute(CALLBACK, String.valueOf(modelObject.isCallback()));
+ writer.writeAttribute(CONVERSATION_SEQUENCE, String.valueOf(modelObject.getConversationSequence()));
+ writer.writeStartElement(QNAME.getPrefix(), RETURN_TYPE, QNAME.getNamespaceURI());
+ writer.writeCharacters(modelObject.getReturnType());
+ writer.writeEndElement();
+ for (String parameter : modelObject.getParameters()) {
+ writer.writeStartElement(QNAME.getPrefix(), PARAMETER, QNAME.getNamespaceURI());
+ writer.writeCharacters(parameter);
+ writer.writeEndElement();
+ }
+ writer.writeEndElement();
+ } catch (XMLStreamException ex) {
+ throw new MarshalException(ex);
+ }
+
+ }
+
+ /**
+ * Unmarshalls a physical operation from the xml reader.
+ */
+ public PhysicalOperationDefinition unmarshal(XMLStreamReader reader) throws MarshalException {
+
+ try {
+ PhysicalOperationDefinition operation = new PhysicalOperationDefinition();
+ operation.setName(reader.getAttributeValue(null, NAME));
+ operation.setCallback(Boolean.valueOf(reader.getAttributeValue(null, CALLBACK)));
+ operation.setConversationSequence(Integer.parseInt(reader.getAttributeValue(null, CONVERSATION_SEQUENCE)));
+ while (true) {
+ switch (reader.next()) {
+ case START_ELEMENT:
+ String name = reader.getName().getLocalPart();
+ String textContent = reader.getElementText();
+ if (PARAMETER.equals(name)) {
+ operation.addParameter(textContent);
+ } else if (RETURN_TYPE.equals(name)) {
+ operation.setReturnType(textContent);
+ }
+ break;
+ case END_ELEMENT:
+ if (QNAME.equals(reader.getName())) {
+ return operation;
+ }
+
+ }
+ }
+ } catch (XMLStreamException ex) {
+ throw new MarshalException(ex);
+ }
+
+ }
+
+ @Override
+ protected QName getModelObjectQName() {
+ return QNAME;
+ }
+
+ @Override
+ protected Class<PhysicalOperationDefinition> getModelObjectType() {
+ return PhysicalOperationDefinition.class;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/PhysicalWireDefinitionMarshaller.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/PhysicalWireDefinitionMarshaller.java
new file mode 100644
index 0000000000..510d0b5836
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/PhysicalWireDefinitionMarshaller.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.marshaller;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import static org.apache.tuscany.core.marshaller.PhysicalChangeSetMarshaller.CORE_NS;
+import static org.apache.tuscany.core.marshaller.PhysicalChangeSetMarshaller.CORE_PREFIX;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.spi.marshaller.MarshalException;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition;
+
+/**
+ * Marshaller for physical wire definition.
+ *
+ * @version $Revision$ $Date: 2007-03-03 11:36:03 +0000 (Sat, 03 Mar
+ * 2007) $
+ */
+public class PhysicalWireDefinitionMarshaller extends AbstractMarshallerExtension<PhysicalWireDefinition> {
+
+ // Source
+ public static final String SOURCE = "wireSource";
+
+ // Target
+ public static final String TARGET = "wireTarget";
+
+ // Operation
+ public static final String OPERATION = "operation";
+
+ // QName for the root element
+ public static final QName QNAME = new QName(CORE_NS, "wire", CORE_PREFIX);
+
+ /**
+ * Marshalls a physical wire to the xml writer.
+ */
+ public void marshal(PhysicalWireDefinition modelObject, XMLStreamWriter writer) throws MarshalException {
+
+ try {
+ writer.writeStartElement(QNAME.getPrefix(), QNAME.getLocalPart(), QNAME.getNamespaceURI());
+ for (PhysicalOperationDefinition pod : modelObject.getOperations()) {
+ registry.marshall(pod, writer);
+ }
+ registry.marshall(modelObject.getSource(), writer);
+ registry.marshall(modelObject.getTarget(), writer);
+ writer.writeEndElement();
+ } catch (XMLStreamException ex) {
+ throw new MarshalException(ex);
+ }
+
+ }
+
+ /**
+ * Unmarshalls a physical wire from the xml reader.
+ */
+ public PhysicalWireDefinition unmarshal(XMLStreamReader reader) throws MarshalException {
+
+ try {
+ PhysicalWireDefinition wireDefinition = new PhysicalWireDefinition();
+ while (true) {
+ switch (reader.next()) {
+ case START_ELEMENT:
+ String name = reader.getName().getLocalPart();
+ ModelObject modelObject = registry.unmarshall(reader);
+ if (OPERATION.equals(name)) {
+ wireDefinition.addOperation((PhysicalOperationDefinition)modelObject);
+ } else if (SOURCE.equals(name)) {
+ wireDefinition.setSource((PhysicalWireSourceDefinition)modelObject);
+ } else if (TARGET.equals(name)) {
+ wireDefinition.setTarget((PhysicalWireTargetDefinition)modelObject);
+ }
+ break;
+ case END_ELEMENT:
+ if (QNAME.equals(reader.getName())) {
+ return wireDefinition;
+ }
+ }
+ }
+ } catch (XMLStreamException ex) {
+ throw new MarshalException(ex);
+ }
+
+ }
+
+ @Override
+ protected QName getModelObjectQName() {
+ return QNAME;
+ }
+
+ @Override
+ protected Class<PhysicalWireDefinition> getModelObjectType() {
+ return PhysicalWireDefinition.class;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/AbstractExtensibleMarshallerExtension.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/AbstractExtensibleMarshallerExtension.java
new file mode 100644
index 0000000000..b2446aace0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/AbstractExtensibleMarshallerExtension.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.core.marshaller.extensions;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.core.marshaller.AbstractMarshallerExtension;
+import org.apache.tuscany.spi.marshaller.MarshalException;
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * Abstract marshaller that supports extensible model objects.
+ *
+ * @version $Revision$ $Date: 2007-03-04 18:23:24 +0000 (Sun, 04 Mar
+ * 2007) $
+ * @param <MD>
+ */
+public abstract class AbstractExtensibleMarshallerExtension<MD extends ModelObject> extends
+ AbstractMarshallerExtension<MD> {
+
+ /**
+ * Create the concrete model object.
+ *
+ * @return Concrete model object.
+ */
+ protected abstract MD getConcreteModelObject();
+
+ /**
+ * Handles extensions for unmarshalling.
+ *
+ * @param modelObject Concrete model object.
+ * @param reader Reader from which marshalled data is read.
+ */
+ protected abstract void handleExtension(MD modelObject, XMLStreamReader reader) throws MarshalException;
+
+ /**
+ * Handles extensions for marshalling.
+ *
+ * @param modelObject Concrete model object.
+ * @param reader Writer to which marshalled data is written.
+ */
+ protected abstract void handleExtension(MD modelObject, XMLStreamWriter writer) throws MarshalException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/AbstractIFProviderDefinitionMarshaller.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/AbstractIFProviderDefinitionMarshaller.java
new file mode 100644
index 0000000000..0e6251b522
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/AbstractIFProviderDefinitionMarshaller.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.core.marshaller.extensions;
+
+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.spi.marshaller.MarshalException;
+import org.apache.tuscany.spi.model.physical.InstanceFactoryProviderDefinition;
+
+/**
+ * Abstract marshaller for physical wire target definition.
+ *
+ * @version $Revision$ $Date$
+ */
+public abstract class AbstractIFProviderDefinitionMarshaller<IFPD extends InstanceFactoryProviderDefinition> extends
+ AbstractExtensibleMarshallerExtension<IFPD> {
+
+ /**
+ * Marshalls a physical java reference definition to the xml writer.
+ */
+ public void marshal(IFPD modelObject, XMLStreamWriter writer) throws MarshalException {
+
+ try {
+
+ QName qname = getModelObjectQName();
+ writer.writeStartElement(qname.getPrefix(), qname.getLocalPart(), qname.getNamespaceURI());
+ writer.writeNamespace(qname.getPrefix(), qname.getNamespaceURI());
+
+ handleExtension(modelObject, writer);
+
+ writer.writeEndElement();
+
+ } catch (XMLStreamException ex) {
+ throw new MarshalException(ex);
+ }
+
+ }
+
+ /**
+ * Unmarshalls a java physical reference definition from the xml reader.
+ */
+ public IFPD unmarshal(XMLStreamReader reader) throws MarshalException {
+
+ try {
+ IFPD ifpd = getConcreteModelObject();
+ while (true) {
+ switch (reader.next()) {
+ case START_ELEMENT:
+ handleExtension(ifpd, reader);
+ break;
+ case END_ELEMENT:
+ if (getModelObjectQName().equals(reader.getName())) {
+ return ifpd;
+ }
+
+ }
+ }
+ } catch (XMLStreamException ex) {
+ throw new MarshalException(ex);
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/AbstractPhysicalComponentDefinitionMarshaller.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/AbstractPhysicalComponentDefinitionMarshaller.java
new file mode 100644
index 0000000000..9d7c946984
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/AbstractPhysicalComponentDefinitionMarshaller.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.core.marshaller.extensions;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.spi.marshaller.MarshalException;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.physical.PhysicalComponentDefinition;
+
+/**
+ * Abstract super class for all PCD marshallers.
+ *
+ * @version $Revision$ $Date: 2007-03-03 16:41:22 +0000 (Sat, 03 Mar
+ * 2007) $
+ */
+public abstract class AbstractPhysicalComponentDefinitionMarshaller<PCD extends PhysicalComponentDefinition>
+ extends AbstractExtensibleMarshallerExtension<PCD> {
+
+ // Component id attribute
+ public static final String COMPONENT_ID = "componentId";
+
+ // Group id attribute
+ public static final String GROUP_ID = "groupId";
+
+ // Init level attribute
+ public static final String INIT_LEVEL = "initLevel";
+
+ // Scope attribute
+ private static final String SCOPE = "scope";
+
+ /**
+ * Marshalls a physical change set to the xml writer.
+ */
+ public final void marshal(PCD modelObject, XMLStreamWriter writer) throws MarshalException {
+
+ try {
+
+ QName qname = getModelObjectQName();
+ writer.writeStartElement(qname.getPrefix(), qname.getLocalPart(), qname.getNamespaceURI());
+ writer.writeAttribute(COMPONENT_ID, modelObject.getComponentId().toASCIIString());
+
+ URI groupId = modelObject.getGroupId();
+ if(groupId != null) {
+ writer.writeAttribute(GROUP_ID, groupId.toASCIIString());
+ }
+
+ writer.writeAttribute(SCOPE, modelObject.getScope().toString());
+ writer.writeAttribute(INIT_LEVEL, String.valueOf(modelObject.getInitLevel()));
+
+ writer.writeNamespace(qname.getPrefix(), qname.getNamespaceURI());
+
+ handleExtension(modelObject, writer);
+
+ writer.writeEndElement();
+
+ } catch (XMLStreamException ex) {
+ throw new MarshalException(ex);
+ }
+
+ }
+
+ /**
+ * Unmarshalls a physical change set from the xml reader.
+ */
+ public final PCD unmarshal(XMLStreamReader reader) throws MarshalException {
+
+ try {
+ PCD componentDefinition = getConcreteModelObject();
+ componentDefinition.setComponentId(new URI(reader.getAttributeValue(null, COMPONENT_ID)));
+
+ String groupId = reader.getAttributeValue(null, GROUP_ID);
+ if(groupId != null) {
+ componentDefinition.setGroupId(new URI(groupId));
+ }
+ componentDefinition.setScope(new Scope(reader.getAttributeValue(null, SCOPE)));
+ componentDefinition.setInitLevel(Integer.parseInt(reader.getAttributeValue(null, INIT_LEVEL)));
+ while (true) {
+ switch (reader.next()) {
+ case START_ELEMENT:
+ handleExtension(componentDefinition, reader);
+ break;
+ case END_ELEMENT:
+ if (getModelObjectQName().equals(reader.getName())) {
+ return componentDefinition;
+ }
+
+ }
+ }
+ } catch (XMLStreamException ex) {
+ throw new MarshalException(ex);
+ } catch (URISyntaxException ex) {
+ throw new MarshalException(ex);
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/AbstractPhysicalWireSourceDefinitionMarshaller.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/AbstractPhysicalWireSourceDefinitionMarshaller.java
new file mode 100644
index 0000000000..4dd147e576
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/AbstractPhysicalWireSourceDefinitionMarshaller.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.core.marshaller.extensions;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.spi.marshaller.MarshalException;
+import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition;
+
+/**
+ * Abstract marshaller for physical wire source definition.
+ *
+ * @version $Revision$ $Date$
+ */
+public abstract class AbstractPhysicalWireSourceDefinitionMarshaller<PWSD extends PhysicalWireSourceDefinition> extends
+ AbstractExtensibleMarshallerExtension<PWSD> {
+
+ // URI attribute
+ public static final String URI_ATTRIBUTE = "uri";
+
+ // URI attribute
+ public static final String CALLBACK_URI = "callbackUri";
+
+ // Optimizable attribute
+ public static final String OPTIMIZABLE = "optimizable";
+
+ // Conversational
+ public static final String CONVERSATIONAL = "conversational";
+
+
+ /**
+ * Marshalls a physical java reference definition to the xml writer.
+ */
+ public void marshal(PWSD modelObject, XMLStreamWriter writer) throws MarshalException {
+
+ try {
+
+ QName qname = getModelObjectQName();
+ writer.writeStartElement(qname.getPrefix(), qname.getLocalPart(), qname.getNamespaceURI());
+ writer.writeAttribute(URI_ATTRIBUTE, modelObject.getUri().toASCIIString());
+
+ URI callbackUri = modelObject.getCallbackUri();
+ if(callbackUri != null) {
+ writer.writeAttribute(CALLBACK_URI, callbackUri.toASCIIString());
+ }
+
+ writer.writeAttribute(OPTIMIZABLE, String.valueOf(modelObject.isOptimizable()));
+ writer.writeAttribute(CONVERSATIONAL, String.valueOf(modelObject.isConversational()));
+ writer.writeNamespace(qname.getPrefix(), qname.getNamespaceURI());
+
+ handleExtension(modelObject, writer);
+
+ writer.writeEndElement();
+
+ } catch (XMLStreamException ex) {
+ throw new MarshalException(ex);
+ }
+
+ }
+
+ /**
+ * Unmarshalls a java physical reference definition from the xml reader.
+ */
+ public PWSD unmarshal(XMLStreamReader reader) throws MarshalException {
+
+ try {
+ PWSD sourceDefinition = getConcreteModelObject();
+ sourceDefinition.setUri(new URI(reader.getAttributeValue(null, URI_ATTRIBUTE)));
+
+ String callbackUri = reader.getAttributeValue(null, CALLBACK_URI);
+ if(callbackUri != null) {
+ sourceDefinition.setCallbackUri(new URI(callbackUri));
+ }
+ sourceDefinition.setOptimizable(Boolean.valueOf(reader.getAttributeValue(null, OPTIMIZABLE)));
+ sourceDefinition.setConversational(Boolean.valueOf(reader.getAttributeValue(null, CONVERSATIONAL)));
+ handleExtension(sourceDefinition, reader);
+ return sourceDefinition;
+ } catch (URISyntaxException ex) {
+ throw new MarshalException(ex);
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/AbstractPhysicalWireTargetDefinitionMarshaller.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/AbstractPhysicalWireTargetDefinitionMarshaller.java
new file mode 100644
index 0000000000..355c9535b8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/AbstractPhysicalWireTargetDefinitionMarshaller.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.core.marshaller.extensions;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.spi.marshaller.MarshalException;
+import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition;
+
+/**
+ * Abstract marshaller for physical wire target definition.
+ *
+ * @version $Revision$ $Date$
+ */
+public abstract class AbstractPhysicalWireTargetDefinitionMarshaller<PWTD extends PhysicalWireTargetDefinition> extends
+ AbstractExtensibleMarshallerExtension<PWTD> {
+
+ // Source name attribute
+ public static final String URI_ATTRIBUTE = "uri";
+
+ /**
+ * Marshalls a physical java reference definition to the xml writer.
+ */
+ public void marshal(PWTD modelObject, XMLStreamWriter writer) throws MarshalException {
+
+ try {
+
+ QName qname = getModelObjectQName();
+ writer.writeStartElement(qname.getPrefix(), qname.getLocalPart(), qname.getNamespaceURI());
+ writer.writeAttribute(URI_ATTRIBUTE, modelObject.getUri().toASCIIString());
+ writer.writeNamespace(qname.getPrefix(), qname.getNamespaceURI());
+
+ handleExtension(modelObject, writer);
+
+ writer.writeEndElement();
+
+ } catch (XMLStreamException ex) {
+ throw new MarshalException(ex);
+ }
+
+ }
+
+ /**
+ * Unmarshalls a java physical reference definition from the xml reader.
+ */
+ public PWTD unmarshal(XMLStreamReader reader) throws MarshalException {
+
+ try {
+ PWTD targetDefinition = getConcreteModelObject();
+ targetDefinition.setUri(new URI(reader.getAttributeValue(null, URI_ATTRIBUTE)));
+ handleExtension(targetDefinition, reader);
+ return targetDefinition;
+ } catch (URISyntaxException ex) {
+ throw new MarshalException(ex);
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/instancefactory/ByteCodeIFProviderDefinitionMarshaller.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/instancefactory/ByteCodeIFProviderDefinitionMarshaller.java
new file mode 100644
index 0000000000..8d208a860c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/instancefactory/ByteCodeIFProviderDefinitionMarshaller.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.core.marshaller.extensions.instancefactory;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.tuscany.core.marshaller.extensions.AbstractIFProviderDefinitionMarshaller;
+import org.apache.tuscany.core.marshaller.extensions.java.PojoPhysicalComponentDefinitionMarshaller;
+import org.apache.tuscany.core.model.physical.instancefactory.ByteCodeIFProviderDefinition;
+import org.apache.tuscany.spi.marshaller.MarshalException;
+
+/**
+ * Byte code instance factory definition marshaller.
+ *
+ * @version $Revision$ $Date$
+ */
+public class ByteCodeIFProviderDefinitionMarshaller extends
+ AbstractIFProviderDefinitionMarshaller<ByteCodeIFProviderDefinition> {
+
+ // Byte code extension NS
+ public static final String BYTE_CODE_NS = "http://tuscany.apache.org/xmlns/marshaller/byteCode/1.0-SNAPSHOT";
+
+ // Byte code prefix
+ public static final String BYTE_CODE_PREFIX = "bc";
+
+ // Byte code element
+ public static final String BYTE_CODE = "byteCode";
+
+ // QName for the root element
+ private static final QName QNAME =
+ new QName(BYTE_CODE_NS, PojoPhysicalComponentDefinitionMarshaller.INSTANCE_FACTORY_PROVIDER, BYTE_CODE_PREFIX);
+
+ @Override
+ protected ByteCodeIFProviderDefinition getConcreteModelObject() {
+ return new ByteCodeIFProviderDefinition();
+ }
+
+ @Override
+ protected void handleExtension(ByteCodeIFProviderDefinition modelObject, XMLStreamReader reader)
+ throws MarshalException {
+
+ try {
+ String name = reader.getName().getLocalPart();
+ if(BYTE_CODE.equals(name)) {
+ byte[] encodedByteCode = reader.getElementText().getBytes();
+ byte[] decodedByteCode = Base64.decodeBase64(encodedByteCode);
+ modelObject.setByteCode(decodedByteCode);
+ }
+ } catch(XMLStreamException ex) {
+ throw new MarshalException(ex);
+ }
+
+ }
+
+ @Override
+ protected void handleExtension(ByteCodeIFProviderDefinition modelObject, XMLStreamWriter writer)
+ throws MarshalException {
+
+ try {
+ writer.writeStartElement(QNAME.getPrefix(), BYTE_CODE, QNAME.getNamespaceURI());
+ byte[] encodedByteCode = Base64.encodeBase64(modelObject.getByteCode());
+ writer.writeCharacters(new String(encodedByteCode));
+ writer.writeEndElement();
+ } catch (XMLStreamException ex) {
+ throw new MarshalException(ex);
+ }
+
+ }
+
+ @Override
+ protected QName getModelObjectQName() {
+ return QNAME;
+ }
+
+ @Override
+ protected Class<ByteCodeIFProviderDefinition> getModelObjectType() {
+ return ByteCodeIFProviderDefinition.class;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/instancefactory/ReflectiveIFProviderDefinitionMarshaller.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/instancefactory/ReflectiveIFProviderDefinitionMarshaller.java
new file mode 100644
index 0000000000..dad2fc9940
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/instancefactory/ReflectiveIFProviderDefinitionMarshaller.java
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.marshaller.extensions.instancefactory;
+
+import java.lang.annotation.ElementType;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.core.marshaller.extensions.AbstractIFProviderDefinitionMarshaller;
+import org.apache.tuscany.core.marshaller.extensions.java.PojoPhysicalComponentDefinitionMarshaller;
+import org.apache.tuscany.core.model.physical.instancefactory.InjectionSiteMapping;
+import org.apache.tuscany.core.model.physical.instancefactory.InjectionSource;
+import org.apache.tuscany.core.model.physical.instancefactory.MemberSite;
+import org.apache.tuscany.core.model.physical.instancefactory.ReflectiveIFProviderDefinition;
+import org.apache.tuscany.core.model.physical.instancefactory.InjectionSource.ValueSourceType;
+import org.apache.tuscany.spi.marshaller.MarshalException;
+
+/**
+ * Byte code instance factory definition marshaller.
+ *
+ * @version $Revision$ $Date$
+ */
+public class ReflectiveIFProviderDefinitionMarshaller extends
+ AbstractIFProviderDefinitionMarshaller<ReflectiveIFProviderDefinition> {
+
+ // Byte code extension NS
+ public static final String REFLECTIVE_NS = "http://tuscany.apache.org/xmlns/marshaller/reflect/1.0-SNAPSHOT";
+
+ // Byte code prefix
+ public static final String REFLECTIVE_PREFIX = "reflect";
+
+ // Implementation class
+ public static final String IMPL_CLASS = "implementationClass";
+
+ // Init method
+ public static final String INIT_METHOD = "initMethod";
+
+ // Destroy method
+ public static final String DESTROY_METHOD = "destroyMethod";
+
+ // Constructor argument
+ public static final String CONSTRUCTOR_ARGUMENT = "constructorArgument";
+
+ // Constructor injection name
+ public static final String CDI_SOURCE = "cdiSOurce";
+
+ // Injection site
+ public static final String INJECTION_SITE = "injectionSite";
+
+ // Property
+ public static final String PROPERTY = "property";
+
+ // Injection site type
+ public static final String TYPE = "type";
+
+ // Injection site class
+ public static final String ELEMENT_TYPE = "elementType";
+
+ // Injection site URI
+ public static final String NAME = "name";
+
+ // Property value
+ public static final String VALUE = "value";
+
+ // Injection site name
+ public static final String PHYSICAL_NAME = "physicalName";
+
+ // QName for the root element
+ private static final QName QNAME =
+ new QName(REFLECTIVE_NS, PojoPhysicalComponentDefinitionMarshaller.INSTANCE_FACTORY_PROVIDER, REFLECTIVE_PREFIX);
+
+ @Override
+ protected ReflectiveIFProviderDefinition getConcreteModelObject() {
+ return new ReflectiveIFProviderDefinition();
+ }
+
+ @Override
+ protected void handleExtension(ReflectiveIFProviderDefinition modelObject, XMLStreamReader reader)
+ throws MarshalException {
+
+ try {
+
+ String name = reader.getName().getLocalPart();
+
+ if(IMPL_CLASS.equals(name)) {
+
+ modelObject.setImplementationClass(reader.getElementText());
+
+ } else if(INIT_METHOD.equals(name)) {
+
+ modelObject.setInitMethod(reader.getElementText());
+
+ } else if(DESTROY_METHOD.equals(name)) {
+
+ modelObject.setDestroyMethod(reader.getElementText());
+
+ } else if(CONSTRUCTOR_ARGUMENT.equals(name)) {
+
+ modelObject.addConstructorArgument(reader.getElementText());
+
+ } else if(CDI_SOURCE.equals(name)) {
+
+ InjectionSource injectionSource = new InjectionSource();
+ injectionSource.setName(reader.getAttributeValue(null, NAME));
+ injectionSource.setValueType(ValueSourceType.valueOf(reader.getAttributeValue(null, ELEMENT_TYPE)));
+ modelObject.addCdiSource(injectionSource);
+
+ } else if(INJECTION_SITE.equals(name)) {
+
+ InjectionSiteMapping injectionSite = new InjectionSiteMapping();
+
+ InjectionSource injectionSource = new InjectionSource();
+ injectionSource.setName(reader.getAttributeValue(null, NAME));
+ injectionSource.setValueType(ValueSourceType.valueOf(reader.getAttributeValue(null, TYPE)));
+
+ MemberSite memberSite = new MemberSite();
+ memberSite.setElementType(ElementType.valueOf(reader.getAttributeValue(null, ELEMENT_TYPE)));
+ memberSite.setName(reader.getAttributeValue(null, PHYSICAL_NAME));
+
+ injectionSite.setSite(memberSite);
+ injectionSite.setSource(injectionSource);
+
+ modelObject.addInjectionSite(injectionSite);
+
+ } else if(PROPERTY.equals(name)) {
+
+ InjectionSource injectionSource = new InjectionSource();
+ injectionSource.setName(reader.getAttributeValue(null, NAME));
+ injectionSource.setValueType(ValueSourceType.PROPERTY);
+ modelObject.addPropertValue(injectionSource, reader.getAttributeValue(null, VALUE));
+
+ }
+
+ } catch (XMLStreamException ex) {
+ throw new MarshalException(ex);
+ }
+
+ }
+
+ @Override
+ protected void handleExtension(ReflectiveIFProviderDefinition modelObject, XMLStreamWriter writer)
+ throws MarshalException {
+
+ try {
+
+ writer.writeStartElement(QNAME.getPrefix(), IMPL_CLASS, QNAME.getNamespaceURI());
+ writer.writeCharacters(modelObject.getImplementationClass());
+ writer.writeEndElement();
+
+ String initMethod = modelObject.getInitMethod();
+ if(initMethod != null) {
+ writer.writeStartElement(QNAME.getPrefix(), INIT_METHOD, QNAME.getNamespaceURI());
+ writer.writeCharacters(initMethod);
+ writer.writeEndElement();
+ }
+
+ String destroyMethod = modelObject.getDestroyMethod();
+ if(destroyMethod != null) {
+ writer.writeStartElement(QNAME.getPrefix(), DESTROY_METHOD, QNAME.getNamespaceURI());
+ writer.writeCharacters(modelObject.getDestroyMethod());
+ writer.writeEndElement();
+ }
+
+ for(String constructorArgument : modelObject.getConstructorArguments()) {
+ writer.writeStartElement(QNAME.getPrefix(), CONSTRUCTOR_ARGUMENT, QNAME.getNamespaceURI());
+ writer.writeCharacters(constructorArgument);
+ writer.writeEndElement();
+ }
+
+ for(InjectionSource cdiSource : modelObject.getCdiSources()) {
+ writer.writeStartElement(QNAME.getPrefix(), CDI_SOURCE, QNAME.getNamespaceURI());
+ writer.writeAttribute(NAME, cdiSource.getName());
+ writer.writeAttribute(TYPE, cdiSource.getValueType().name());
+ writer.writeEndElement();
+ }
+
+ for(InjectionSiteMapping injectionSite : modelObject.getInjectionSites()) {
+
+ MemberSite memberSite = injectionSite.getSite();
+ InjectionSource source = injectionSite.getSource();
+
+ writer.writeStartElement(QNAME.getPrefix(), INJECTION_SITE, QNAME.getNamespaceURI());
+ writer.writeAttribute(TYPE, source.getValueType().name());
+ writer.writeAttribute(ELEMENT_TYPE, memberSite.getElementType().name());
+ writer.writeAttribute(NAME, source.getName());
+ writer.writeAttribute(PHYSICAL_NAME, memberSite.getName());
+ writer.writeEndElement();
+ }
+
+ Map<InjectionSource, String> propertyValues = modelObject.getPropertyValues();
+ for(InjectionSource propertySource : propertyValues.keySet()) {
+ writer.writeStartElement(QNAME.getPrefix(), PROPERTY, QNAME.getNamespaceURI());
+ writer.writeAttribute(NAME, propertySource.getName());
+ writer.writeAttribute(TYPE, propertyValues.get(propertySource));
+ writer.writeEndElement();
+ }
+
+ } catch (XMLStreamException ex) {
+ throw new MarshalException(ex);
+ }
+ }
+
+ @Override
+ protected QName getModelObjectQName() {
+ return QNAME;
+ }
+
+ @Override
+ protected Class<ReflectiveIFProviderDefinition> getModelObjectType() {
+ return ReflectiveIFProviderDefinition.class;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/java/JavaPhysicalComponentDefinitionMarshaller.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/java/JavaPhysicalComponentDefinitionMarshaller.java
new file mode 100644
index 0000000000..2ec06257e6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/java/JavaPhysicalComponentDefinitionMarshaller.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.core.marshaller.extensions.java;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.core.marshaller.PhysicalChangeSetMarshaller;
+import org.apache.tuscany.core.model.physical.java.JavaPhysicalComponentDefinition;
+import org.apache.tuscany.spi.marshaller.MarshalException;
+
+/**
+ * Marshaller for Java physical component definitions.
+ *
+ * @version $Revision$ $Date: 2007-03-03 16:41:22 +0000 (Sat, 03 Mar
+ * 2007) $
+ */
+public class JavaPhysicalComponentDefinitionMarshaller extends
+ PojoPhysicalComponentDefinitionMarshaller<JavaPhysicalComponentDefinition> {
+
+ // Core marshaller namespace
+ public static final String JAVA_NS = "http://tuscany.apache.org/xmlns/marshaller/java/1.0-SNAPSHOT";
+
+ // Core marshaller prefix
+ public static final String JAVA_PREFIX = "java";
+
+ // QName for the root element
+ private static final QName QNAME =
+ new QName(JAVA_NS, PhysicalChangeSetMarshaller.COMPONENT, JAVA_PREFIX);
+
+ /**
+ * Gets the qualified name of the XML fragment for the marshalled model
+ * object.
+ *
+ * @return {"http://tuscany.apache.org/xmlns/marshaller/component/java/1.0-SNAPSHOT",
+ * "component"}
+ */
+ @Override
+ protected QName getModelObjectQName() {
+ return QNAME;
+ }
+
+ /**
+ * Retursn the type of the model object.
+ *
+ * @return <code>JavaPhysicalComponentDefinition.class</code>.
+ */
+ @Override
+ protected Class<JavaPhysicalComponentDefinition> getModelObjectType() {
+ return JavaPhysicalComponentDefinition.class;
+ }
+
+ /**
+ * Create the concrete PCD.
+ *
+ * @return An instance of<code>JavaPhysicalComponentDefinition</code>.
+ */
+ @Override
+ protected JavaPhysicalComponentDefinition getConcreteModelObject() {
+ return new JavaPhysicalComponentDefinition();
+ }
+
+ /**
+ * Handles extensions for unmarshalling Java physical component definitions
+ * including the marshalling of base64 encoded instance factory byte code.
+ *
+ * @param componentDefinition Physical component definition.
+ * @param reader Reader from which marshalled data is read.
+ */
+ @Override
+ protected void handlePojoExtension(JavaPhysicalComponentDefinition componentDefinition, XMLStreamReader reader)
+ throws MarshalException {
+ }
+
+ /**
+ * Handles extensions for marshalling Java physical component definitions
+ * including the marshalling of base64 encoded instance factory byte code.
+ *
+ * @param componentDefinition Physical component definition.
+ * @param writer Writer to which marshalled data is written.
+ */
+ @Override
+ protected void handlePojoExtension(JavaPhysicalComponentDefinition componentDefinition, XMLStreamWriter writer)
+ throws MarshalException {
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/java/JavaPhysicalWireSourceDefinitionMarshaller.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/java/JavaPhysicalWireSourceDefinitionMarshaller.java
new file mode 100644
index 0000000000..b661652243
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/java/JavaPhysicalWireSourceDefinitionMarshaller.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.core.marshaller.extensions.java;
+
+import static org.apache.tuscany.core.marshaller.extensions.java.JavaPhysicalComponentDefinitionMarshaller.JAVA_NS;
+import static org.apache.tuscany.core.marshaller.extensions.java.JavaPhysicalComponentDefinitionMarshaller.JAVA_PREFIX;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.core.marshaller.PhysicalWireDefinitionMarshaller;
+import org.apache.tuscany.core.marshaller.extensions.AbstractPhysicalWireSourceDefinitionMarshaller;
+import org.apache.tuscany.core.model.physical.java.JavaPhysicalWireSourceDefinition;
+
+/**
+ * Marshaller for java physical wire source definition.
+ *
+ * @version $Revision$ $Date: 2007-03-03 16:41:22 +0000 (Sat, 03 Mar
+ * 2007) $
+ */
+public class JavaPhysicalWireSourceDefinitionMarshaller extends
+ AbstractPhysicalWireSourceDefinitionMarshaller<JavaPhysicalWireSourceDefinition> {
+
+ // QName for the root element
+ private static final QName QNAME = new QName(JAVA_NS, PhysicalWireDefinitionMarshaller.SOURCE, JAVA_PREFIX);
+
+ /**
+ * Gets the qualified name of the XML fragment for the marshalled model
+ * object.
+ *
+ * @return {"http://tuscany.apache.org/xmlns/marshaller/reference/java/1.0-SNAPSHOT",
+ * "service"}.
+ */
+ @Override
+ protected QName getModelObjectQName() {
+ return QNAME;
+ }
+
+ /**
+ * Returns the type of the model object.
+ *
+ * @return <code>JavaPhysicalWireSourceDefinition.class</code>.
+ */
+ @Override
+ protected Class<JavaPhysicalWireSourceDefinition> getModelObjectType() {
+ return JavaPhysicalWireSourceDefinition.class;
+ }
+
+ /**
+ * Create the concrete model object.
+ *
+ * @return An instance of <code>JavaPhysicalWireSourceDefinition</code>.
+ */
+ @Override
+ protected JavaPhysicalWireSourceDefinition getConcreteModelObject() {
+ return new JavaPhysicalWireSourceDefinition();
+ }
+
+ /**
+ * Handles extensions for unmarshalling Java wire source definitions.
+ *
+ * @param modelObject Concrete model object.
+ * @param reader Reader from which marshalled data is read.
+ */
+ @Override
+ protected void handleExtension(JavaPhysicalWireSourceDefinition modelObject, XMLStreamReader reader) {
+ }
+
+ /**
+ * Handles extensions for marshalling Java wire source definitions.
+ *
+ * @param modelObject Concrete model object.
+ * @param reader Writer to which marshalled data is written.
+ */
+ @Override
+ protected void handleExtension(JavaPhysicalWireSourceDefinition modelObject, XMLStreamWriter writer) {
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/java/JavaPhysicalWireTargetDefinitionMarshaller.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/java/JavaPhysicalWireTargetDefinitionMarshaller.java
new file mode 100644
index 0000000000..1d0de82cf9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/java/JavaPhysicalWireTargetDefinitionMarshaller.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.core.marshaller.extensions.java;
+
+import static org.apache.tuscany.core.marshaller.extensions.java.JavaPhysicalComponentDefinitionMarshaller.JAVA_NS;
+import static org.apache.tuscany.core.marshaller.extensions.java.JavaPhysicalComponentDefinitionMarshaller.JAVA_PREFIX;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.core.marshaller.PhysicalWireDefinitionMarshaller;
+import org.apache.tuscany.core.marshaller.extensions.AbstractPhysicalWireTargetDefinitionMarshaller;
+import org.apache.tuscany.core.model.physical.java.JavaPhysicalWireTargetDefinition;
+
+/**
+ * Marshaller for java physical service definition.
+ *
+ * @version $Revision$ $Date: 2007-03-03 16:41:22 +0000 (Sat, 03 Mar
+ * 2007) $
+ */
+public class JavaPhysicalWireTargetDefinitionMarshaller extends
+ AbstractPhysicalWireTargetDefinitionMarshaller<JavaPhysicalWireTargetDefinition> {
+
+ // QName for the root element
+ private static final QName QNAME = new QName(JAVA_NS, PhysicalWireDefinitionMarshaller.TARGET, JAVA_PREFIX);
+
+ /**
+ * Gets the qualified name of the XML fragment for the marshalled model
+ * object.
+ *
+ * @return {"http://tuscany.apache.org/xmlns/marshaller/reference/java/1.0-SNAPSHOT",
+ * "service"}.
+ */
+ @Override
+ protected QName getModelObjectQName() {
+ return QNAME;
+ }
+
+ /**
+ * Returns the type of the model object.
+ *
+ * @return <code>JavaPhysicalWireTargetDefinition.class</code>.
+ */
+ @Override
+ protected Class<JavaPhysicalWireTargetDefinition> getModelObjectType() {
+ return JavaPhysicalWireTargetDefinition.class;
+ }
+
+ /**
+ * Create the concrete model object.
+ *
+ * @return An instance of <code>JavaPhysicalWireTargetDefinition</code>.
+ */
+ @Override
+ protected JavaPhysicalWireTargetDefinition getConcreteModelObject() {
+ return new JavaPhysicalWireTargetDefinition();
+ }
+
+ /**
+ * Handles extensions for unmarshalling Java wire target definitions.
+ *
+ * @param modelObject Concrete model object.
+ * @param reader Reader from which marshalled data is read.
+ */
+ @Override
+ protected void handleExtension(JavaPhysicalWireTargetDefinition modelObject, XMLStreamReader reader) {
+ }
+
+ /**
+ * Handles extensions for marshalling Java wire target definitions.
+ *
+ * @param modelObject Concrete model object.
+ * @param reader Writer to which marshalled data is written.
+ */
+ @Override
+ protected void handleExtension(JavaPhysicalWireTargetDefinition modelObject, XMLStreamWriter writer) {
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/java/PojoPhysicalComponentDefinitionMarshaller.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/java/PojoPhysicalComponentDefinitionMarshaller.java
new file mode 100644
index 0000000000..e617289af9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/extensions/java/PojoPhysicalComponentDefinitionMarshaller.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.core.marshaller.extensions.java;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.core.marshaller.extensions.AbstractPhysicalComponentDefinitionMarshaller;
+import org.apache.tuscany.spi.marshaller.MarshalException;
+import org.apache.tuscany.spi.model.physical.InstanceFactoryProviderDefinition;
+import org.apache.tuscany.spi.model.physical.POJOComponentDefinition;
+
+/**
+ * Marshaller for Java physical component definitions.
+ *
+ * @version $Revision$ $Date: 2007-03-03 16:41:22 +0000 (Sat, 03 Mar
+ * 2007) $
+ */
+public abstract class PojoPhysicalComponentDefinitionMarshaller<PCD extends POJOComponentDefinition> extends
+ AbstractPhysicalComponentDefinitionMarshaller<PCD> {
+
+ // Classloader id
+ private static final String CLASSLOADER_ID = "classLoaderId";
+
+ // Instance factory provider
+ public static final String INSTANCE_FACTORY_PROVIDER = "instanceFactoryProvider";
+
+ /**
+ * Handles extensions for unmarshalling Java physical component definitions
+ * including the marshalling of base64 encoded instance factory byte code.
+ *
+ * @param componentDefinition Physical component definition.
+ * @param reader Reader from which marshalled data is read.
+ */
+ @Override
+ protected final void handleExtension(PCD componentDefinition, XMLStreamReader reader) throws MarshalException {
+
+ try {
+ String name = reader.getName().getLocalPart();
+ if (CLASSLOADER_ID.equals(name)) {
+ componentDefinition.setClassLoaderId(new URI(reader.getElementText()));
+ } else if (INSTANCE_FACTORY_PROVIDER.equals(name)) {
+ InstanceFactoryProviderDefinition ipcd = (InstanceFactoryProviderDefinition)registry.unmarshall(reader);
+ componentDefinition.setInstanceFactoryProviderDefinition(ipcd);
+ }
+ handlePojoExtension(componentDefinition, reader);
+ } catch (URISyntaxException ex) {
+ throw new MarshalException(ex);
+ } catch (XMLStreamException ex) {
+ throw new MarshalException(ex);
+ }
+
+ }
+
+ /**
+ * Handles extensions for marshalling Java physical component definitions
+ * including the marshalling of base64 encoded instance factory byte code.
+ *
+ * @param componentDefinition Physical component definition.
+ * @param writer Writer to which marshalled data is written.
+ */
+ @Override
+ protected final void handleExtension(PCD componentDefinition, XMLStreamWriter writer) throws MarshalException {
+ try {
+
+ QName qname = getModelObjectQName();
+ writer.writeStartElement(qname.getPrefix(), CLASSLOADER_ID, qname.getNamespaceURI());
+ writer.writeCharacters(componentDefinition.getClassLoaderId().toASCIIString());
+ writer.writeEndElement();
+
+ registry.marshall(componentDefinition.getInstanceFactoryProviderDefinition(), writer);
+ handlePojoExtension(componentDefinition, writer);
+
+ } catch (XMLStreamException ex) {
+ throw new MarshalException(ex);
+ }
+
+ }
+
+ protected abstract void handlePojoExtension(PCD componentDefinition, XMLStreamReader reader)
+ throws MarshalException;
+
+ protected abstract void handlePojoExtension(PCD componentDefinition, XMLStreamWriter writer)
+ throws MarshalException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/NonBlockingIntentDefinition.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/NonBlockingIntentDefinition.java
new file mode 100644
index 0000000000..4e4df7fc5f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/NonBlockingIntentDefinition.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.core.model;
+
+import org.apache.tuscany.spi.model.IntentDefinition;
+
+/**
+ * Represents a non-blocking intent
+ *
+ * @version $Rev$ $Date$
+ */
+public class NonBlockingIntentDefinition extends IntentDefinition {
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/instancefactory/ByteCodeIFProviderDefinition.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/instancefactory/ByteCodeIFProviderDefinition.java
new file mode 100644
index 0000000000..c561b04c1d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/instancefactory/ByteCodeIFProviderDefinition.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.core.model.physical.instancefactory;
+
+import org.apache.tuscany.spi.model.physical.InstanceFactoryProviderDefinition;
+
+/**
+ * Byte code based instance factory provider.
+ *
+ * @version $Revision$ $Date$
+ */
+public class ByteCodeIFProviderDefinition extends InstanceFactoryProviderDefinition {
+
+ // Byte code
+ byte[] byteCode;
+
+ /**
+ * Gets the instance factory byte code.
+ * @return Byte code for the instance factory.
+ */
+ public byte[] getByteCode() {
+ return byteCode;
+ }
+
+ /**
+ * Sets the instance factory byte code.
+ * @param byteCode Instance factory byte code.
+ */
+ public void setByteCode(byte[] byteCode) {
+ this.byteCode = byteCode;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/instancefactory/InjectionSiteMapping.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/instancefactory/InjectionSiteMapping.java
new file mode 100644
index 0000000000..5edc0650f8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/instancefactory/InjectionSiteMapping.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.core.model.physical.instancefactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InjectionSiteMapping {
+
+ // SOurce of the mapping
+ private InjectionSource source;
+
+ // Site of the mapping
+ private MemberSite site;
+
+ /**
+ * Gets the source of the injection.
+ * @return Injection source.
+ */
+ public InjectionSource getSource() {
+ return source;
+ }
+
+ /**
+ * Sets the source of the injection.
+ * @param source Injection source.
+ */
+ public void setSource(InjectionSource source) {
+ this.source = source;
+ }
+
+ /**
+ * Gets the site of the injection.
+ * @return Injection site.
+ */
+ public MemberSite getSite() {
+ return site;
+ }
+
+ /**
+ * Set the size of the injection.
+ * @param site Injection site.
+ */
+ public void setSite(MemberSite site) {
+ this.site = site;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/instancefactory/InjectionSource.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/instancefactory/InjectionSource.java
new file mode 100644
index 0000000000..7bfacc2b9d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/instancefactory/InjectionSource.java
@@ -0,0 +1,96 @@
+package org.apache.tuscany.core.model.physical.instancefactory;
+
+/**
+ * Represents a value source.
+ *
+ * @version $Revision$ $Date$
+ */
+public class InjectionSource {
+
+ // Type
+ private ValueSourceType valueType;
+
+ // Name
+ private String name;
+
+ // Type enumeration
+ public static enum ValueSourceType {
+ CALLBACK,
+ REFERENCE,
+ PROPERTY
+ }
+
+ public InjectionSource() {
+ }
+
+ public InjectionSource(ValueSourceType valueType, String name) {
+ this.valueType = valueType;
+ this.name = name;
+ }
+
+ /**
+ * Sets the type (callback, reference, property
+ *
+ * @return Type.
+ */
+ public ValueSourceType getValueType() {
+ return valueType;
+ }
+
+ /**
+ * Gets the type (callback, reference, property.
+ *
+ * @param valueType Type.
+ */
+ public void setValueType(ValueSourceType valueType) {
+ this.valueType = valueType;
+ }
+
+ /**
+ * Gets the name.
+ *
+ * @return Name.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name.
+ *
+ * @param name Name.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = 31 + ((name == null) ? 0 : name.hashCode());
+ result = 31 * result + ((valueType == null) ? 0 : valueType.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 InjectionSource other = (InjectionSource)obj;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ if (valueType == null) {
+ if (other.valueType != null)
+ return false;
+ } else if (valueType != other.valueType)
+ return false;
+ return true;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/instancefactory/MemberSite.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/instancefactory/MemberSite.java
new file mode 100644
index 0000000000..509f4b1dd1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/instancefactory/MemberSite.java
@@ -0,0 +1,59 @@
+package org.apache.tuscany.core.model.physical.instancefactory;
+
+import java.lang.annotation.ElementType;
+
+/**
+ * Represents a field injection site.
+ *
+ * @version $Revision$ $Date$
+ *
+ */
+public class MemberSite {
+
+ // Element type
+ private ElementType elementType;
+
+ // Name of the site
+ private String name;
+
+ public MemberSite() {
+ }
+
+ public MemberSite(ElementType elementType, String name) {
+ this.elementType = elementType;
+ this.name = name;
+ }
+
+ /**
+ * Gets the name of the site.
+ * @return Site name.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name of the site.
+ * @param name Name of the site.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Gets the element type.
+ * @return Element type.
+ */
+ public ElementType getElementType() {
+ return elementType;
+ }
+
+ /**
+ * Sets the element type.
+ * @param elementType Element type.
+ */
+ public void setElementType(ElementType elementType) {
+ this.elementType = elementType;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/instancefactory/ReflectiveIFProviderDefinition.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/instancefactory/ReflectiveIFProviderDefinition.java
new file mode 100644
index 0000000000..fcfe937ced
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/instancefactory/ReflectiveIFProviderDefinition.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.core.model.physical.instancefactory;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.model.physical.InstanceFactoryProviderDefinition;
+
+/**
+ * Reflection based instance factory.
+ *
+ * @version $Revision$ $Date$
+ */
+public class ReflectiveIFProviderDefinition extends InstanceFactoryProviderDefinition {
+
+ // Implementation class
+ private String implementationClass;
+
+ // Constructor arguments
+ private List<String> constructorArguments = new LinkedList<String>();
+
+ // Init method
+ private String initMethod;
+
+ // Destroy method
+ private String destroyMethod;
+
+ // Constructor injection sites
+ private List<InjectionSource> cdiSources = new LinkedList<InjectionSource>();
+
+ // Injection sites
+ private List<InjectionSiteMapping> injectionSites = new LinkedList<InjectionSiteMapping>();
+
+ // Property sites
+ private Map<InjectionSource, String> propertyValues = new HashMap<InjectionSource, String>();
+
+ /**
+ * returns the constructor argument.
+ * @return the constructorArguments Fully qualified names of the constructor
+ * atgument types.
+ */
+ public List<String> getConstructorArguments() {
+ return Collections.unmodifiableList(constructorArguments);
+ }
+
+ /**
+ * Adds a constructor argument type.
+ * @param constructorArgument the constructorArguments to set
+ */
+ public void addConstructorArgument(String constructorArgument) {
+ constructorArguments.add(constructorArgument);
+ }
+
+ /**
+ * Returns constructor injection names.
+ * @return the constructorNames Constructor injection names.
+ */
+ public List<InjectionSource> getCdiSources() {
+ return Collections.unmodifiableList(cdiSources);
+ }
+
+ /**
+ * Adds a constructor injection name.
+ * @param cdiSource Constructor injection name.
+ */
+ public void addCdiSource(InjectionSource cdiSource) {
+ cdiSources.add(cdiSource);
+ }
+
+ /**
+ * Gets the destroy method.
+ * @return Destroy method name.
+ */
+ public String getDestroyMethod() {
+ return destroyMethod;
+ }
+
+ /**
+ * Sets the destroy method.
+ * @param destroyMethod Destroy method name.
+ */
+ public void setDestroyMethod(String destroyMethod) {
+ this.destroyMethod = destroyMethod;
+ }
+
+ /**
+ * Gets the implementation class.
+ * @return Implementation class.
+ */
+ public String getImplementationClass() {
+ return implementationClass;
+ }
+
+ /**
+ * Sets the implementation class.
+ * @param implementationClass Implementation class.
+ */
+ public void setImplementationClass(String implementationClass) {
+ this.implementationClass = implementationClass;
+ }
+
+ /**
+ * Gets the init method.
+ * @return Init method name.
+ */
+ public String getInitMethod() {
+ return initMethod;
+ }
+
+ /**
+ * Sets the init method.
+ * @param initMethod Init method name.
+ */
+ public void setInitMethod(String initMethod) {
+ this.initMethod = initMethod;
+ }
+
+ /**
+ * Gets the injection sites.
+ * @return Injection sites.
+ */
+ public List<InjectionSiteMapping> getInjectionSites() {
+ return Collections.unmodifiableList(injectionSites);
+ }
+
+ /**
+ * Adds an injection site.
+ * @param injectionSite site.
+ */
+ public void addInjectionSite(InjectionSiteMapping injectionSite) {
+ injectionSites.add(injectionSite);
+ }
+
+ /**
+ * Returns a read-only view of properties.
+ * @return Read-only view of properties.
+ */
+ public Map<InjectionSource, String> getPropertyValues() {
+ return Collections.unmodifiableMap(propertyValues);
+ }
+
+ /**
+ * Adds a property to the definition.
+ * @param injectionSource Injection source for the property.
+ * @param property String value of the property.
+ */
+ public void addPropertValue(InjectionSource injectionSource, String propertValue) {
+ propertyValues.put(injectionSource, propertValue);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/java/JavaPhysicalComponentDefinition.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/java/JavaPhysicalComponentDefinition.java
new file mode 100644
index 0000000000..1fbb485e1d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/java/JavaPhysicalComponentDefinition.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.core.model.physical.java;
+
+import org.apache.tuscany.spi.model.physical.POJOComponentDefinition;
+
+/**
+ * Represents the physical component definition for a Java implementation.
+ *
+ * @version $Rev$ $Date$
+ * @param <T> the implementation class (if known)
+ */
+public class JavaPhysicalComponentDefinition<T> extends POJOComponentDefinition<T> {
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/java/JavaPhysicalWireSourceDefinition.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/java/JavaPhysicalWireSourceDefinition.java
new file mode 100644
index 0000000000..19333d68aa
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/java/JavaPhysicalWireSourceDefinition.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.core.model.physical.java;
+
+import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition;
+
+/**
+ * Models a Java physical wire source definition.
+ *
+ * @version $Revision$ $Date: 2007-02-28 06:29:37 +0000 (Wed, 28 Feb
+ * 2007) $
+ */
+public class JavaPhysicalWireSourceDefinition extends PhysicalWireSourceDefinition {
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/java/JavaPhysicalWireTargetDefinition.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/java/JavaPhysicalWireTargetDefinition.java
new file mode 100644
index 0000000000..a41da39cdf
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/model/physical/java/JavaPhysicalWireTargetDefinition.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.core.model.physical.java;
+
+import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition;
+
+/**
+ * Models a Java physical wire target definition.
+ *
+ * @version $Revision$ $Date: 2007-02-28 06:29:37 +0000 (Wed, 28 Feb
+ * 2007) $
+ */
+public class JavaPhysicalWireTargetDefinition extends PhysicalWireTargetDefinition {
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/DefaultExceptionFormatter.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/DefaultExceptionFormatter.java
new file mode 100644
index 0000000000..14468061e3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/DefaultExceptionFormatter.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.core.monitor;
+
+import java.io.PrintWriter;
+
+import org.apache.tuscany.api.TuscanyException;
+import org.apache.tuscany.api.TuscanyRuntimeException;
+import org.apache.tuscany.host.monitor.ExceptionFormatter;
+
+/**
+ * Performs basics formatting of exceptions for JDK logging
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultExceptionFormatter implements ExceptionFormatter {
+
+ public DefaultExceptionFormatter() {
+ }
+
+ public boolean canFormat(Class<?> type) {
+ return Throwable.class.isAssignableFrom(type);
+ }
+
+ public PrintWriter write(PrintWriter writer, Throwable exception) {
+ if (exception instanceof TuscanyException) {
+ TuscanyException e = (TuscanyException) exception;
+ e.appendBaseMessage(writer);
+ } else if (exception instanceof TuscanyRuntimeException) {
+ TuscanyRuntimeException e = (TuscanyRuntimeException) exception;
+ e.appendBaseMessage(writer);
+ }
+ writer.append("\n");
+ return writer;
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/InvalidLevelException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/InvalidLevelException.java
new file mode 100644
index 0000000000..cf07b0f914
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/InvalidLevelException.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.core.monitor;
+
+/**
+ * Exception indicating an invalid log level has been passed.
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidLevelException extends IllegalArgumentException {
+ private static final long serialVersionUID = 7767234706427841915L;
+ private final String method;
+ private final String level;
+
+ /**
+ * Constructor specifying the method name and the level affected.
+ *
+ * @param method the name of the method being monitored
+ * @param level the invalid log level value
+ */
+ public InvalidLevelException(String method, String level) {
+ super();
+ this.method = method;
+ this.level = level;
+ }
+
+ /**
+ * Returns the name of the method being monitored.
+ *
+ * @return the name of the method being monitored
+ */
+ public String getMethod() {
+ return method;
+ }
+
+ /**
+ * Returns the invalid log level specified.
+ *
+ * @return the invalid log level that was specified
+ */
+ public String getLevel() {
+ return level;
+ }
+
+ public String getMessage() {
+ return "Invalid level for method " + method + " : " + level;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/JavaLoggingMonitorFactory.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/JavaLoggingMonitorFactory.java
new file mode 100644
index 0000000000..4adff1b0db
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/JavaLoggingMonitorFactory.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.core.monitor;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.ResourceBundle;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+import org.osoa.sca.annotations.Service;
+
+import org.apache.tuscany.host.MonitorFactory;
+import org.apache.tuscany.host.monitor.FormatterRegistry;
+
+/**
+ * A factory for monitors that forwards events to a {@link java.util.logging.Logger Java Logging (JSR47) Logger}.
+ *
+ * @version $Rev$ $Date$
+ * @see java.util.logging
+ */
+@Service(interfaces = {MonitorFactory.class, FormatterRegistry.class})
+public class JavaLoggingMonitorFactory extends ProxyMonitorFactory {
+
+ /**
+ * Construct a MonitorFactory that will monitor the specified methods at the specified levels and generate messages
+ * using java.util.logging.
+ * <p/>
+ * The supplied Properties can be used to specify custom log levels for specific monitor methods. The key should be
+ * the method name in form returned by <code>Class.getName() + '#' + Method.getName()</code> and the value the log
+ * level to use as defined by {@link java.util.logging.Level}.
+ *
+ * @param levels definition of custom levels for specific monitored methods, may be null or empty.
+ * @param defaultLevel the default log level to use
+ * @param bundleName the name of a resource bundle that will be passed to the logger
+ * @see java.util.logging.Logger
+ */
+ public JavaLoggingMonitorFactory(Properties levels, Level defaultLevel, String bundleName) {
+ Map<String, Object> configProperties = new HashMap<String, Object>();
+ configProperties.put("levels", levels);
+ configProperties.put("defaultLevel", defaultLevel);
+ configProperties.put("bundleName", bundleName);
+ initInternal(configProperties);
+ }
+
+ /**
+ * Constructs a MonitorFactory that needs to be subsequently configured via a call to {@link #initialize}.
+ */
+ public JavaLoggingMonitorFactory() {
+ }
+
+ protected <T> InvocationHandler createInvocationHandler(Class<T> monitorInterface,
+ Map<String, Level> levels) {
+ ResourceBundle bundle = locateBundle(monitorInterface, bundleName);
+ Logger logger = Logger.getLogger(monitorInterface.getName());
+ return new LoggingHandler(logger, levels, bundle);
+ }
+
+ private class LoggingHandler implements InvocationHandler {
+ private final Logger logger;
+ private final Map<String, Level> methodLevels;
+ private final ResourceBundle bundle;
+
+ public LoggingHandler(Logger logger,
+ Map<String, Level> methodLevels,
+ ResourceBundle bundle
+ ) {
+ this.logger = logger;
+ this.methodLevels = methodLevels;
+ this.bundle = bundle;
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ String sourceMethod = method.getName();
+ Level level = methodLevels.get(sourceMethod);
+ if (level != null && logger.isLoggable(level)) {
+ // construct the key for the resource bundle
+ String className = logger.getName();
+ String key = className + '#' + sourceMethod;
+
+ LogRecord logRecord = new LogRecord(level, key);
+ logRecord.setLoggerName(className);
+ logRecord.setSourceClassName(className);
+ logRecord.setSourceMethodName(sourceMethod);
+ logRecord.setParameters(args);
+ if (args != null) {
+ for (Object o : args) {
+ if (o instanceof Throwable) {
+ logRecord.setMessage(formatException((Throwable) o));
+ break;
+ }
+ }
+ }
+ logRecord.setResourceBundle(bundle);
+ logger.log(logRecord);
+ }
+ return null;
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/MonitorFactoryUtil.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/MonitorFactoryUtil.java
new file mode 100644
index 0000000000..92224d469f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/MonitorFactoryUtil.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.core.monitor;
+
+import org.apache.tuscany.host.MonitorFactory;
+
+import java.util.Map;
+
+/**
+ * Helper for creating MonitorFactory instances.
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+
+public final class MonitorFactoryUtil {
+ /**
+ * Hide the constructor
+ */
+ private MonitorFactoryUtil() {
+ }
+
+ /**
+ * Creates a MonitorFactory instance of the specified type.
+ * @param name fully qualified classname of the desired MonitorFactory type
+ * @param props collection of initialization properties
+ * @return a configured MonitorFactory instance, or null if the factory could not be instantiated.
+ */
+ @SuppressWarnings("unchecked")
+ public static MonitorFactory createMonitorFactory(String name, Map<String, Object> props) {
+ Class<? extends MonitorFactory> clazz;
+ try {
+ clazz = (Class<? extends MonitorFactory>) Class.forName(name);
+ } catch (ClassNotFoundException cnfe) {
+ return null;
+ } catch (ClassCastException cce) {
+ return null;
+ }
+
+ return createMonitorFactory(clazz, props);
+ }
+
+ /**
+ * Creates a MonitorFactory instance of the specified type.
+ * @param mfc class of the desired MonitorFactory type
+ * @param props collection of initialization properties
+ * @return a configured MonitorFactory instance, or null if the factory could not be instantiated.
+ */
+ public static MonitorFactory createMonitorFactory(Class<? extends MonitorFactory> mfc, Map<String, Object> props) {
+ MonitorFactory mf;
+ try {
+ mf = mfc.newInstance();
+ mf.initialize(props);
+ } catch (InstantiationException e) {
+ throw new AssertionError(e);
+ } catch (IllegalAccessException e) {
+ throw new AssertionError(e);
+ }
+ // allow IllegalArgumentException to propogate out
+
+ return mf;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/NullMonitorFactory.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/NullMonitorFactory.java
new file mode 100644
index 0000000000..46c52e38f6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/NullMonitorFactory.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.core.monitor;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Map;
+
+import org.osoa.sca.annotations.EagerInit;
+
+import org.apache.tuscany.host.MonitorFactory;
+import org.apache.tuscany.host.monitor.ExceptionFormatter;
+
+/**
+ * Implementation of a {@link MonitorFactory} that produces implementations that simply return.
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+public class NullMonitorFactory implements MonitorFactory {
+
+ /**
+ * Singleton hander that does nothing.
+ */
+ private static final InvocationHandler NULL_MONITOR = new InvocationHandler() {
+ public Object invoke(Object proxy, Method method, Object[] args) {
+ return null;
+ }
+ };
+
+ public void initialize(Map<String, Object> configProperties) {
+ }
+
+ public <T> T getMonitor(Class<T> monitorInterface) {
+ /*
+ * This uses a reflection proxy to implement the monitor interface which
+ * is a simple but perhaps not very performant solution. Performance
+ * might be improved by code generating an implementation with empty methods.
+ */
+ return monitorInterface.cast(
+ Proxy.newProxyInstance(monitorInterface.getClassLoader(), new Class<?>[]{monitorInterface}, NULL_MONITOR));
+ }
+
+ public void register(ExceptionFormatter formatter) {
+
+ }
+
+ public void unregister(ExceptionFormatter formatter) {
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/ProxyMonitorFactory.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/ProxyMonitorFactory.java
new file mode 100644
index 0000000000..d9ca9e6cfc
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/monitor/ProxyMonitorFactory.java
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.monitor;
+
+import java.util.Map;
+import java.util.Properties;
+import java.util.HashMap;
+import java.util.ResourceBundle;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.WeakHashMap;
+import java.util.logging.Level;
+import java.lang.ref.WeakReference;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.tuscany.host.MonitorFactory;
+import org.apache.tuscany.host.monitor.FormatterRegistry;
+import org.apache.tuscany.host.monitor.ExceptionFormatter;
+import org.apache.tuscany.api.annotation.LogLevel;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public abstract class ProxyMonitorFactory implements MonitorFactory, FormatterRegistry {
+ protected String bundleName;
+ protected final List<ExceptionFormatter> formatters = new ArrayList<ExceptionFormatter>();
+ protected final ExceptionFormatter defaultFormatter = new DefaultExceptionFormatter();
+ protected Level defaultLevel;
+ protected Map<String, Level> levels;
+ private final Map<Class<?>, WeakReference<?>> proxies = new WeakHashMap<Class<?>, WeakReference<?>>();
+
+ public void initialize(Map<String, Object> configProperties) {
+ if (configProperties == null) {
+ return;
+ }
+ initInternal(configProperties);
+ }
+
+ protected void initInternal(Map<String, Object> configProperties) {
+ try {
+ this.defaultLevel = (Level) configProperties.get("defaultLevel");
+ this.bundleName = (String) configProperties.get("bundleName");
+ Properties levels = (Properties) configProperties.get("levels");
+
+ this.levels = new HashMap<String, Level>();
+ if (levels != null) {
+ for (Map.Entry<Object, Object> entry : levels.entrySet()) {
+ String method = (String) entry.getKey();
+ String level = (String) entry.getValue();
+ try {
+ this.levels.put(method, Level.parse(level));
+ } catch (IllegalArgumentException e) {
+ throw new InvalidLevelException(method, level);
+ }
+ }
+ }
+ } catch (ClassCastException cce) {
+ throw new IllegalArgumentException(cce.getLocalizedMessage());
+ }
+ }
+
+ public synchronized <T> T getMonitor(Class<T> monitorInterface) {
+ T proxy = getCachedMonitor(monitorInterface);
+ if (proxy == null) {
+ proxy = createMonitor(monitorInterface);
+ proxies.put(monitorInterface, new WeakReference<T>(proxy));
+ }
+ return proxy;
+ }
+
+ protected <T> T getCachedMonitor(Class<T> monitorInterface) {
+ WeakReference<?> ref = proxies.get(monitorInterface);
+ return (ref != null) ? monitorInterface.cast(ref.get()) : null;
+ }
+
+ protected <T> T createMonitor(Class<T> monitorInterface) {
+ String className = monitorInterface.getName();
+ Method[] methods = monitorInterface.getMethods();
+ Map<String, Level> levels = new HashMap<String, Level>(methods.length);
+ for (Method method : methods) {
+ String key = className + '#' + method.getName();
+ Level level = null;
+ if (this.levels != null) {
+ this.levels.get(key);
+ }
+ // if not specified the in config properties, look for an annotation on the method
+ if (level == null) {
+ LogLevel annotation = method.getAnnotation(LogLevel.class);
+ if (annotation != null && annotation.value() != null) {
+ try {
+ level = Level.parse(annotation.value());
+ } catch (IllegalArgumentException e) {
+ // bad value, just use the default
+ level = defaultLevel;
+ }
+ }
+ }
+ if (level == null) {
+ level = defaultLevel;
+ }
+ levels.put(method.getName(), level);
+ }
+
+ InvocationHandler handler = createInvocationHandler(monitorInterface, levels);
+ Object proxy = Proxy.newProxyInstance(monitorInterface.getClassLoader(),
+ new Class<?>[]{monitorInterface},
+ handler);
+ return monitorInterface.cast(proxy);
+ }
+
+ protected <T> ResourceBundle locateBundle(Class<T> monitorInterface, String bundleName) {
+ Locale locale = Locale.getDefault();
+ ClassLoader cl = monitorInterface.getClassLoader();
+ String packageName = monitorInterface.getPackage().getName();
+ while (true) {
+ try {
+ return ResourceBundle.getBundle(packageName + '.' + bundleName, locale, cl);
+ } catch (MissingResourceException e) {
+ //ok
+ }
+ int index = packageName.lastIndexOf('.');
+ if (index == -1) {
+ break;
+ }
+ packageName = packageName.substring(0, index);
+ }
+ try {
+ return ResourceBundle.getBundle(bundleName, locale, cl);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public void register(ExceptionFormatter formatter) {
+ formatters.add(formatter);
+ }
+
+ public void unregister(ExceptionFormatter formatter) {
+ formatters.remove(formatter);
+ }
+
+ protected abstract <T> InvocationHandler createInvocationHandler(Class<T> monitorInterface,
+ Map<String, Level> levels);
+
+ protected String formatException(Throwable e) {
+ ExceptionFormatter formatter = defaultFormatter;
+ for (ExceptionFormatter candidate : formatters) {
+ if (candidate.canFormat(e.getClass())) {
+ formatter = candidate;
+ break;
+ }
+ }
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ formatter.write(pw, e);
+ format(pw, e);
+ pw.close();
+ return writer.toString();
+ }
+
+ protected void format(PrintWriter writer, Throwable throwable) {
+ writer.println(throwable.getClass().getName());
+ StackTraceElement[] trace = throwable.getStackTrace();
+ for (StackTraceElement aTrace : trace) {
+ writer.println("\tat " + aTrace);
+ }
+ Throwable ourCause = throwable.getCause();
+
+ if (ourCause != null) {
+ printStackTraceAsCause(writer, ourCause, trace);
+ }
+ }
+
+ protected void printStackTraceAsCause(PrintWriter pw,
+ Throwable throwable,
+ StackTraceElement[] causedTrace) {
+
+ // Compute number of frames in common between this and caused
+ StackTraceElement[] trace = throwable.getStackTrace();
+ int m = trace.length - 1;
+ int n = causedTrace.length - 1;
+ while (m >= 0 && n >= 0 && trace[m].equals(causedTrace[n])) {
+ m--;
+ n--;
+ }
+ int framesInCommon = trace.length - 1 - m;
+
+ pw.println("Caused by: " + throwable.getClass().getName());
+
+ ExceptionFormatter formatter = defaultFormatter;
+ for (ExceptionFormatter candidate : formatters) {
+ if (candidate.canFormat(throwable.getClass())) {
+ formatter = candidate;
+ break;
+ }
+ }
+ formatter.write(pw, throwable);
+
+ for (int i = 0; i <= m; i++) {
+ pw.println("\tat " + trace[i]);
+ }
+ if (framesInCommon != 0) {
+ pw.println("\t... " + framesInCommon + " more");
+ }
+
+ // Recurse if we have a cause
+ Throwable ourCause = throwable.getCause();
+ if (ourCause != null) {
+ printStackTraceAsCause(pw, ourCause, trace);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/policy/IntentRegistryImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/policy/IntentRegistryImpl.java
new file mode 100644
index 0000000000..5ea24e4c9b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/policy/IntentRegistryImpl.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.core.policy;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.model.Intent;
+import org.apache.tuscany.spi.model.IntentName;
+import org.apache.tuscany.spi.policy.IntentRegistry;
+
+/**
+ * The default implementation of a data intent registry
+ */
+public class IntentRegistryImpl implements IntentRegistry {
+ private final Map<IntentName, IntentEntry> intentRepo = new HashMap<IntentName, IntentEntry>();
+
+ public Collection<IntentName> getQualifiedIntents(final IntentName qualifiable, final QName artifact) {
+ List<IntentName> result = new ArrayList<IntentName>();
+ for (IntentName intentName : intentRepo.keySet()) {
+ if (intentRepo.get(intentName).getAppliedArtifacts().contains(artifact)
+ && PolicyHelper.isQualifiedIntentFor(intentName, qualifiable, true)) {
+ result.add(intentName);
+ }
+ }
+ return result;
+ }
+
+ public Collection<IntentName> inlineProfileIntent(final Collection<IntentName> intentNameList,
+ final QName artifact) {
+
+ return getConcretIntentsInternal(intentNameList, artifact);
+ }
+
+ private Collection<IntentName> getConcretIntentsInternal(final Collection<IntentName> intentNameList,
+ QName artifact) {
+ List<IntentName> result = new ArrayList<IntentName>();
+ for (IntentName intentName : intentNameList) {
+ IntentEntry intentEntry = intentRepo.get(intentName);
+ if (!intentEntry.isProfileIntent()) {
+ if (intentEntry.getAppliedArtifacts().contains(artifact)) {
+ result.add(intentEntry.getName());
+ }
+ } else {
+ result.addAll(getConcretIntentsInternal(intentEntry.getRequriedIntents(), artifact));
+ }
+ }
+ return result;
+ }
+
+ public boolean isApplicable(IntentName intentName, QName artifact) {
+ if (intentRepo.containsKey(intentName)) {
+ return intentRepo.get(intentName).getAppliedArtifacts().contains(artifact);
+ }
+ return false;
+ }
+
+ public void register(Intent intent) {
+
+ IntentEntry entry = new IntentEntry(intent);
+ // if the qualified intents have been registered, make the intent qualifiable(unqualified)
+ if (!getQualifiedIntents(intent.getName()).isEmpty()) {
+ entry.setQualified(false);
+ }
+ intentRepo.put(intent.getName(), entry);
+ List<IntentName> qualifiables = getAllQualifiableIntent(intent.getName());
+ // set qualifiable intent of this intent unqualified
+ for (IntentName qualifiable : qualifiables) {
+ IntentEntry qualifiableEntry = intentRepo.get(qualifiable);
+ qualifiableEntry.setQualified(false);
+ for (QName artifact : intent.getAppliedArtifacts()) {
+ qualifiableEntry.addAppliedArtifacts(artifact);
+ }
+ }
+ }
+
+ public void unRegister(Intent intent) {
+ if (intentRepo.containsKey(intent.getName())) {
+ IntentEntry intentEntry = intentRepo.get(intent.getName());
+ List<QName> appliedArtifacts = intent.getAppliedArtifacts();
+ for (QName artifact : appliedArtifacts) {
+ if (intentEntry.getAppliedArtifacts().contains(artifact)) {
+ intentEntry.removeappliedArtifact(artifact);
+ }
+ }
+ if (intentEntry.getAppliedArtifacts().isEmpty()) {
+ intentRepo.remove(intent.getName());
+ }
+ }
+ }
+
+ public boolean isQualifiedIntent(IntentName name) {
+ IntentEntry intentEntry = intentRepo.get(name);
+ return intentEntry.isQualified();
+ }
+
+ private List<IntentName> getQualifiedIntents(final IntentName qualifiable) {
+ List<IntentName> result = new ArrayList<IntentName>();
+ for (IntentName intentName : intentRepo.keySet()) {
+ if (PolicyHelper.isQualifiedIntentFor(intentName, qualifiable, true)) {
+ result.add(intentName);
+ }
+ }
+ return result;
+ }
+
+ private List<IntentName> getAllQualifiableIntent(final IntentName qualified) {
+
+ List<IntentName> result = new ArrayList<IntentName>();
+ for (IntentName intentName : intentRepo.keySet()) {
+ if (PolicyHelper.isQualifiedIntentFor(qualified, intentName, false)) {
+ result.add(intentName);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Wrapper class for intent used internally
+ */
+ private static final class IntentEntry extends Intent {
+
+ /**
+ * Whether this intent is qualified, defaults to true
+ */
+ private boolean isQualified = true;
+
+ private IntentEntry(Intent intent) {
+ super(intent.getName(), intent.getDescription());
+ appliedArtifacts.addAll(intent.getAppliedArtifacts());
+ requriedIntents.addAll(intent.getRequriedIntents());
+ }
+
+ public boolean isQualified() {
+ return isQualified;
+ }
+
+ public void setQualified(boolean isQualified) {
+ this.isQualified = isQualified;
+ }
+
+ public void removeappliedArtifact(QName artifact) {
+ appliedArtifacts.remove(artifact);
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyBuilderRegistryImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyBuilderRegistryImpl.java
new file mode 100644
index 0000000000..9c874b5610
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyBuilderRegistryImpl.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.core.policy;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.spi.policy.PolicyBuilderRegistry;
+import org.apache.tuscany.spi.policy.SourcePolicyBuilder;
+import org.apache.tuscany.spi.policy.TargetPolicyBuilder;
+
+/**
+ * The default policy builder
+ *
+ * @version $Rev$ $Date$
+ * @deprecated
+ */
+public class PolicyBuilderRegistryImpl implements PolicyBuilderRegistry {
+
+ private final List<List<SourcePolicyBuilder>> sourceBuilders;
+ private final List<List<TargetPolicyBuilder>> targetBuilders;
+
+ public PolicyBuilderRegistryImpl() {
+ sourceBuilders = new ArrayList<List<SourcePolicyBuilder>>();
+ targetBuilders = new ArrayList<List<TargetPolicyBuilder>>();
+ for (int i = 0; i <= FINAL; i++) {
+ sourceBuilders.add(new ArrayList<SourcePolicyBuilder>());
+ targetBuilders.add(new ArrayList<TargetPolicyBuilder>());
+ }
+ }
+
+ public void registerTargetBuilder(int phase, TargetPolicyBuilder builder) {
+ assert INITIAL <= phase && phase <= FINAL : "Illegal phase";
+ targetBuilders.get(phase).add(builder);
+ }
+
+ public void registerSourceBuilder(int phase, SourcePolicyBuilder builder) {
+ assert INITIAL <= phase && phase <= FINAL : "Illegal phase";
+ sourceBuilders.get(phase).add(builder);
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyEngineImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyEngineImpl.java
new file mode 100644
index 0000000000..308e43c038
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyEngineImpl.java
@@ -0,0 +1,297 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.policy;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.model.IntentMap;
+import org.apache.tuscany.spi.model.IntentName;
+import org.apache.tuscany.spi.model.PolicyContentModel;
+import org.apache.tuscany.spi.model.PolicyModel;
+import org.apache.tuscany.spi.model.PolicySet;
+import org.apache.tuscany.spi.model.PolicySetReference;
+import org.apache.tuscany.spi.model.Qualifier;
+import org.apache.tuscany.spi.policy.IntentRegistry;
+import org.apache.tuscany.spi.policy.PolicyEngine;
+import org.apache.tuscany.spi.policy.PolicySetContainer;
+import org.apache.tuscany.spi.policy.SCATypeManager;
+
+/**
+ * Default implementation of a polciy engine
+ */
+public class PolicyEngineImpl implements PolicyEngine {
+ private final IntentRegistry intentRegistry;
+ private final PolicySetContainer policySetContainer;
+ private final SCATypeManager scaTypeManager;
+
+ public PolicyEngineImpl(IntentRegistry intentRegistry,
+ PolicySetContainer policySetContainer,
+ SCATypeManager scaTypeManager) {
+ this.intentRegistry = intentRegistry;
+ this.policySetContainer = policySetContainer;
+ this.scaTypeManager = scaTypeManager;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Collection<PolicyModel> getPolicy(final IntentName[] requires,
+ final QName[] policySetNames,
+ final QName artifactType) {
+ if (requires == null || requires.length == 0) {
+ return Collections.EMPTY_LIST;
+ }
+ Collection<PolicyModel> result = new ArrayList<PolicyModel>();
+ Collection<IntentName> requiredIntents = java.util.Arrays.asList(requires);
+ Collection<IntentName> matchings;
+
+ //handle profile intents
+ requiredIntents = intentRegistry.inlineProfileIntent(requiredIntents, artifactType);
+ //
+ if (policySetNames != null && policySetNames.length != 0) {
+ Collection<PolicySet> explicitPolicySet = getExplicitPolicySet(policySetNames);
+ matchings = calculateExplicitPolicySet(requiredIntents, explicitPolicySet, artifactType, result);
+ //remove satisfied intent
+ requiredIntents.removeAll(matchings);
+ }
+ //
+ if (requiredIntents.size() > 0) {
+ matchings = findingAdditionalMatching(requiredIntents, artifactType, result);
+ requiredIntents.removeAll(matchings);
+ }
+ //If no collection of policySets covers all required intents, the configuration is not valid.
+ if (requiredIntents.size() > 0) {
+ //TODO
+ }
+ return result;
+ }
+
+
+ private boolean introspectPolicySet(PolicySet policySet, IntentName intent, QName artifactType,
+ Collection<PolicyModel> matchings) {
+ Collection<QName> appliedArtifacts = policySet.getAppliedArtifacts();
+ boolean provide = false;
+ for (QName name : appliedArtifacts) {
+ if (this.scaTypeManager.isTypeOf(artifactType, name)) {
+ provide = true;
+ break;
+ }
+ }
+ if (!provide) {
+ return false;
+ }
+ //1. The required intent matches a provides intent in a policySet exactly.
+ if (policySet.getProvideIntents().contains(intent)) {
+ if (intentRegistry.isQualifiedIntent(intent)) {
+ addMatching(matchings, policySet);
+ } else {
+ Collection<IntentMap> intentMaps = policySet.getIntentMaps();
+ provide = searchIntentMaps(intent, intent, matchings, intentMaps);
+ if (provide) {
+ return true;
+ }
+ }
+ } else if (provideAbstract(intent, policySet.getProvideIntents())) {
+ // 2. The provides intent is a parent (e.g. prefix) of the required intent (in this case the policySet must
+ // have an intentMap entry for the requested qualifier)
+ Collection<IntentMap> intentMaps = policySet.getIntentMaps();
+ IntentName satisfiedIntent = getSatisfiedIntent(intent, policySet.getProvideIntents());
+ provide = searchIntentMaps(intent, satisfiedIntent, matchings, intentMaps);
+ if (provide) {
+ return true;
+ }
+ } else if (provideQualifier(intent, policySet.getProvideIntents())) {
+ //3. The provides intent is more qualified than the required intent
+ if (intentRegistry.isQualifiedIntent(intent)) {
+ addMatching(matchings, policySet);
+ } else {
+ //TODO
+ }
+ }
+
+ //handle PolicySetReference
+ Collection<PolicySetReference> policySetReferences = policySet.getPolicySetReferences();
+ for (PolicySetReference reference : policySetReferences) {
+ PolicySet referencedPolicySet = policySetContainer.getPolicySet(reference.getReference());
+ if (introspectPolicySet(referencedPolicySet, intent, artifactType, matchings)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private void addMatching(Collection<PolicyModel> matching, PolicyContentModel policy) {
+ if (!policy.getWsPolicyAttachments().isEmpty()) {
+ matching.addAll(policy.getWsPolicyAttachments());
+ }
+ if (!policy.getPolicyExtensions().isEmpty()) {
+ matching.addAll(policy.getPolicyExtensions());
+ }
+ }
+
+ private boolean searchIntentMaps(IntentName require,
+ IntentName satisfiedIntent,
+ Collection<PolicyModel> matchings,
+ Collection<IntentMap> intentMaps) {
+ String qualifierName = getQualifierName(require, satisfiedIntent, intentMaps);
+ for (IntentMap intentMap : intentMaps) {
+ if (intentMap.getProvideIntents().contains(qualifierName)) {
+ Collection<Qualifier> qualifiers = intentMap.getQualifiers();
+ for (Qualifier qualifier : qualifiers) {
+ String nextQualifier = getNextQualifier(require, satisfiedIntent, intentMap);
+ if (qualifier.getName().equals(nextQualifier)) {
+ if (intentRegistry
+ .isQualifiedIntent(new IntentName(satisfiedIntent.toString() + "/" + nextQualifier))) {
+ addMatching(matchings, qualifier);
+ return true;
+ } else {
+ require = new IntentName(require.toString() + "/" + intentMap.getDefaultProvideIntent());
+ satisfiedIntent = new IntentName(satisfiedIntent.toString() + "/" + qualifierName);
+ intentMaps = new ArrayList<IntentMap>(0);
+ intentMaps.add(qualifier.getIntentMap());
+ searchIntentMaps(require, satisfiedIntent, matchings, intentMaps);
+ }
+ break;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ private String getQualifierName(IntentName require, IntentName satisfiedIntent, Collection<IntentMap> intentMaps) {
+ String[] requrieQualifiers = require.getQualifiedNames();
+ String[] satisfiedQualifiers = satisfiedIntent.getQualifiedNames();
+ if (requrieQualifiers.length == satisfiedQualifiers.length) {
+ return requrieQualifiers[requrieQualifiers.length - 1];
+ } else if (requrieQualifiers.length > satisfiedQualifiers.length) {
+ return satisfiedQualifiers[satisfiedQualifiers.length - 1];
+ }
+ //TODO raise exception
+ return null;
+ }
+
+ private String getNextQualifier(IntentName require, IntentName satisfiedIntent, IntentMap intentMap) {
+ String[] requrieQualifiers = require.getQualifiedNames();
+ String[] satisfiedQualifiers = satisfiedIntent.getQualifiedNames();
+ if (requrieQualifiers.length > satisfiedQualifiers.length) {
+ return requrieQualifiers[satisfiedQualifiers.length];
+ } else {
+ return intentMap.getDefaultProvideIntent();
+ }
+ }
+
+ private IntentName getSatisfiedIntent(IntentName require, Collection<IntentName> provides) {
+ for (IntentName name : provides) {
+ if (PolicyHelper.isQualifiedIntentFor(require, name, true)) {
+ return name;
+ }
+ }
+ //TODO raise exception
+ return null;
+ }
+
+ private boolean provideAbstract(IntentName require, Collection<IntentName> provides) {
+ for (IntentName name : provides) {
+ if (PolicyHelper.isQualifiedIntentFor(require, name, true)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean provideQualifier(IntentName require, Collection<IntentName> provides) {
+ for (IntentName name : provides) {
+ if (PolicyHelper.isQualifiedIntentFor(name, require, true)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private Collection<PolicySet> getExplicitPolicySet(QName[] policySetNames) {
+ Collection<PolicySet> result = new ArrayList<PolicySet>();
+ for (QName policySetName : policySetNames) {
+ PolicySet set = policySetContainer.getPolicySet(policySetName);
+ if (set != null) {
+ result.add(set);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Step C. Calculate the list of explicitly specified policySets that apply to the target element as follows: 1.
+ * Start with the list of policySets specified in the element's policySet attribute. 2. If any of these explicitly
+ * listed policySets has an XPath expression in its appliesTo attribute that does not match the target element
+ * (binding or implementation) then the composite is invalid. It does not match if the XPath returns a result set
+ * that corresponds to XPath false. For example, a policySet could have appliesTo=”binding.ws/soaphttp”. This would
+ * return false if the target element is a <binding.jms…/> element. 3. Include the values of policySet attributes
+ * from ancestor elements. 4. Remove any policySet where the XPath expression in that policySet’s appliesTo
+ * attribute does not match the target element.
+ * <p/>
+ *
+ * @param requires
+ * @param policies
+ * @return intent names was satisfied by this step.
+ */
+ private Collection<IntentName> calculateExplicitPolicySet(Collection<IntentName> requires,
+ Collection<PolicySet> policies,
+ QName artifactType,
+ Collection<PolicyModel> matchings) {
+ Collection<IntentName> satisfied = new ArrayList<IntentName>();
+ for (IntentName intent : requires) {
+ for (PolicySet policySet : policies) {
+ if (introspectPolicySet(policySet, intent, artifactType, matchings)) {
+ satisfied.add(intent);
+ }
+ }
+ }
+ return satisfied;
+ }
+
+ /**
+ * * The remaining required intents, if any, are provided by finding additional matching policySets within the SCA
+ * system. E. Choose the smallest collection of these policySets that match all remaining required intents. A
+ * policySet matches a required intent if any of the following are true: 1. The required intent matches a provides
+ * intent in a policySet exactly. 2. The provides intent is a parent (e.g. prefix) of the required intent (in this
+ * case the policySet must have an intentMap entry for the requested qualifier) 3. The provides intent is more
+ * qualified than the required intent All intents should now be satisfied.
+ *
+ * @param remainings
+ * @param artifactType
+ * @param matchings
+ */
+ private Collection<IntentName> findingAdditionalMatching(final Collection<IntentName> remainings,
+ QName artifactType,
+ Collection<PolicyModel> matchings) {
+ Collection<IntentName> satisfied = new ArrayList<IntentName>();
+ Collection<PolicySet> policies = this.policySetContainer.getAllPolicySet();
+ for (IntentName intent : remainings) {
+ for (PolicySet policySet : policies) {
+ if (introspectPolicySet(policySet, intent, artifactType, matchings)) {
+ satisfied.add(intent);
+ }
+ }
+ }
+ return satisfied;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyHelper.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyHelper.java
new file mode 100644
index 0000000000..50c94aaf13
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/policy/PolicyHelper.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.core.policy;
+
+import org.apache.tuscany.spi.model.IntentName;
+
+/**
+ * Contains utility methods for dealing with policies
+ */
+public final class PolicyHelper {
+
+ private PolicyHelper() {
+ }
+
+ /**
+ * Whether <code>qualified</code> is qualified intent for <code>qualifiable</code>
+ * <p/>
+ * For example: sec.confidentiality/message is direct qualifier for sec.confidentiality.
+ * sec.confidentiality/message/body is qualifier for sec.confidentiality, but not a direct qualifier
+ *
+ * @param qualified qualified intent name
+ * @param qualifiable qualifiable intent name
+ * @param direct indicate whether to expect <code>qualified</code> is direct qualified intent for
+ * <code>qualifiable</code>
+ * @return whether <code>qualified</code> is qualified intent for <code>qualifiable</code>
+ */
+ public static boolean isQualifiedIntentFor(final IntentName qualified,
+ final IntentName qualifiable,
+ boolean direct) {
+ if (qualified.equals(qualifiable) || !qualified.getDomain().equals(qualifiable.getDomain())) {
+ return false;
+ }
+ boolean result = true;
+ String[] shortArray = qualifiable.getQualifiedNames();
+ String[] longArray = qualified.getQualifiedNames();
+ if (longArray.length - shortArray.length < 1 && !direct) {
+ return false;
+ } else if (direct && longArray.length - shortArray.length != 1) {
+ return false;
+ }
+ for (int i = 0; i < shortArray.length; i++) {
+ if (!shortArray[i].equals(longArray[i])) {
+ result = false;
+ break;
+ }
+ }
+ return result;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/property/PropertyHelper.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/property/PropertyHelper.java
new file mode 100644
index 0000000000..8ed7e8adf6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/property/PropertyHelper.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.core.property;
+
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.Map;
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.parsers.ParserConfigurationException;
+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.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+import org.apache.tuscany.spi.databinding.extension.DOMHelper;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.InvalidValueException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.PropertyValue;
+
+import org.apache.tuscany.core.databinding.xml.InputStream2Node;
+
+/**
+ * The property factory backed by the DataBindingframework
+ */
+public final class PropertyHelper {
+
+ private static final XPathFactory FACTORY = XPathFactory.newInstance();
+
+ private PropertyHelper() {
+ }
+
+ public static Document evaluate(NamespaceContext nsContext, Node node, String xPathExpression)
+ throws XPathExpressionException, ParserConfigurationException {
+ XPath path = FACTORY.newXPath();
+ if (nsContext != null) {
+ path.setNamespaceContext(nsContext);
+ } else {
+ path.setNamespaceContext(new DOMNamespeceContext(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 = DOMHelper.newDocument();
+ if (result instanceof Document) {
+ return document;
+ } else {
+ document.appendChild(document.importNode(result, true));
+ return document;
+ }
+ }
+
+ public static Document loadFromFile(String file, DeploymentContext deploymentContext)
+ throws LoaderException {
+ try {
+ URI uri = URI.create(file);
+ URL url = null;
+ if (!uri.isAbsolute()) {
+ url = deploymentContext.getClassLoader().getResource(file);
+ } else {
+ url = uri.toURL();
+ }
+ InputStream is = url.openStream();
+ try {
+ InputStream2Node transformer = new InputStream2Node();
+ return (Document) transformer.transform(is, null);
+ } finally {
+ is.close();
+ }
+ } catch (Exception e) {
+ throw new LoaderException(e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public static void processProperties(CompositeComponentType<?, ?, Property<?>> parent,
+ ComponentDefinition<? extends Implementation<?>> componentDefinition,
+ DeploymentContext deploymentContext) throws LoaderException {
+ Map<String, PropertyValue<?>> propertyValues = componentDefinition.getPropertyValues();
+
+ for (PropertyValue propValue : propertyValues.values()) {
+ Document node = propValue.getValue();
+ String source = propValue.getSource();
+ String file = propValue.getFile();
+ if (source != null) {
+ try {
+ // $<name>/...
+ 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 = parent.getProperties().get(name);
+ if (compositeProp == null) {
+ throw new InvalidValueException("Source cannot be resolved to a composite property");
+ }
+ Document document = compositeProp.getDefaultValue();
+ // 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?
+ node = evaluate(null, document, xpath);
+ if (node != null) {
+ propValue.setValue(node);
+ }
+ /*Property<?> prop =
+ (Property<?>)componentDefinition.getImplementation().getComponentType()
+ .getProperties().get(propValue.getName());
+ propValue
+ .setValueFactory(new SimplePropertyObjectFactory(prop, propValue.getValue()));*/
+ } else {
+ throw new InvalidValueException("Source has an invalid value");
+ }
+ } catch (Exception e) {
+ throw new LoaderException(e);
+ }
+ } else if (file != null) {
+ node = loadFromFile(propValue.getFile(), deploymentContext);
+ propValue.setValue(node);
+ Property<?> prop =
+ (Property<?>) componentDefinition.getImplementation().getComponentType().getProperties()
+ .get(propValue.getName());
+ propValue.setValueFactory(new SimplePropertyObjectFactory(prop, propValue.getValue()));
+ }
+ }
+ }
+
+ private static class DOMNamespeceContext implements NamespaceContext {
+ private Node node;
+
+ /**
+ * @param node
+ */
+ public DOMNamespeceContext(Node node) {
+ super();
+ this.node = node;
+ }
+
+ public String getNamespaceURI(String prefix) {
+ return node.lookupNamespaceURI(prefix);
+ }
+
+ public String getPrefix(String namespaceURI) {
+ return node.lookupPrefix(namespaceURI);
+ }
+
+ public Iterator getPrefixes(String namespaceURI) {
+ return null;
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/property/PropertyObjectFactoryImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/property/PropertyObjectFactoryImpl.java
new file mode 100644
index 0000000000..8419bc1eba
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/property/PropertyObjectFactoryImpl.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.core.property;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Node;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Scope;
+import org.osoa.sca.annotations.Service;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.databinding.DataBinding;
+import org.apache.tuscany.spi.databinding.DataBindingRegistry;
+import org.apache.tuscany.spi.databinding.Mediator;
+import org.apache.tuscany.spi.databinding.extension.SimpleTypeMapperExtension;
+import org.apache.tuscany.spi.model.ElementInfo;
+import org.apache.tuscany.spi.model.TypeInfo;
+import org.apache.tuscany.spi.loader.PropertyObjectFactory;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.PropertyValue;
+
+import org.apache.tuscany.core.databinding.xml.DOMDataBinding;
+
+@Service(PropertyObjectFactory.class)
+@Scope("COMPOSITE")
+public class PropertyObjectFactoryImpl implements PropertyObjectFactory {
+ private DataBindingRegistry registry;
+ private Mediator mediator;
+
+ public PropertyObjectFactoryImpl() {
+ }
+
+ @Constructor
+ public PropertyObjectFactoryImpl(@Reference DataBindingRegistry registry, @Reference Mediator mediator) {
+ super();
+ this.registry = registry;
+ this.mediator = mediator;
+ }
+
+ public <T> ObjectFactory<T> createObjectFactory(Property<T> property, PropertyValue<T> value) {
+ if (mediator == null) {
+ return new SimplePropertyObjectFactory<T>(property, value.getValue());
+ }
+ return new ObjectFactoryImpl<T>(property, value);
+ }
+
+ public class ObjectFactoryImpl<P> implements ObjectFactory<P> {
+ private Property<P> property;
+ private PropertyValue<P> propertyValue;
+ private DataType<QName> sourceDataType;
+ private DataType<?> targetDataType;
+
+ public ObjectFactoryImpl(Property<P> property, PropertyValue<P> propertyValue) {
+ this.property = property;
+ this.propertyValue = propertyValue;
+ sourceDataType = new DataType<QName>(DOMDataBinding.NAME, Node.class, this.property.getXmlType());
+ TypeInfo typeInfo = null;
+ if (this.property.getXmlType() != null) {
+ if (SimpleTypeMapperExtension.isSimpleXSDType(this.property.getXmlType())) {
+ typeInfo = new TypeInfo(property.getXmlType(), true, null);
+ } else {
+ typeInfo = new TypeInfo(property.getXmlType(), false, null);
+ }
+ } else {
+ typeInfo = new TypeInfo(property.getXmlType(), false, null);
+ }
+
+ ElementInfo elementInfo = new ElementInfo(null, typeInfo);
+ sourceDataType.setMetadata(ElementInfo.class.getName(), elementInfo);
+ Class javaType = this.property.getJavaType();
+ String dataBinding = (String) property.getExtensions().get(DataBinding.class.getName());
+ if (dataBinding != null) {
+ targetDataType = new DataType<Class>(dataBinding, javaType, javaType);
+ } else {
+ targetDataType = registry.introspectType(javaType);
+ if (targetDataType == null) {
+ targetDataType = new DataType<Class>("java.lang.Object", javaType, javaType);
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public P getInstance() throws ObjectCreationException {
+ return (P) mediator.mediate(propertyValue.getValue(), sourceDataType, targetDataType, null);
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/property/SimplePropertyObjectFactory.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/property/SimplePropertyObjectFactory.java
new file mode 100644
index 0000000000..7e9c685bc7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/property/SimplePropertyObjectFactory.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.core.property;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.databinding.extension.SimpleTypeMapperExtension;
+import org.apache.tuscany.spi.model.TypeInfo;
+import org.apache.tuscany.spi.model.Property;
+
+import org.w3c.dom.Document;
+
+public class SimplePropertyObjectFactory<P> implements ObjectFactory<P> {
+ private SimpleTypeMapperExtension typeMapper;
+ private Property<P> property;
+ private Document value;
+ private P instance;
+
+ public SimplePropertyObjectFactory(Property<P> property, Document value) {
+ super();
+
+ this.property = property;
+ this.value = (value == null) ? property.getDefaultValue() : value;
+ this.typeMapper = new SimpleTypeMapperExtension();
+ }
+
+ @SuppressWarnings("unchecked")
+ public P getInstance() throws ObjectCreationException {
+ if (value == null) {
+ return null;
+ }
+ if (instance == null) {
+ String text = value.getDocumentElement().getTextContent();
+ TypeInfo xmlType = null;
+ if (property.getJavaType() == null) {
+ xmlType = new TypeInfo(property.getXmlType(), true, null);
+ } else {
+ xmlType = typeMapper.getXMLType(property.getJavaType());
+ }
+ if (xmlType == null) {
+ throw new IllegalArgumentException("Complex property is not supported.");
+ }
+ instance = (P)typeMapper.toJavaObject(xmlType, text, null);
+ }
+ return instance;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/resolver/AutowireResolver.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/resolver/AutowireResolver.java
new file mode 100644
index 0000000000..8502f8d5f8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/resolver/AutowireResolver.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.core.resolver;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.resolver.ResolutionException;
+
+/**
+ * Implementations are responsible for resolving autowire targets in an SCA Domain. It is assumed that autowire
+ * resolution occurs after resource resolution as service interface classes may be laoded
+ *
+ * @version $Rev$ $Date$
+ */
+public interface AutowireResolver {
+
+ /**
+ * Resolves autowires for a component definition and its decendents
+ *
+ * @param parentDefinition the parent
+ * @param definition the component definition to resolve autowires for
+ * @throws ResolutionException
+ */
+ void resolve(ComponentDefinition<Implementation<CompositeComponentType<?, ?, ?>>> parentDefinition,
+ ComponentDefinition<? extends Implementation<?>> definition) throws ResolutionException;
+
+ /**
+ * Resolves autowires for a composite component type and its decendents
+ *
+ * @param compositeType the component type to resolve autowires for
+ * @throws ResolutionException
+ */
+ @SuppressWarnings({"unchecked"})
+ public void resolve(CompositeComponentType<?, ?, ?> compositeType) throws ResolutionException;
+
+ /**
+ * Adds the uri of a host system service that can be an autowire target
+ *
+ * @param contract the service contract of the system service
+ * @param uri the component uri
+ */
+ void addHostUri(ServiceContract contract, URI uri);
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/resolver/AutowireTargetNotFoundException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/resolver/AutowireTargetNotFoundException.java
new file mode 100644
index 0000000000..1526724ca9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/resolver/AutowireTargetNotFoundException.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.core.resolver;
+
+import org.apache.tuscany.spi.resolver.ResolutionException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AutowireTargetNotFoundException extends ResolutionException {
+ public AutowireTargetNotFoundException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/resolver/DefaultAutowireResolver.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/resolver/DefaultAutowireResolver.java
new file mode 100644
index 0000000000..eab78e25d9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/resolver/DefaultAutowireResolver.java
@@ -0,0 +1,181 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.resolver;
+
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.resolver.ResolutionException;
+
+/**
+ * Default implementation of an autowire resolver
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultAutowireResolver implements AutowireResolver {
+ private Map<ServiceContract, URI> hostAutowire = new HashMap<ServiceContract, URI>();
+
+
+ @SuppressWarnings({"unchecked"})
+ public void resolve(ComponentDefinition<Implementation<CompositeComponentType<?, ?, ?>>> parentDefinition,
+ ComponentDefinition<? extends Implementation<?>> definition)
+ throws ResolutionException {
+ ComponentType<?, ?, ?> type = definition.getImplementation().getComponentType();
+ // resolve autowires
+ if (type instanceof CompositeComponentType) {
+ CompositeComponentType<?, ?, ?> compositeType = (CompositeComponentType<?, ?, ?>) type;
+ for (ComponentDefinition<? extends Implementation<?>> child : compositeType.getComponents().values()) {
+ Implementation<?> implementation = child.getImplementation();
+ ComponentType<?, ?, ?> childType = implementation.getComponentType();
+ if (childType instanceof CompositeComponentType) {
+ // recurse decendents for composites
+ resolve((ComponentDefinition<Implementation<CompositeComponentType<?, ?, ?>>>) definition, child);
+ }
+ Map<String, ReferenceTarget> targets = child.getReferenceTargets();
+ for (ReferenceDefinition reference : childType.getReferences().values()) {
+ ReferenceTarget target = targets.get(reference.getUri().getFragment());
+ if (target == null) {
+ continue;
+ }
+ if (target.isAutowire()) {
+ ServiceContract requiredContract = reference.getServiceContract();
+ resolve(compositeType, requiredContract, target, reference.isRequired());
+ }
+ }
+ }
+ } else {
+ // a leaf level component
+ ComponentType<?, ?, ?> componentType = definition.getImplementation().getComponentType();
+ Map<String, ReferenceTarget> targets = definition.getReferenceTargets();
+ for (ReferenceDefinition reference : componentType.getReferences().values()) {
+ ReferenceTarget target = targets.get(reference.getUri().getFragment());
+ if (target == null) {
+ continue;
+ }
+ if (target.isAutowire()) {
+ ServiceContract requiredContract = reference.getServiceContract();
+ CompositeComponentType<?, ?, ?> ctype = parentDefinition.getImplementation().getComponentType();
+ resolve(ctype, requiredContract, target, reference.isRequired());
+ }
+ }
+ }
+ }
+
+ public void addHostUri(ServiceContract contract, URI uri) {
+ hostAutowire.put(contract, uri);
+ }
+
+ public void resolve(CompositeComponentType<?, ?, ?> compositeType) throws ResolutionException {
+ for (ComponentDefinition<? extends Implementation<?>> child : compositeType.getComponents().values()) {
+ Implementation<?> implementation = child.getImplementation();
+ ComponentType<?, ?, ?> childType = implementation.getComponentType();
+ if (childType instanceof CompositeComponentType) {
+ // recurse decendents for composites
+ resolve(null, child);
+ }
+ Map<String, ReferenceTarget> targets = child.getReferenceTargets();
+ for (ReferenceDefinition reference : childType.getReferences().values()) {
+ ReferenceTarget target = targets.get(reference.getUri().getFragment());
+ if (target == null) {
+ continue;
+ }
+ if (target.isAutowire()) {
+ ServiceContract requiredContract = reference.getServiceContract();
+ resolve(compositeType, requiredContract, target, reference.isRequired());
+ }
+ }
+ }
+ }
+ /**
+ * Performs the actual resolution against a composite TODO this should be extensible allowing for path
+ * optimizations
+ *
+ * @param compositeType the composite component type to resolve against
+ * @param requiredContract the required target contract
+ * @param target the reference target
+ * @param required true if the autowire is required
+ * @throws AutowireTargetNotFoundException
+ *
+ */
+ private void resolve(CompositeComponentType<?, ?, ?> compositeType,
+ ServiceContract requiredContract,
+ ReferenceTarget target,
+ boolean required) throws AutowireTargetNotFoundException {
+ // for now, attempt to match on interface, assume the class can be loaded
+ Class<?> requiredInterface = requiredContract.getInterfaceClass();
+ if (requiredInterface == null) {
+ throw new UnsupportedOperationException("Only interfaces support for autowire");
+ }
+ // autowire to a target in the parent
+ URI targetUri = null;
+ URI candidateUri = null;
+ // find a suitable target, starting with components first
+ for (ComponentDefinition<? extends Implementation<?>> candidate : compositeType.getComponents().values()) {
+ Implementation<?> candidateImpl = candidate.getImplementation();
+ ComponentType<?, ?, ?> candidateType = candidateImpl.getComponentType();
+ for (ServiceDefinition service : candidateType.getServices().values()) {
+ Class<?> serviceInterface = service.getServiceContract().getInterfaceClass();
+ if (serviceInterface == null) {
+ continue;
+ }
+ if (requiredInterface.equals(serviceInterface)) {
+ targetUri = URI.create(candidate.getUri().toString() + service.getUri());
+ break;
+ } else if (candidateUri == null && requiredInterface.isAssignableFrom(serviceInterface)) {
+ candidateUri = URI.create(candidate.getUri().toString() + service.getUri());
+ }
+ }
+ if (targetUri != null) {
+ break;
+ }
+ }
+ if (targetUri == null) {
+ targetUri = resolvePrimordial(requiredContract);
+ }
+ if (candidateUri != null) {
+ targetUri = candidateUri;
+ }
+ if (targetUri != null) {
+ target.addTarget(targetUri);
+ }
+ if (targetUri == null && required) {
+ String uri = target.getReferenceName().toString();
+ throw new AutowireTargetNotFoundException("No suitable target found for", uri);
+ }
+ }
+
+ private URI resolvePrimordial(ServiceContract contract) {
+ Class<?> requiredClass = contract.getInterfaceClass();
+ for (Map.Entry<ServiceContract, URI> entry : hostAutowire.entrySet()) {
+ if (requiredClass.isAssignableFrom(entry.getKey().getInterfaceClass())) {
+ return entry.getValue();
+ }
+ }
+ return null;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/runtime/AbstractRuntime.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/runtime/AbstractRuntime.java
new file mode 100644
index 0000000000..8ecd77092f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/runtime/AbstractRuntime.java
@@ -0,0 +1,374 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.runtime;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import javax.xml.stream.XMLInputFactory;
+
+import org.osoa.sca.ComponentContext;
+
+import static org.apache.tuscany.spi.bootstrap.ComponentNames.TUSCANY_SYSTEM_ROOT;
+import static org.apache.tuscany.spi.bootstrap.ComponentNames.TUSCANY_SYSTEM;
+import static org.apache.tuscany.spi.bootstrap.ComponentNames.TUSCANY_DEPLOYER;
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.builder.Connector;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ComponentException;
+import org.apache.tuscany.spi.component.ComponentManager;
+import org.apache.tuscany.spi.component.RegistrationException;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.component.ScopeContainerMonitor;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.GroupInitializationException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.deployer.Deployer;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.resolver.ResolutionException;
+import org.apache.tuscany.spi.services.management.TuscanyManagementService;
+import org.apache.tuscany.spi.services.classloading.ClassLoaderRegistry;
+
+import org.apache.tuscany.core.bootstrap.Bootstrapper;
+import org.apache.tuscany.core.bootstrap.DefaultBootstrapper;
+import org.apache.tuscany.core.builder.ConnectorImpl;
+import org.apache.tuscany.core.component.ComponentManagerImpl;
+import org.apache.tuscany.core.component.scope.ScopeRegistryImpl;
+import org.apache.tuscany.core.component.scope.CompositeScopeContainer;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation;
+import org.apache.tuscany.core.monitor.NullMonitorFactory;
+import org.apache.tuscany.core.resolver.AutowireResolver;
+import org.apache.tuscany.core.resolver.DefaultAutowireResolver;
+import org.apache.tuscany.core.services.classloading.ClassLoaderRegistryImpl;
+import org.apache.tuscany.host.MonitorFactory;
+import org.apache.tuscany.host.RuntimeInfo;
+import org.apache.tuscany.host.management.ManagementService;
+import org.apache.tuscany.host.monitor.FormatterRegistry;
+import org.apache.tuscany.host.runtime.InitializationException;
+import org.apache.tuscany.host.runtime.TuscanyRuntime;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractRuntime<I extends RuntimeInfo> implements TuscanyRuntime<I> {
+ private static final URI MONITOR_URI = TUSCANY_SYSTEM_ROOT.resolve("MonitorFactory");
+
+ private static final URI COMPONENT_MGR_URI = TUSCANY_SYSTEM_ROOT.resolve("ComponentManager");
+
+ private static final URI AUTOWIRE_RESOLVER_URI = TUSCANY_SYSTEM_ROOT.resolve("AutowireResolver");
+
+ private static final URI SCOPE_REGISTRY_URI = TUSCANY_SYSTEM_ROOT.resolve("ScopeRegistry");
+
+ private static final URI WORK_CONTEXT_URI = TUSCANY_SYSTEM.resolve("WorkContext");
+
+ private static final URI RUNTIME_INFO_URI = TUSCANY_SYSTEM_ROOT.resolve("RuntimeInfo");
+
+ private static final URI CLASSLOADER_REGISTRY_URI = TUSCANY_SYSTEM_ROOT.resolve("ClassLoaderRegistry");
+
+ private static final URI HOST_CLASSLOADER_ID = URI.create("sca://./hostClassLoader");
+
+ private static final URI BOOT_CLASSLOADER_ID = URI.create("sca://./bootClassLoader");
+
+ private final XMLInputFactory xmlFactory;
+ private URL systemScdl;
+ private String applicationName;
+ private URL applicationScdl;
+ private Class<I> runtimeInfoType;
+ private ManagementService<?> managementService;
+
+ // primorial components automatically registered with the runtime
+ /**
+ * Information provided by the host about its runtime environment.
+ */
+ private I runtimeInfo;
+
+ /**
+ * MonitorFactory provided by the host for directing events to its management framework.
+ */
+ private MonitorFactory monitorFactory;
+
+ /**
+ * The ComponentManager that manages all components in this runtime.
+ */
+ private ComponentManager componentManager;
+
+ /**
+ * Registry for ClassLoaders used by this runtime.
+ */
+ private ClassLoaderRegistry classLoaderRegistry;
+
+ private AutowireResolver resolver;
+
+ private Component systemComponent;
+ private Component tuscanySystem;
+
+ private JavaInterfaceProcessorRegistry interfaceProcessorRegistry;
+ private ScopeRegistry scopeRegistry;
+
+ protected AbstractRuntime(Class<I> runtimeInfoType) {
+ this(runtimeInfoType, new NullMonitorFactory());
+ }
+
+ protected AbstractRuntime(Class<I> runtimeInfoType, MonitorFactory monitorFactory) {
+ this.runtimeInfoType = runtimeInfoType;
+ this.monitorFactory = monitorFactory;
+ xmlFactory = XMLInputFactory.newInstance("javax.xml.stream.XMLInputFactory", getClass().getClassLoader());
+ interfaceProcessorRegistry = new JavaInterfaceProcessorRegistryImpl();
+ classLoaderRegistry = new ClassLoaderRegistryImpl();
+ classLoaderRegistry.register(BOOT_CLASSLOADER_ID, getClass().getClassLoader());
+ }
+
+ public URL getSystemScdl() {
+ return systemScdl;
+ }
+
+ public void setSystemScdl(URL systemScdl) {
+ this.systemScdl = systemScdl;
+ }
+
+ public String getApplicationName() {
+ return applicationName;
+ }
+
+ public void setApplicationName(String applicationName) {
+ this.applicationName = applicationName;
+ }
+
+ public URL getApplicationScdl() {
+ return applicationScdl;
+ }
+
+ public void setApplicationScdl(URL applicationScdl) {
+ this.applicationScdl = applicationScdl;
+ }
+
+ public ClassLoader getHostClassLoader() {
+ return classLoaderRegistry.getClassLoader(HOST_CLASSLOADER_ID);
+ }
+
+ public void setHostClassLoader(ClassLoader hostClassLoader) {
+ classLoaderRegistry.register(HOST_CLASSLOADER_ID, hostClassLoader);
+ }
+
+ public I getRuntimeInfo() {
+ return runtimeInfo;
+ }
+
+ public void setRuntimeInfo(I runtimeInfo) {
+ this.runtimeInfo = runtimeInfo;
+ }
+
+ public MonitorFactory getMonitorFactory() {
+ return monitorFactory;
+ }
+
+ public void setMonitorFactory(MonitorFactory monitorFactory) {
+ this.monitorFactory = monitorFactory;
+ }
+
+ public ManagementService<?> getManagementService() {
+ return managementService;
+ }
+
+ public void setManagementService(ManagementService<?> managementService) {
+ this.managementService = managementService;
+ }
+
+ public void initialize() throws InitializationException {
+ URI name = TUSCANY_SYSTEM_ROOT.resolve("main");
+ Bootstrapper bootstrapper = createBootstrapper();
+
+ registerBaselineSystemComponents();
+
+ // deploy the system scdl
+ Collection<Component> components;
+ try {
+ components = deploySystemScdl(bootstrapper.createDeployer(),
+ systemComponent,
+ name,
+ getSystemScdl(),
+ getClass().getClassLoader());
+ } catch (LoaderException e) {
+ throw new InitializationException(e);
+ } catch (BuilderException e) {
+ throw new InitializationException(e);
+ } catch (ComponentException e) {
+ throw new InitializationException(e);
+ } catch (ResolutionException e) {
+ throw new InitializationException(e);
+ }
+ for (Component component : components) {
+ component.start();
+ }
+ Component composite = componentManager.getComponent(name);
+ URI uri = composite.getUri();
+ ScopeContainer scopeContainer = scopeRegistry.getScopeContainer(Scope.COMPOSITE);
+ try {
+ scopeContainer.startContext(uri, uri);
+ } catch (GroupInitializationException e) {
+ throw new InitializationException(e);
+ }
+ }
+
+ public void destroy() {
+ if (tuscanySystem != null) {
+ tuscanySystem.stop();
+ tuscanySystem = null;
+ }
+ if (systemComponent != null) {
+ systemComponent.stop();
+ systemComponent = null;
+ }
+ }
+
+
+ public ComponentContext getComponentContext(URI componentId) {
+ Component component = componentManager.getComponent(componentId);
+ if (component == null) {
+ return null;
+ }
+ return component.getComponentContext();
+ }
+
+ protected Bootstrapper createBootstrapper() {
+ TuscanyManagementService tms = (TuscanyManagementService) getManagementService();
+ resolver = new DefaultAutowireResolver();
+ componentManager = new ComponentManagerImpl(tms, resolver);
+ Connector connector = new ConnectorImpl(componentManager);
+
+ scopeRegistry = new ScopeRegistryImpl();
+ CompositeScopeContainer scopeContainer =
+ new CompositeScopeContainer(monitorFactory.getMonitor(ScopeContainerMonitor.class));
+ scopeContainer.start();
+ scopeRegistry.register(scopeContainer);
+ return new DefaultBootstrapper(getMonitorFactory(),
+ xmlFactory,
+ componentManager,
+ resolver,
+ connector,
+ scopeRegistry);
+ }
+
+ protected void registerBaselineSystemComponents() throws InitializationException {
+ // register the RuntimeInfo provided by the host
+ registerSystemComponent(RUNTIME_INFO_URI, runtimeInfoType, runtimeInfo);
+
+ // register the MonitorFactory provided by the host
+ List<Class<?>> monitorServices = new ArrayList<Class<?>>();
+ monitorServices.add(MonitorFactory.class);
+ monitorServices.add(FormatterRegistry.class);
+ registerSystemComponent(MONITOR_URI, monitorServices, getMonitorFactory());
+
+ // register the ClassLoaderRegistry
+ registerSystemComponent(CLASSLOADER_REGISTRY_URI, ClassLoaderRegistry.class, classLoaderRegistry);
+
+ // register the ComponentManager to that the fabric can wire to it
+ registerSystemComponent(COMPONENT_MGR_URI, ComponentManager.class, componentManager);
+
+ // register the AutowireResolver
+ registerSystemComponent(AUTOWIRE_RESOLVER_URI, AutowireResolver.class, resolver);
+
+ // register the ScopeRegistry
+ registerSystemComponent(SCOPE_REGISTRY_URI, ScopeRegistry.class, scopeRegistry);
+ }
+
+ protected <S, I extends S> void registerSystemComponent(URI uri, Class<S> type, I component)
+ throws InitializationException {
+ try {
+ JavaServiceContract<S> contract = interfaceProcessorRegistry.introspect(type);
+ componentManager.registerJavaObject(uri, contract, component);
+ } catch (RegistrationException e) {
+ throw new InitializationException(e);
+ } catch (InvalidServiceContractException e) {
+ throw new InitializationException(e);
+ }
+ }
+
+ protected <I> void registerSystemComponent(URI uri, List<Class<?>> types, I component)
+ throws InitializationException {
+ try {
+ List<JavaServiceContract<?>> contracts = new ArrayList<JavaServiceContract<?>>();
+ for (Class<?> type : types) {
+ contracts.add(interfaceProcessorRegistry.introspect(type));
+
+ }
+ componentManager.registerJavaObject(uri, contracts, component);
+ } catch (RegistrationException e) {
+ throw new InitializationException(e);
+ } catch (InvalidServiceContractException e) {
+ throw new InitializationException(e);
+ }
+ }
+
+ protected Collection<Component> deploySystemScdl(Deployer deployer,
+ Component parent,
+ URI name,
+ URL systemScdl,
+ ClassLoader systemClassLoader)
+ throws LoaderException, BuilderException, ComponentException, ResolutionException {
+
+ SystemCompositeImplementation impl = new SystemCompositeImplementation();
+ impl.setScdlLocation(systemScdl);
+ impl.setClassLoader(systemClassLoader);
+ ComponentDefinition<SystemCompositeImplementation> definition =
+ new ComponentDefinition<SystemCompositeImplementation>(name, impl);
+
+ return deployer.deploy(parent, definition);
+ }
+
+
+ protected ComponentManager getComponentManager() {
+ return componentManager;
+ }
+
+ protected ScopeRegistry getScopeRegistry() {
+ return scopeRegistry;
+ }
+
+ protected WorkContext getWorkContext() {
+ try {
+ AtomicComponent component =
+ (AtomicComponent) getComponentManager().getComponent(WORK_CONTEXT_URI);
+ return (WorkContext) component.getTargetInstance();
+ } catch (TargetResolutionException e) {
+ throw new AssertionError(e);
+ }
+ }
+
+
+ protected Deployer getDeployer() {
+ try {
+ AtomicComponent component =
+ (AtomicComponent) getComponentManager().getComponent(TUSCANY_DEPLOYER);
+ return (Deployer) component.getTargetInstance();
+ } catch (TargetResolutionException e) {
+ throw new AssertionError(e);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/artifact/LocalMavenRepository.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/artifact/LocalMavenRepository.java
new file mode 100644
index 0000000000..f50e8544a3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/artifact/LocalMavenRepository.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.core.services.artifact;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Collection;
+
+import org.osoa.sca.annotations.Property;
+
+import org.apache.tuscany.spi.services.artifact.Artifact;
+import org.apache.tuscany.spi.services.artifact.ArtifactRepository;
+
+/**
+ * An implementation of ArtifactRepository that uses a local Maven2 repository.
+ *
+ * @version $Rev$ $Date$
+ */
+public class LocalMavenRepository implements ArtifactRepository {
+ private File localRepo;
+
+ /**
+ * Constructor specifying the location of the local repo. Relative paths are resolved against the user's home
+ * directory.
+ *
+ * @param repoPath the path to the local repo
+ */
+ public LocalMavenRepository(@Property(name = "repository") String repoPath) {
+ String home = AccessController.doPrivileged(new PrivilegedAction<String>() {
+ public String run() {
+ return System.getProperty("user.home");
+ }
+ });
+ this.localRepo = new File(home, repoPath);
+ }
+
+ public void resolve(Artifact artifact) {
+ if (artifact.getUrl() != null) {
+ return;
+ }
+
+ String path = getPath(artifact);
+ File artifactFile = new File(localRepo, path);
+ if (artifactFile.exists()) {
+ try {
+ artifact.setUrl(artifactFile.toURI().toURL());
+ } catch (MalformedURLException e) {
+ // toURI should have escaped the filename to allow it to be converted to a URL
+ throw new AssertionError();
+ }
+ }
+ }
+
+ /**
+ * Return the path into the repo for an artifact. The path for an artifact is ${group.replace('.',
+ * '/')}/$[name}/${version}/${name}-${version}[-${classifier}].${type}
+ *
+ * @param artifact the artifact to resolve
+ * @return the path into the repo for the artifact
+ */
+ protected String getPath(Artifact artifact) {
+ StringBuilder builder = new StringBuilder();
+ if (artifact.getGroup() != null) {
+ builder.append(artifact.getGroup().replace('.', '/')).append('/');
+ }
+ builder.append(artifact.getName()).append('/');
+ builder.append(artifact.getVersion()).append('/');
+
+ builder.append(artifact.getName()).append('-').append(artifact.getVersion());
+ if (artifact.getClassifier() != null) {
+ builder.append('-').append(artifact.getClassifier());
+ }
+ builder.append('.').append(artifact.getType());
+ return builder.toString();
+ }
+
+ public void resolve(Collection<? extends Artifact> artifacts) {
+ for (Artifact artifact : artifacts) {
+ resolve(artifact);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/classloading/ClassLoaderRegistryImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/classloading/ClassLoaderRegistryImpl.java
new file mode 100644
index 0000000000..afa7f64246
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/classloading/ClassLoaderRegistryImpl.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.core.services.classloading;
+
+import java.net.URI;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.services.classloading.ClassLoaderRegistry;
+import org.apache.tuscany.spi.services.classloading.DuplicateClassLoaderException;
+
+/**
+ * Implementation of a registry for classloaders.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ClassLoaderRegistryImpl implements ClassLoaderRegistry {
+ private final Map<URI, ClassLoader> registry = new ConcurrentHashMap<URI, ClassLoader>();
+
+ public synchronized void register(URI id, ClassLoader classLoader) throws DuplicateClassLoaderException {
+ if (registry.containsKey(id)) {
+ throw new DuplicateClassLoaderException("Duplicate class loader", id.toString());
+ }
+ registry.put(id, classLoader);
+ }
+
+ public ClassLoader getClassLoader(URI id) {
+ return registry.get(id);
+ }
+
+ public ClassLoader unregister(URI id) {
+ return registry.remove(id);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/AssemblyServiceImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/AssemblyServiceImpl.java
new file mode 100644
index 0000000000..a1c3a3966b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/AssemblyServiceImpl.java
@@ -0,0 +1,308 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.services.deployment;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.deployer.ChangeSetHandler;
+import org.apache.tuscany.spi.deployer.ChangeSetHandlerRegistry;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.generator.GenerationException;
+import org.apache.tuscany.spi.generator.GeneratorContext;
+import org.apache.tuscany.spi.generator.GeneratorRegistry;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.marshaller.MarshalException;
+import org.apache.tuscany.spi.marshaller.ModelMarshallerRegistry;
+import org.apache.tuscany.spi.model.BindingDefinition;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalChangeSet;
+import org.apache.tuscany.spi.resolver.ResolutionException;
+import org.apache.tuscany.spi.services.discovery.DiscoveryException;
+import org.apache.tuscany.spi.services.discovery.DiscoveryService;
+
+import org.apache.tuscany.core.deployer.RootDeploymentContext;
+import org.apache.tuscany.core.generator.DefaultGeneratorContext;
+import org.apache.tuscany.core.resolver.AutowireResolver;
+import org.apache.tuscany.host.deployment.AssemblyService;
+import org.apache.tuscany.host.deployment.DeploymentException;
+import org.apache.tuscany.host.deployment.UnsupportedContentTypeException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+public class AssemblyServiceImpl implements AssemblyService, ChangeSetHandlerRegistry {
+ private static final URI DOMAIN_URI = URI.create("tuscany://./domain");
+ private final GeneratorRegistry generatorRegistry;
+ private final LoaderRegistry loaderRegistry;
+ private final AutowireResolver autowireResolver;
+ private final ScopeRegistry scopeRegistry;
+ private final XMLInputFactory xmlFactory;
+ private final ModelMarshallerRegistry marshallerRegistry;
+ private final DiscoveryService discoveryService;
+ private ComponentDefinition<CompositeImplementation> domain;
+ private final Map<String, ChangeSetHandler> registry = new HashMap<String, ChangeSetHandler>();
+
+ public AssemblyServiceImpl(@Reference LoaderRegistry loaderRegistry,
+ @Reference GeneratorRegistry generatorRegistry,
+ @Reference AutowireResolver autowireResolver,
+ @Reference ScopeRegistry scopeRegistry,
+ @Reference ModelMarshallerRegistry marshallerRegistry,
+ @Reference DiscoveryService discoveryService) {
+ this.loaderRegistry = loaderRegistry;
+ this.generatorRegistry = generatorRegistry;
+ this.autowireResolver = autowireResolver;
+ this.scopeRegistry = scopeRegistry;
+ this.marshallerRegistry = marshallerRegistry;
+ this.discoveryService = discoveryService;
+ xmlFactory = XMLInputFactory.newInstance("javax.xml.stream.XMLInputFactory", getClass().getClassLoader());
+ domain = createDomain();
+ }
+
+ public void applyChanges(URL changeSet) throws DeploymentException, IOException {
+ if (changeSet == null) {
+ throw new IllegalArgumentException("changeSet is null");
+ }
+
+ URLConnection connection = changeSet.openConnection();
+ String contentType = connection.getContentType();
+ //todo try and figure out content type from the URL
+ if (contentType == null) {
+ throw new UnsupportedContentTypeException(null, changeSet.toString());
+ }
+
+ InputStream is = connection.getInputStream();
+ try {
+ applyChanges(is, contentType);
+ } finally {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+
+ public void applyChanges(InputStream changeSet, String contentType) throws DeploymentException, IOException {
+ if (changeSet == null) {
+ throw new IllegalArgumentException("changeSet is null");
+ }
+ if (contentType == null) {
+ throw new IllegalArgumentException("contentType is null");
+ }
+
+ ChangeSetHandler handler = registry.get(contentType);
+ if (handler == null) {
+ throw new UnsupportedContentTypeException(contentType);
+ }
+
+ handler.applyChanges(changeSet);
+ }
+
+ public void register(ChangeSetHandler handler) {
+ registry.put(handler.getContentType(), handler);
+ }
+
+ public void include(InputStream stream) throws DeploymentException {
+ try {
+ XMLStreamReader reader = xmlFactory.createXMLStreamReader(stream);
+ while (reader.next() != XMLStreamConstants.START_ELEMENT) {
+ }
+
+ ScopeContainer<URI> scopeContainer = scopeRegistry.getScopeContainer(Scope.COMPOSITE);
+ URI groupId = domain.getUri();
+ // FIXME this needs to be done properly
+ ClassLoader cl = getClass().getClassLoader();
+ DeploymentContext deploymentContext =
+ new RootDeploymentContext(cl, null, groupId, xmlFactory, scopeContainer, false);
+
+ CompositeComponentType<?, ?, ?> type =
+ (CompositeComponentType<?, ?, ?>) loaderRegistry.load(null, reader, deploymentContext);
+ try {
+ autowireResolver.resolve(type);
+ } catch (ResolutionException e) {
+ throw new DeploymentException(e);
+ }
+ Map<URI, GeneratorContext> contexts = new HashMap<URI, GeneratorContext>();
+ // TODO create physical resource definitions
+ // create physical component definitions
+ for (ComponentDefinition<?> child : type.getDeclaredComponents().values()) {
+ try {
+ generate(child, contexts);
+ } catch (GenerationException e) {
+ throw new DeploymentException(e);
+ }
+ }
+ // create physical wire definitions
+ for (ComponentDefinition<?> child : type.getDeclaredComponents().values()) {
+ URI id = child.getRuntimeId();
+ GeneratorContext context = contexts.get(id);
+ if (context == null) {
+ PhysicalChangeSet changeSet = new PhysicalChangeSet();
+ context = new DefaultGeneratorContext(changeSet);
+ contexts.put(id, context);
+ }
+ try {
+ // TODO support composite recursion
+ for (Map.Entry<String, ReferenceTarget> entry : child.getReferenceTargets().entrySet()) {
+ List<URI> targets = entry.getValue().getTargets();
+ for (URI uri : targets) {
+ Implementation implementation = child.getImplementation();
+ ComponentType<?, ?, ?> componentType = implementation.getComponentType();
+ ReferenceDefinition referenceDefinition = componentType.getReferences().get(entry.getKey());
+ // TODO resolve target
+ ModelObject target = resolveTarget(uri, type);
+ if (target instanceof ReferenceDefinition) {
+ ReferenceDefinition targetReference = (ReferenceDefinition) target;
+ // TODO this should be extensible and moved out
+ BindingDefinition binding = targetReference.getBindings().get(0);
+ generatorRegistry.generateWire(child, referenceDefinition, binding, context);
+
+ } else if (target instanceof ComponentDefinition) {
+ ComponentDefinition<?> targetComponent = (ComponentDefinition) target;
+ String serviceName = uri.getFragment();
+ Implementation<?> targetImplementation = targetComponent.getImplementation();
+ ComponentType<?, ?, ?> targetType = targetImplementation.getComponentType();
+ ServiceDefinition serviceDefinition = null;
+ if (serviceName != null) {
+ serviceDefinition = targetType.getServices().get(serviceName);
+ } else if (targetType.getServices().size() == 1) {
+ // default service
+ serviceDefinition = targetType.getServices().values().iterator().next();
+ }
+ assert serviceDefinition != null;
+ generatorRegistry.generateWire(child,
+ referenceDefinition,
+ serviceDefinition,
+ targetComponent, context);
+ } else {
+ throw new AssertionError();
+ }
+ }
+ }
+ } catch (GenerationException e) {
+ throw new DeploymentException(e);
+ }
+
+
+ }
+ for (Map.Entry<URI, GeneratorContext> entry : contexts.entrySet()) {
+ marshallAndSend(entry.getKey(), entry.getValue());
+ }
+ } catch (XMLStreamException e) {
+ throw new DocumentParseException(e);
+ } catch (LoaderException e) {
+ throw new DocumentParseException(e);
+ } catch (MarshalException e) {
+ throw new DocumentParseException(e);
+ } catch (DiscoveryException e) {
+ throw new DocumentParseException(e);
+ }
+ }
+
+ /*
+ * Marshalls and sends the PCS.
+ */
+ private void marshallAndSend(URI id, GeneratorContext context)
+ throws XMLStreamException, MarshalException, DiscoveryException {
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ PhysicalChangeSet pcs = context.getPhysicalChangeSet();
+
+ XMLStreamWriter pcsWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(out);
+ marshallerRegistry.marshall(pcs, pcsWriter);
+
+ ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+ XMLStreamReader pcsReader = XMLInputFactory.newInstance().createXMLStreamReader(in);
+ discoveryService.sendMessage(id.toASCIIString(), pcsReader);
+
+ }
+
+ private void generate(ComponentDefinition<?> component, Map<URI, GeneratorContext> contexts)
+ throws GenerationException {
+ URI id = component.getRuntimeId();
+ GeneratorContext context = contexts.get(id);
+ if (context == null) {
+ PhysicalChangeSet changeSet = new PhysicalChangeSet();
+ context = new DefaultGeneratorContext(changeSet);
+ contexts.put(id, context);
+ }
+ // TODO support composite recursion
+ generatorRegistry.generate(component, context);
+
+ }
+
+ private ComponentDefinition<CompositeImplementation> createDomain() {
+ CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ CompositeImplementation impl = new CompositeImplementation();
+ impl.setComponentType(type);
+ return new ComponentDefinition<CompositeImplementation>(DOMAIN_URI, impl);
+ }
+
+ private ModelObject resolveTarget(URI uri, CompositeComponentType<?, ?, ?> type) {
+ // TODO only resolves one level deep
+// StringTokenizer tokenizer = new StringTokenizer(uri.getPath(), "/");
+// while (tokenizer.hasMoreTokens()) {
+// }
+
+ String key = DOMAIN_URI.relativize(uri).toString();
+ ComponentDefinition<?> targetComponent = type.getDeclaredComponents().get(key);
+ if (targetComponent != null) {
+ return targetComponent;
+ }
+ ReferenceDefinition targetReference = type.getDeclaredReferences().get(key);
+ if (targetReference != null) {
+ return targetReference;
+ }
+ throw new AssertionError();
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContentTypeDescriberImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContentTypeDescriberImpl.java
new file mode 100644
index 0000000000..bae5c1d450
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContentTypeDescriberImpl.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.core.services.deployment;
+
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Service;
+
+import org.apache.tuscany.spi.deployer.ContentTypeDescriber;
+
+import org.apache.tuscany.core.util.FileHelper;
+
+/**
+ * Implementation of the content describer
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+@Service(ContentTypeDescriber.class)
+public class ContentTypeDescriberImpl implements ContentTypeDescriber {
+ private final Map<String, String> contentTypeRegistry = new HashMap<String, String>();
+
+ public ContentTypeDescriberImpl() {
+ super();
+ init();
+ }
+
+ /**
+ * Initialize contentType registry with know types based on known file extensions
+ */
+ private void init() {
+ contentTypeRegistry.put("SCDL", "application/v.tuscany.scdl");
+ contentTypeRegistry.put("COMPOSITE", "application/v.tuscany.scdl");
+ contentTypeRegistry.put("WSDL", "application/v.tuscany.wsdl");
+ contentTypeRegistry.put("JAR", "application/x-compressed");
+ }
+
+ 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 url
+ * @param defaultContentType
+ * @return
+ */
+ public String getContentType(URL resourceURL, String defaultContentType) {
+ URLConnection connection = null;
+ String contentType = defaultContentType;
+
+ 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
+ // return defaultContentType if provided
+ contentType = defaultContentType;
+ }
+ } catch (IOException io) {
+ // could not access artifact, just ignore and we will return
+ // null contentType
+ }
+ }
+ return contentType == null ? defaultContentType : contentType;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionDirectoryWatcher.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionDirectoryWatcher.java
new file mode 100644
index 0000000000..cbbd5f8623
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionDirectoryWatcher.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.core.services.deployment;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.host.deployment.ContributionService;
+import org.apache.tuscany.host.deployment.DeploymentException;
+
+@EagerInit
+public class ContributionDirectoryWatcher {
+ private final String path;
+
+ private final ContributionService contributionService;
+
+ public ContributionDirectoryWatcher(@Reference ContributionService contributionService,
+ @Property(name = "path") String path) {
+ this.path = path;
+ this.contributionService = contributionService;
+ }
+
+ @Init
+ public void init() {
+ File extensionDir = new File(path);
+ if (!extensionDir.isDirectory()) {
+ // we don't have an extension directory, there's nothing to do
+ return;
+ }
+
+ File[] files = extensionDir.listFiles();
+ for (File file : files) {
+ try {
+ if (file.isDirectory()) {
+ this.contributionService.contribute(file.toURL(), false);
+ } else {
+ this.contributionService.contribute(file.toURL(), true);
+ }
+ } catch (DeploymentException de) {
+ // FIXME handle this
+ de.printStackTrace();
+ } catch (IOException ioe) {
+ // FIXME handle this
+ ioe.printStackTrace();
+ }
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionLoader.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionLoader.java
new file mode 100644
index 0000000000..dc97291348
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionLoader.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.core.services.deployment;
+
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import static org.osoa.sca.Constants.SCA_NS;
+
+import java.net.URI;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.InvalidValueException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.Contribution;
+import org.apache.tuscany.spi.model.ContributionImport;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * Loader that handles &lt;include&gt; elements.
+ *
+ * @version $Rev: 515261 $ $Date: 2007-03-06 11:22:46 -0800 (Tue, 06 Mar 2007) $
+ */
+public class ContributionLoader extends LoaderExtension<Contribution> {
+ private static final QName CONTRIBUTION = new QName(SCA_NS, "contribution");
+ private static final QName DEPLOYABLE = new QName(SCA_NS, "deployable");
+ private static final QName IMPORT = new QName(SCA_NS, "import");
+ private static final QName EXPORT = new QName(SCA_NS, "export");
+
+ @Constructor({"registry"})
+ public ContributionLoader(@Reference LoaderRegistry registry) {
+ super(registry);
+ }
+
+ public QName getXMLType() {
+ return CONTRIBUTION;
+ }
+
+ public Contribution load(ModelObject object,
+ XMLStreamReader reader,
+ DeploymentContext deploymentContext) throws XMLStreamException, LoaderException {
+
+ Contribution contribution = new Contribution();
+ while (true) {
+ int event = reader.next();
+ switch (event) {
+ case START_ELEMENT:
+ QName element = reader.getName();
+ 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);
+ String ns = reader.getNamespaceContext().getNamespaceURI(prefix);
+ if (ns == null) {
+ throw new InvalidValueException("Invalid prefix: " + prefix);
+ }
+ compositeName = new QName(ns, localPart, prefix);
+ } else {
+ String prefix = "";
+ String ns = reader.getNamespaceURI();
+ String localPart = name;
+ compositeName = new QName(ns, localPart, prefix);
+ }
+ contribution.getDeployables().add(compositeName);
+ } 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 = new ContributionImport();
+ if (location != null) {
+ contributionImport.setLocation(URI.create(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");
+ }
+ contribution.getExports().add(ns);
+ }
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ if (CONTRIBUTION.equals(reader.getName())) {
+ return contribution;
+ }
+ break;
+
+ }
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionProcessorRegistryImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionProcessorRegistryImpl.java
new file mode 100644
index 0000000000..5866789e7e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionProcessorRegistryImpl.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.core.services.deployment;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Service;
+
+import org.apache.tuscany.spi.deployer.ContentTypeDescriber;
+import org.apache.tuscany.spi.deployer.ContributionProcessor;
+import org.apache.tuscany.spi.deployer.ContributionProcessorRegistry;
+import org.apache.tuscany.spi.model.Contribution;
+
+import org.apache.tuscany.host.deployment.DeploymentException;
+import org.apache.tuscany.host.deployment.UnsupportedContentTypeException;
+
+/**
+ * Default implementation of ContributionProcessorRegistry
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+@Service(ContributionProcessorRegistry.class)
+public class ContributionProcessorRegistryImpl implements ContributionProcessorRegistry {
+ /**
+ * Processor registry
+ */
+ private Map<String, ContributionProcessor> registry = new HashMap<String, ContributionProcessor>();
+ /**
+ * Helper method to describe contentType for each artifact
+ */
+ private ContentTypeDescriber contentTypeDescriber;
+
+ public ContributionProcessorRegistryImpl(@Reference ContentTypeDescriber contentTypeDescriber) {
+ if (contentTypeDescriber == null) {
+ this.contentTypeDescriber = new ContentTypeDescriberImpl();
+ } else {
+ this.contentTypeDescriber = contentTypeDescriber;
+ }
+ }
+
+ public void register(String contentType, ContributionProcessor processor) {
+ registry.put(contentType, processor);
+ }
+
+ public void unregister(String contentType) {
+ registry.remove(contentType);
+ }
+
+ public void processContent(Contribution contribution, URI source, InputStream inputStream)
+ throws DeploymentException, IOException {
+
+ URL locationURL = contribution.getArtifact(source).getLocation();
+ String contentType = this.contentTypeDescriber.getContentType(locationURL, null);
+ if (contentType == null) {
+ throw new UnsupportedContentTypeException("Invalid contentType: null");
+ }
+
+ ContributionProcessor processor = this.registry.get(contentType);
+ if (processor == null) {
+ throw new UnsupportedContentTypeException(contentType, locationURL.getPath());
+ }
+
+ processor.processContent(contribution, source, inputStream);
+
+ }
+
+ public void processModel(Contribution contribution, URI source, Object modelObject) throws DeploymentException,
+ IOException {
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryImpl.java
new file mode 100644
index 0000000000..b56c7fe263
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryImpl.java
@@ -0,0 +1,275 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.services.deployment;
+
+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.core.util.FileHelper;
+import org.apache.tuscany.core.util.IOHelper;
+import org.apache.tuscany.spi.deployer.ContributionRepository;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Property;
+
+/**
+ * The default implementation of ContributionRepository
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+public class ContributionRepositoryImpl implements ContributionRepository {
+ private static final String NS = "http://tuscany.apache.org/xmlns/1.0-SNAPSHOT";
+ private final File rootFile;
+ private Map<URI, String> contributionMap = new HashMap<URI, String>();
+
+ private URI domain;
+ private XMLInputFactory factory;
+
+ /**
+ * Constructor with repository root
+ *
+ * @param repository
+ */
+ @Constructor
+ public ContributionRepositoryImpl(@Property(name = "repository")
+ final String repository) throws IOException {
+ String root = repository;
+ if (repository == null) {
+ root = AccessController.doPrivileged(new PrivilegedAction<String>() {
+ public String run() {
+ // Default to <user.home>/.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(URI contribution) {
+ // FIXME: Map the contribution URI to a file?
+ return new File(rootFile, "contributions" + File.separator + contribution.getPath());
+ }
+
+ /**
+ * 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(URI contribution, InputStream contributionStream) throws IOException {
+ // where the file should be stored in the repository
+ File location = mapToFile(contribution);
+ 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(URI contribution, URL sourceURL) throws IOException {
+ // where the file should be stored in the repository
+ File location = mapToFile(contribution);
+ File source = FileHelper.toFile(sourceURL);
+ if (source == null || source.isFile()) {
+ InputStream is = sourceURL.openStream();
+ try {
+ return store(contribution, 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(URI 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(URI 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<URI> list() {
+ return new ArrayList<URI>(contributionMap.keySet());
+ }
+
+ @Init
+ 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.create(uri), location);
+ }
+ break;
+ default:
+ break;
+ }
+ reader.next();
+ }
+ } catch (Exception e) {
+ // Ignore
+ } finally {
+ IOHelper.closeQuietly(is);
+ }
+ }
+
+ private void saveMap() {
+ File domainFile = new File(rootFile, "sca-domain.xml");
+ FileOutputStream os = null;
+ try {
+ os = new FileOutputStream(domainFile);
+ PrintWriter writer = new PrintWriter(new OutputStreamWriter(os, "UTF-8"));
+ writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+ writer.println("<domain uri=\"" + getDomain() + "\" xmlns=\"" + NS + "\">");
+ for (Map.Entry<URI, String> e : contributionMap.entrySet()) {
+ writer.println(" <contribution uri=\"" + e.getKey() + "\" location=\"" + e.getValue() + "\"/>");
+ }
+ writer.println("</domain>");
+ writer.flush();
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e);
+ } finally {
+ IOHelper.closeQuietly(os);
+ }
+ }
+
+ @Destroy
+ public void destroy() {
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionServiceImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionServiceImpl.java
new file mode 100644
index 0000000000..bf19683a7c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/ContributionServiceImpl.java
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.services.deployment;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.ContributionProcessorRegistry;
+import org.apache.tuscany.spi.deployer.ContributionRepository;
+import org.apache.tuscany.spi.model.Contribution;
+
+import org.apache.tuscany.core.util.IOHelper;
+import org.apache.tuscany.host.deployment.ContributionService;
+import org.apache.tuscany.host.deployment.DeploymentException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ContributionServiceImpl implements ContributionService {
+ /**
+ * Repository where contributions are stored. Usually set by injection.
+ */
+ protected ContributionRepository contributionRepository;
+ /**
+ * Registry of available processors. Usually set by injection.
+ */
+ protected ContributionProcessorRegistry processorRegistry;
+ /**
+ * Contribution registry This is a registry of processed Contributios index by URI
+ */
+ protected Map<URI, Contribution> contributionRegistry = new HashMap<URI, Contribution>();
+
+ public ContributionServiceImpl(@Reference ContributionRepository repository,
+ @Reference ContributionProcessorRegistry processorRegistry) {
+ super();
+ this.contributionRepository = repository;
+ this.processorRegistry = processorRegistry;
+ }
+
+ public URI contribute(URL contribution, boolean storeInRepository) throws DeploymentException, IOException {
+ if (contribution == null) {
+ throw new IllegalArgumentException("contribution is null");
+ }
+
+ URI source;
+ try {
+ source = contribution.toURI();
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException("contribution cannot be converted to a URI", e);
+ }
+
+ InputStream is = contribution.openConnection().getInputStream();
+ try {
+ return contribute(source, is, storeInRepository);
+ } finally {
+ IOHelper.closeQuietly(is);
+ }
+ }
+
+ public URI contribute(URI source, InputStream contributionStream, boolean storeInRepository)
+ throws DeploymentException, IOException {
+ if (source == null) {
+ throw new IllegalArgumentException("source URI for contribution is null");
+ }
+
+ if (contributionStream == null) {
+ throw new IllegalArgumentException("Invalid contribution stream : null");
+ }
+
+ // store the contribution in the contribution repository
+ URI contributionURI = URI.create("sca://contribution/" + UUID.randomUUID());
+ URL locationURL;
+ if (storeInRepository) {
+ locationURL = this.contributionRepository.store(source, contributionStream);
+ } else {
+ locationURL = source.toURL();
+ }
+
+
+ Contribution contribution = null;
+ contribution = new Contribution(contributionURI);
+ contribution.setLocation(locationURL);
+
+ //process the contribution
+ this.processorRegistry.processContent(contribution, contributionURI, locationURL.openStream());
+
+ //store the contribution on the registry
+ this.contributionRegistry.put(contribution.getUri(), contribution);
+
+ return contribution.getUri();
+ }
+
+ public Contribution getContribution(URI id) {
+ return this.contributionRegistry.get(id);
+ }
+
+ public void remove(URI contribution) throws DeploymentException {
+ //remove from repository
+ this.contributionRegistry.remove(contribution);
+ //remove from registry
+ this.contributionRegistry.remove(contribution);
+ }
+
+ public <T> T resolve(URI contribution, Class<T> definitionType, String namespace, String name) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public URL resolve(URI contribution, String namespace, URI uri, URI baseURI) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/DocumentParseException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/DocumentParseException.java
new file mode 100644
index 0000000000..38f02bc642
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/DocumentParseException.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.core.services.deployment;
+
+import org.apache.tuscany.host.deployment.DeploymentException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DocumentParseException extends DeploymentException {
+
+ public DocumentParseException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/InvalidContributionMetadataException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/InvalidContributionMetadataException.java
new file mode 100644
index 0000000000..110633e685
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/InvalidContributionMetadataException.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.core.services.deployment;
+
+import org.apache.tuscany.host.deployment.DeploymentException;
+
+/**
+ * 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 DeploymentException {
+
+ protected InvalidContributionMetadataException() {
+ }
+
+ protected InvalidContributionMetadataException(String message) {
+ super(message);
+ }
+
+ protected InvalidContributionMetadataException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ protected InvalidContributionMetadataException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ protected InvalidContributionMetadataException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+
+ protected InvalidContributionMetadataException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/InvalidDocumentException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/InvalidDocumentException.java
new file mode 100644
index 0000000000..f509929f29
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/InvalidDocumentException.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.core.services.deployment;
+
+import org.apache.tuscany.host.deployment.DeploymentException;
+
+/**
+ * Exception that indicates that the supplied XML Document invalid.
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidDocumentException extends DeploymentException {
+ protected InvalidDocumentException(String rootElement) {
+ super(rootElement);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/XMLChangeSetHandler.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/XMLChangeSetHandler.java
new file mode 100644
index 0000000000..b3b38cb438
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/XMLChangeSetHandler.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.core.services.deployment;
+
+import java.io.IOException;
+import java.io.InputStream;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import static javax.xml.stream.XMLStreamConstants.END_DOCUMENT;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.builder.Builder;
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.deployer.ChangeSetHandler;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.Loader;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+
+import org.apache.tuscany.core.deployer.RootDeploymentContext;
+import org.apache.tuscany.host.deployment.ContentTypes;
+import org.apache.tuscany.host.deployment.DeploymentException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class XMLChangeSetHandler implements ChangeSetHandler {
+ private static final String NS = "http://tuscany.apache.org/xmlns/1.0-SNAPSHOT";
+ private static final QName CHANGESET = new QName(NS, "changeSet");
+ private static final QName CREATECOMPONENT = new QName(NS, "createComponent");
+
+ private final Builder builder;
+ private final Loader loader;
+ private final XMLInputFactory xmlFactory;
+
+ public XMLChangeSetHandler(Loader loader, Builder builder) {
+ this.loader = loader;
+ this.builder = builder;
+ xmlFactory = XMLInputFactory.newInstance("javax.xml.stream.XMLInputFactory", getClass().getClassLoader());
+ }
+
+ public String getContentType() {
+ return ContentTypes.CHANGESET_XML;
+ }
+
+ public void applyChanges(InputStream changeSet) throws DeploymentException, IOException {
+ try {
+ XMLStreamReader xmlReader = xmlFactory.createXMLStreamReader(changeSet);
+ while (true) {
+ switch (xmlReader.next()) {
+ case START_ELEMENT:
+ if (!CHANGESET.equals(xmlReader.getName())) {
+ throw new InvalidDocumentException(xmlReader.getName().toString());
+ }
+ processChanges(xmlReader);
+ break;
+ case END_DOCUMENT:
+ return;
+ }
+ }
+ } catch (XMLStreamException e) {
+ throw (IOException) new IOException(e.getMessage()).initCause(e);
+ }
+ }
+
+ public void processChanges(XMLStreamReader xmlReader) throws XMLStreamException, DeploymentException {
+ while (true) {
+ switch (xmlReader.next()) {
+ case START_ELEMENT:
+ if (CREATECOMPONENT.equals(xmlReader.getName())) {
+ createComponent(xmlReader);
+ } else {
+ // reject unrecognized commands
+ throw new InvalidDocumentException(xmlReader.getName().toString());
+ }
+ break;
+ case END_ELEMENT:
+ return;
+ }
+ }
+ }
+
+ public void createComponent(XMLStreamReader xmlReader) throws XMLStreamException {
+ DeploymentContext deploymentContext = new RootDeploymentContext(null, null, null, xmlFactory, null, false);
+ try {
+ ComponentDefinition<?> componentDefinition =
+ (ComponentDefinition<?>) loader.load(null, xmlReader, deploymentContext);
+ builder.build(componentDefinition, deploymentContext);
+ } catch (LoaderException e) {
+ // FIXME throw something appropriate
+ throw new AssertionError("FIXME");
+ } catch (BuilderException e) {
+ // FIXME throw something appropriate
+ throw new AssertionError("FIXME");
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/CompositeContributionProcessor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/CompositeContributionProcessor.java
new file mode 100644
index 0000000000..0e147e3a38
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/CompositeContributionProcessor.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.services.deployment.contribution;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+
+import javax.xml.stream.XMLInputFactory;
+
+import org.apache.tuscany.core.deployer.RootDeploymentContext;
+import org.apache.tuscany.host.deployment.DeploymentException;
+import org.apache.tuscany.spi.deployer.CompositeClassLoader;
+import org.apache.tuscany.spi.deployer.ContentType;
+import org.apache.tuscany.spi.deployer.ContributionProcessor;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ContributionProcessorExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+import org.apache.tuscany.spi.model.Contribution;
+import org.osoa.sca.annotations.Reference;
+
+public class CompositeContributionProcessor extends ContributionProcessorExtension implements ContributionProcessor {
+ /**
+ * Content-type that this processor can handle
+ */
+ public static final String CONTENT_TYPE = ContentType.COMPOSITE;
+
+ protected XMLInputFactory xmlFactory;
+ private final LoaderRegistry registry;
+
+
+ public CompositeContributionProcessor(@Reference LoaderRegistry registry) {
+ super();
+ this.registry = registry;
+ this.xmlFactory = XMLInputFactory.newInstance("javax.xml.stream.XMLInputFactory", getClass().getClassLoader());
+ }
+
+ @Override
+ public String getContentType() {
+ return CONTENT_TYPE;
+ }
+
+
+ public void processContent(Contribution contribution, URI artifactURI, InputStream inputStream)
+ throws DeploymentException, IOException {
+ if (artifactURI == null) {
+ throw new IllegalArgumentException("Invalid null source uri.");
+ }
+
+ if (inputStream == null) {
+ throw new IllegalArgumentException("Invalid null source inputstream.");
+ }
+
+ try {
+ URI contributionId = contribution.getUri();
+ URL scdlLocation = contribution.getArtifact(artifactURI).getLocation();
+ CompositeClassLoader cl = new CompositeClassLoader(null, getClass().getClassLoader());
+ cl.addURL(contribution.getLocation());
+
+ DeploymentContext deploymentContext =
+ new RootDeploymentContext(cl, scdlLocation, contributionId, this.xmlFactory, null,
+ false);
+
+ CompositeComponentType componentType =
+ this.registry.load(null, scdlLocation, CompositeComponentType.class, deploymentContext);
+
+ CompositeImplementation implementation = new CompositeImplementation();
+ implementation.setComponentType(componentType);
+ ComponentDefinition<CompositeImplementation> componentDefinition =
+ new ComponentDefinition<CompositeImplementation>(implementation);
+
+ //FIXME this changed in trunk....
+ //componentDefinition.setName(componentType.getName());
+
+ contribution.getArtifact(artifactURI).addModelObject(CompositeComponentType.class, null, componentDefinition);
+
+ } catch (LoaderException le) {
+ throw new InvalidComponentDefinitionlException(contribution.getArtifact(artifactURI).getLocation()
+ .toExternalForm(), le);
+ }
+ }
+
+ public void processModel(Contribution contribution, URI source, Object modelObject) throws DeploymentException,
+ IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+} \ No newline at end of file
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessor.java
new file mode 100644
index 0000000000..ef2115fb0a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessor.java
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.services.deployment.contribution;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.core.services.deployment.ContentTypeDescriberImpl;
+import org.apache.tuscany.core.util.FileHelper;
+import org.apache.tuscany.core.util.IOHelper;
+import org.apache.tuscany.host.deployment.DeploymentException;
+import org.apache.tuscany.spi.deployer.ContentType;
+import org.apache.tuscany.spi.deployer.ContentTypeDescriber;
+import org.apache.tuscany.spi.deployer.ContributionProcessor;
+import org.apache.tuscany.spi.extension.ContributionProcessorExtension;
+import org.apache.tuscany.spi.model.Contribution;
+import org.apache.tuscany.spi.model.DeployedArtifact;
+
+public class FolderContributionProcessor extends ContributionProcessorExtension implements ContributionProcessor {
+ /**
+ * Content-type that this processor can handle
+ */
+ public static final String CONTENT_TYPE = ContentType.FOLDER;
+
+ @Override
+ public String getContentType() {
+ return CONTENT_TYPE;
+ }
+
+ /**
+ * Recursively traverse a root directory
+ *
+ * @param fileList
+ * @param root
+ * @throws IOException
+ */
+ private void traverse(List<URL> fileList, File root) throws IOException {
+ if (root.isFile()) {
+ fileList.add(root.toURL());
+ } else if (root.isDirectory()) {
+ // FIXME: Maybe we should externalize it as a property
+ // Regular expression to exclude .xxx files
+ File[] files = root.listFiles(FileHelper.getFileFilter("[^\u002e].*", true));
+ for (int i = 0; i < files.length; i++) {
+ traverse(fileList, files[i]);
+ }
+ }
+ }
+
+ /**
+ * Get a list of files from the directory
+ *
+ * @return
+ * @throws IOException
+ */
+ protected List<URL> getArtifacts(URL rootURL) throws DeploymentException,
+ IOException {
+ List<URL> artifacts = new ArrayList<URL>();
+
+ // Assume the root is a jar file
+ File rootFolder;
+
+ try {
+ rootFolder = new File(rootURL.toURI());
+ if (rootFolder.isDirectory()) {
+ this.traverse(artifacts, rootFolder);
+ }
+
+ } catch (URISyntaxException e) {
+ throw new InvalidFolderContributionURIException(rootURL.toExternalForm(), e);
+ }
+
+ return artifacts;
+ }
+
+ public void processContent(Contribution contribution, URI source, InputStream inputStream)
+ throws DeploymentException, IOException {
+ if (contribution == null) {
+ throw new IllegalArgumentException("Invalid null contribution.");
+ }
+
+ if (source == null) {
+ throw new IllegalArgumentException("Invalid null source uri.");
+ }
+
+ URL contributionURL = contribution.getArtifact(source).getLocation();
+
+ for (URL artifactURL : getArtifacts(contributionURL)) {
+ String artifactPath = artifactURL.toExternalForm().substring(contributionURL.toExternalForm().length());
+ URI artifactURI = contribution.getUri().resolve(artifactPath);
+ DeployedArtifact artifact = new DeployedArtifact(artifactURI);
+ artifact.setLocation(artifactURL);
+ contribution.addArtifact(artifact);
+
+ ContentTypeDescriber contentTypeDescriber = new ContentTypeDescriberImpl();
+ String contentType = contentTypeDescriber.getContentType(artifactURL, null);
+
+ // just process scdl and contribution metadata for now
+ if (ContentType.COMPOSITE.equals(contentType)) {
+ InputStream is = artifactURL.openStream();
+ try {
+ this.registry.processContent(contribution, artifactURI, is);
+ } finally {
+ IOHelper.closeQuietly(is);
+ is = null;
+ }
+ }
+ }
+ }
+
+ public void processModel(Contribution contribution, URI source, Object modelObject) throws DeploymentException,
+ IOException {
+ // NOOP
+ }
+
+} \ No newline at end of file
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/InvalidComponentDefinitionlException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/InvalidComponentDefinitionlException.java
new file mode 100644
index 0000000000..f0b47ccf7b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/InvalidComponentDefinitionlException.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.core.services.deployment.contribution;
+
+import org.apache.tuscany.host.deployment.DeploymentException;
+
+/**
+ * Exception that indicates that the supplied XML Document invalid.
+ *
+ */
+public class InvalidComponentDefinitionlException extends DeploymentException {
+
+ protected InvalidComponentDefinitionlException(String componentDefinitionLocatoin) {
+ super(componentDefinitionLocatoin);
+ }
+
+ protected InvalidComponentDefinitionlException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/InvalidFolderContributionURIException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/InvalidFolderContributionURIException.java
new file mode 100644
index 0000000000..547608e64d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/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.core.services.deployment.contribution;
+
+import org.apache.tuscany.host.deployment.DeploymentException;
+
+/**
+ * Exception that indicates that the supplied XML Document invalid.
+ *
+ */
+public class InvalidFolderContributionURIException extends DeploymentException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1564255850052593282L;
+
+ protected InvalidFolderContributionURIException(String componentDefinitionLocatoin) {
+ super(componentDefinitionLocatoin);
+ }
+
+ protected InvalidFolderContributionURIException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/InvalidPojoComponentDefinitionlException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/InvalidPojoComponentDefinitionlException.java
new file mode 100644
index 0000000000..e2d2f12cb5
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/InvalidPojoComponentDefinitionlException.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.core.services.deployment.contribution;
+
+import org.apache.tuscany.host.deployment.DeploymentException;
+
+/**
+ * Exception that indicates that the supplied XML Document invalid.
+ *
+ */
+public class InvalidPojoComponentDefinitionlException extends DeploymentException {
+
+ protected InvalidPojoComponentDefinitionlException(String componentDefinitionLocatoin) {
+ super(componentDefinitionLocatoin);
+ }
+
+ protected InvalidPojoComponentDefinitionlException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessor.java
new file mode 100644
index 0000000000..819c0ce9e6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessor.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.core.services.deployment.contribution;
+
+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.core.services.deployment.ContentTypeDescriberImpl;
+import org.apache.tuscany.core.util.IOHelper;
+import org.apache.tuscany.host.deployment.DeploymentException;
+import org.apache.tuscany.spi.deployer.ContentType;
+import org.apache.tuscany.spi.deployer.ContentTypeDescriber;
+import org.apache.tuscany.spi.deployer.ContributionProcessor;
+import org.apache.tuscany.spi.extension.ContributionProcessorExtension;
+import org.apache.tuscany.spi.model.Contribution;
+import org.apache.tuscany.spi.model.DeployedArtifact;
+
+public class JarContributionProcessor extends ContributionProcessorExtension implements ContributionProcessor {
+ /**
+ * Content-type that this processor can handle
+ */
+ public static final String CONTENT_TYPE = ContentType.JAR;
+
+ @Override
+ public String getContentType() {
+ return CONTENT_TYPE;
+ }
+
+ /**
+ * Get a list of resources inside the jar
+ *
+ * @return
+ * @throws IOException
+ */
+ protected List<URL> getArtifacts(URL rootURL, InputStream sourceInputStream) throws IOException {
+ List<URL> artifacts = new ArrayList<URL>();
+
+ // Assume the root is a jar file
+ JarInputStream jar = new JarInputStream(sourceInputStream);
+ try {
+ while (true) {
+ JarEntry entry = jar.getNextJarEntry();
+ if (entry == null) {
+ // EOF
+ break;
+ }
+ if (entry.isDirectory()) {
+ continue;
+ }
+
+ // FIXME: Maybe we should externalize the filter as a property
+ if (!entry.getName().startsWith(".")) {
+ artifacts.add(new URL(rootURL, entry.getName()));
+ }
+ }
+ } finally {
+ jar.close();
+ }
+ return artifacts;
+ }
+
+ private URL forceJarURL(URL sourceURL) throws MalformedURLException {
+ if (sourceURL.toString().startsWith("jar:")) {
+ return sourceURL;
+ } else {
+ return new URL("jar:" + sourceURL.toExternalForm() + "!/");
+ }
+
+ }
+
+ public void processContent(Contribution contribution, URI source, InputStream inputStream)
+ throws DeploymentException, IOException {
+ if (contribution == null) {
+ throw new IllegalArgumentException("Invalid null contribution.");
+ }
+
+ if (source == null) {
+ throw new IllegalArgumentException("Invalid null source uri.");
+ }
+
+ if (inputStream == null) {
+ throw new IllegalArgumentException("Invalid null source inputstream.");
+ }
+
+ URL sourceURL = contribution.getArtifact(source).getLocation();
+
+ sourceURL = forceJarURL(sourceURL);
+
+ for (URL artifactURL : getArtifacts(sourceURL, inputStream)) {
+ URI artifactURI;
+
+ String artifactPath = artifactURL.toExternalForm().substring(sourceURL.toExternalForm().length());
+ artifactURI = contribution.getUri().resolve(artifactPath);
+ DeployedArtifact artifact = new DeployedArtifact(artifactURI);
+ artifact.setLocation(artifactURL);
+ contribution.addArtifact(artifact);
+
+
+ ContentTypeDescriber contentTypeDescriber = new ContentTypeDescriberImpl();
+ String contentType = contentTypeDescriber.getContentType(artifactURL, null);
+
+ // just process scdl for now
+ if (ContentType.COMPOSITE.equals(contentType)) {
+ InputStream is = IOHelper.getInputStream(artifactURL);
+ try {
+ this.registry.processContent(contribution, artifactURI, is);
+ } finally {
+ IOHelper.closeQuietly(is);
+ is = null;
+ }
+ }
+ }
+
+ }
+
+ public void processModel(Contribution contribution, URI source, Object modelObject) throws DeploymentException,
+ IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessor.java
new file mode 100644
index 0000000000..d0d4e15934
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessor.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.core.services.deployment.contribution;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+
+import org.apache.tuscany.host.deployment.DeploymentException;
+import org.apache.tuscany.spi.deployer.CompositeClassLoader;
+import org.apache.tuscany.spi.deployer.ContentType;
+import org.apache.tuscany.spi.deployer.ContributionProcessor;
+import org.apache.tuscany.spi.extension.ContributionProcessorExtension;
+import org.apache.tuscany.spi.implementation.java.IntrospectionRegistry;
+import org.apache.tuscany.spi.implementation.java.Introspector;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+import org.apache.tuscany.spi.model.Contribution;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+
+public class JavaContributionProcessor extends ContributionProcessorExtension implements ContributionProcessor {
+ /**
+ * Content-type that this processor can handle
+ */
+ public static final String CONTENT_TYPE = ContentType.JAVA;
+ /**
+ * Pojo introspector
+ */
+ private Introspector introspector;
+
+ @Constructor
+ public JavaContributionProcessor(@Reference IntrospectionRegistry introspector) {
+ //this.introspector = introspector;
+ }
+
+ @Override
+ public String getContentType() {
+ return CONTENT_TYPE;
+ }
+
+ private String getClazzName(URL clazzURL) {
+ String clazzName;
+
+ clazzName = clazzURL.toExternalForm().substring(clazzURL.toExternalForm().lastIndexOf("!/") + 2,
+ clazzURL.toExternalForm().length() - ".class".length());
+ clazzName = clazzName.replace("/", ".");
+
+ return clazzName;
+ }
+
+
+ public void processContent(Contribution contribution, URI artifactURI, InputStream inputStream)
+ throws DeploymentException, IOException {
+ if (artifactURI == null) {
+ throw new IllegalArgumentException("Invalid null artifact uri.");
+ }
+
+ if (inputStream == null) {
+ throw new IllegalArgumentException("Invalid null source inputstream.");
+ }
+
+ // TODO Auto-generated method stub
+
+ try {
+ CompositeClassLoader cl = new CompositeClassLoader(null, getClass().getClassLoader());
+ cl.addURL(contribution.getLocation());
+
+ String clazzName = getClazzName(contribution.getArtifact(artifactURI).getLocation());
+ System.out.println(clazzName);
+
+ Class clazz = cl.loadClass(clazzName);
+
+ //PojoComponentType javaInfo = introspector.introspect(null, clazz, null, null);
+
+ //contribution.getArtifact(artifactURI).addModelObject(PojoComponentType.class, null, javaInfo);
+
+ } catch (ClassNotFoundException cnfe) {
+ throw new InvalidPojoComponentDefinitionlException(contribution.getArtifact(artifactURI).getLocation().toExternalForm(), cnfe);
+ //} catch (ProcessingException pe) {
+ // throw new InvalidPojoComponentDefinitionlException(contribution.getArtifact(artifactURI).getLocation().toExternalForm(), pe);
+ }
+ }
+
+ public void processModel(Contribution contribution, URI source, Object modelObject)
+ throws DeploymentException, IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/resolver/ComponentDefinitionArtifactResolver.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/resolver/ComponentDefinitionArtifactResolver.java
new file mode 100644
index 0000000000..cc5bc170e7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/deployment/resolver/ComponentDefinitionArtifactResolver.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.core.services.deployment.resolver;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.Map;
+
+import org.apache.tuscany.spi.deployer.ArtifactResolver;
+import org.apache.tuscany.spi.deployer.ArtifactResolverRegistry;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ArtifactResolverExtension;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.Contribution;
+import org.apache.tuscany.spi.model.DeployedArtifact;
+import org.osoa.sca.annotations.Reference;
+
+public class ComponentDefinitionArtifactResolver extends ArtifactResolverExtension implements ArtifactResolver {
+
+ public ComponentDefinitionArtifactResolver(@Reference
+ ArtifactResolverRegistry registry) {
+ super(registry);
+ }
+
+ @Override
+ public Class<?> getType() {
+ return ComponentDefinition.class;
+ }
+
+ public <ComponentDefinition> ComponentDefinition resolve(Contribution contribution,
+ Class<ComponentDefinition> modelClass,
+ String namespace,
+ String name,
+ Map attributes,
+ DeploymentContext context) {
+
+ // generate artifact uri based on it's name
+ URI artifactURI = contribution.getUri().resolve(name);
+ DeployedArtifact artifact = contribution.getArtifact(artifactURI);
+
+ ComponentDefinition componentDefinition =
+ (ComponentDefinition)artifact.getModelObject(CompositeComponentType.class, null);
+ return componentDefinition;
+ }
+
+ public URL resolve(Contribution contribution, String targetNamespace, String location, String baseURI) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/extension/AbstractExtensionDeployer.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/extension/AbstractExtensionDeployer.java
new file mode 100644
index 0000000000..37e599cc7b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/extension/AbstractExtensionDeployer.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.core.services.extension;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.Deployer;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AbstractExtensionDeployer {
+ protected Deployer deployer;
+ protected Component parent;
+
+ @Reference
+ public void setDeployer(Deployer deployer) {
+ this.deployer = deployer;
+ }
+
+ protected void deployExtension(File file) {
+ // extension name is file name less any extension
+ String name = file.getName();
+ int dot = name.lastIndexOf('.');
+ if (dot > 0) {
+ name = name.substring(0, dot);
+ }
+ URL url;
+ try {
+ url = file.toURI().toURL();
+ } catch (MalformedURLException e) {
+ // toURI should have encoded the URL
+ throw new AssertionError();
+ }
+
+ deployExtension(name, url);
+ }
+
+ protected void deployExtension(String name, URL url) {
+ throw new UnsupportedOperationException("");
+// // FIXME for now, assume this class's ClassLoader is the Tuscany system classloader
+// // FIXME we should really use the one associated with the parent composite
+// CompositeClassLoader extensionCL = new CompositeClassLoader(getClass().getClassLoader());
+//
+// // see if the URL points to a composite JAR by looking for a default SCDL file inside it
+// URL scdlLocation;
+// try {
+// scdlLocation = new URL("jar:" + url.toExternalForm() + "!/META-INF/sca/default.scdl");
+// } catch (MalformedURLException e) {
+// // the form of the jar: URL should be correct given url.toExternalForm() worked
+// throw new AssertionError();
+// }
+// try {
+// scdlLocation.openStream().close();
+// // we connected to the SCDL so let's add the JAR file to the classloader
+// extensionCL.addURL(url);
+// } catch (IOException e) {
+// // assume that the URL we were given is not a JAR file so just use the supplied resource
+// scdlLocation = url;
+// }
+//
+// // create a ComponentDefinition to represent the component we are going to deploy
+// SystemCompositeImplementation implementation = new SystemCompositeImplementation();
+// implementation.setScdlLocation(scdlLocation);
+// implementation.setClassLoader(extensionCL);
+// URI uri = parent.getUri().resolve(name);
+// ComponentDefinition<SystemCompositeImplementation> definition =
+// new ComponentDefinition<SystemCompositeImplementation>(uri, implementation);
+//
+// // FIXME: [rfeng] Should we reset the thread context class loader here?
+// // From the debugger with tomcat, the current TCCL is the RealmClassLoader
+// // ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
+// try {
+// // Thread.currentThread().setContextClassLoader(extensionCL);
+// Component component;
+// try {
+// component = deployer.deploy(parent, definition);
+// component.start();
+// } catch (BuilderException e) {
+// // FIXME JFM handle the exception
+// e.printStackTrace();
+// } catch (ComponentException e) {
+// // FIXME handle the exception
+// e.printStackTrace();
+// } catch (ResolutionException e) {
+// // FIXME handle the exception
+// e.printStackTrace();
+// }
+// } catch (LoaderException e) {
+// // FIXME handle the exception
+// e.printStackTrace();
+// }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistry.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistry.java
new file mode 100644
index 0000000000..38ce4d16d2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistry.java
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.services.host;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.osoa.sca.annotations.Service;
+
+import org.apache.tuscany.spi.host.ResourceHost;
+import org.apache.tuscany.spi.host.ResourceHostRegistry;
+import org.apache.tuscany.spi.host.ResourceResolutionException;
+
+/**
+ * The default implementation of a <code>ResourceRegisty</code> that resolves resources in the <code>SCA://</code>
+ * namespace against its parent composite and delegates resolution to registered <code>ResourceHost</code>s for other
+ * namespaces. The search order for resources resolved by type starts with the SCA namespace and proceeds to hosts in
+ * the order they were registered.
+ *
+ * @version $Rev$ $Date$
+ */
+@Service(interfaces = {ResourceHost.class, ResourceHostRegistry.class})
+public class DelegatingResourceHostRegistry implements ResourceHost, ResourceHostRegistry {
+ private static final String SCA_PREFIX = "SCA://";
+ private Map<String, ResourceHost> resourceHosts = new HashMap<String, ResourceHost>();
+ private Map<Class<?>, Object> systemResources = new HashMap<Class<?>, Object>();
+ private Map<Key, Object> mappedSystemResources = new HashMap<Key, Object>();
+
+ public DelegatingResourceHostRegistry() {
+ }
+
+ public void registerResourceHost(String uri, ResourceHost host) {
+ resourceHosts.put(uri, host);
+ }
+
+ public void unregisterResourceHost(String uri) {
+ resourceHosts.remove(uri);
+ }
+
+ public void registerResource(Class<?> type, Object resource) {
+ systemResources.put(type, resource);
+ }
+
+ public void registerResource(Class<?> type, String name, Object resource) {
+ mappedSystemResources.put(new Key(type, name), resource);
+ }
+
+ public void unregisterResource(Class<?> type, String name) {
+ mappedSystemResources.remove(new Key(type, name));
+ }
+
+ public void unregisterResource(Class<?> type) {
+ systemResources.remove(type);
+ }
+
+ public <T> T resolveResource(Class<T> type) throws ResourceResolutionException {
+ T instance = type.cast(systemResources.get(type));
+ if (instance == null) {
+ for (ResourceHost host : resourceHosts.values()) {
+ instance = host.resolveResource(type);
+ if (instance != null) {
+ return instance;
+ }
+ }
+ }
+ return instance;
+ }
+
+ public <T> T resolveResource(Class<T> type, String mappedName) throws ResourceResolutionException {
+ if (mappedName.startsWith(SCA_PREFIX)) {
+ String name = mappedName.substring(SCA_PREFIX.length());
+ return type.cast(mappedSystemResources.get(new Key(type, name)));
+ } else {
+ int pos = mappedName.indexOf("://");
+ if (pos == -1) {
+ return type.cast(mappedSystemResources.get(new Key(type, mappedName)));
+ }
+ String uri = mappedName.substring(0, pos + 3);
+ ResourceHost host = resourceHosts.get(uri);
+ if (host == null) {
+ throw new ResourceResolutionException("No resource host for URI", uri);
+ }
+ return host.resolveResource(type, mappedName);
+ }
+ }
+
+ private class Key {
+ private Class<?> clazz;
+ private String name;
+
+ public Key(Class<?> clazz, String name) {
+ this.clazz = clazz;
+ this.name = name;
+ }
+
+ public Key(Class<?> clazz) {
+ this.clazz = clazz;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ Key key = (Key) o;
+
+ if (clazz != null ? !clazz.equals(key.clazz) : key.clazz != null) {
+ return false;
+ }
+ if (name != null ? !name.equals(key.name) : key.name != null) {
+ return false;
+ }
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = clazz != null ? clazz.hashCode() : 0;
+ result = 31 * result + (name != null ? name.hashCode() : 0);
+ return result;
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/store/memory/MemoryStore.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/store/memory/MemoryStore.java
new file mode 100644
index 0000000000..a48cd5a2d7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/store/memory/MemoryStore.java
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.services.store.memory;
+
+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.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;
+
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.event.AbstractEventPublisher;
+import org.apache.tuscany.spi.services.store.DuplicateRecordException;
+import org.apache.tuscany.spi.services.store.RecoveryListener;
+import org.apache.tuscany.spi.services.store.Store;
+import org.apache.tuscany.spi.services.store.StoreExpirationEvent;
+import org.apache.tuscany.spi.services.store.StoreMonitor;
+import org.apache.tuscany.spi.services.store.StoreWriteException;
+
+import org.apache.tuscany.api.annotation.Monitor;
+
+/**
+ * Implements a non-durable, non-transactional store using a simple in-memory map
+ *
+ * @version $Rev$ $Date$
+ */
+@Service(Store.class)
+@EagerInit
+public class MemoryStore extends AbstractEventPublisher implements Store {
+ private Map<SCAObject, Map<String, Record>> 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(@Monitor StoreMonitor monitor) {
+ this.monitor = monitor;
+ this.store = new ConcurrentHashMap<SCAObject, Map<String, Record>>();
+ 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(SCAObject owner, String id, Object object, long expiration) throws StoreWriteException {
+ Map<String, Record> map = store.get(owner);
+ if (map == null) {
+ map = new ConcurrentHashMap<String, Record>();
+ store.put(owner, map);
+ }
+ if (map.containsKey(id)) {
+ throw new DuplicateRecordException(owner.getUri().toString(), id);
+ }
+ map.put(id, new Record(object, expiration));
+ }
+
+ public void updateRecord(SCAObject owner, String id, Object object, long expiration) throws StoreWriteException {
+ Map<String, Record> map = store.get(owner);
+ if (map == null) {
+ throw new StoreWriteException("Record not found", owner.getUri().toString(), id);
+ }
+ Record record = map.get(id);
+ if (record == null) {
+ throw new StoreWriteException("Record not found", owner.getUri().toString(), id);
+ }
+ record.data = object;
+ }
+
+ public Object readRecord(SCAObject owner, String id) {
+ Map<String, Record> 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(SCAObject owner, String id) throws StoreWriteException {
+ Map<String, Record> map = store.get(owner);
+ if (map == null) {
+ throw new StoreWriteException("Owner not found", owner.getUri().toString(), id);
+ }
+ if (map.remove(id) == null) {
+ throw new StoreWriteException("Owner not found", owner.getUri().toString(), 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<SCAObject, Map<String, Record>> entries : store.entrySet()) {
+ for (Map.Entry<String, Record> entry : entries.getValue().entrySet()) {
+ final long expiration = entry.getValue().expiration;
+ if (expiration != NEVER && now >= expiration) {
+ SCAObject owner = entries.getKey();
+ Object instance = entry.getValue().getData();
+ // notify listeners of the expiration
+ StoreExpirationEvent event = new StoreExpirationEvent(this, owner, instance);
+ publish(event);
+ entries.getValue().remove(entry.getKey());
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/work/jca/JcaWorkScheduler.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/work/jca/JcaWorkScheduler.java
new file mode 100644
index 0000000000..79b7bf4ca1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/work/jca/JcaWorkScheduler.java
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.services.work.jca;
+
+import javax.resource.spi.work.Work;
+import javax.resource.spi.work.WorkEvent;
+import javax.resource.spi.work.WorkException;
+import javax.resource.spi.work.WorkListener;
+import javax.resource.spi.work.WorkManager;
+import javax.resource.spi.work.WorkRejectedException;
+
+import org.apache.tuscany.spi.services.work.NotificationListener;
+import org.apache.tuscany.spi.services.work.WorkScheduler;
+import org.apache.tuscany.spi.services.work.WorkSchedulerException;
+
+/**
+ * A work scheduler implementation based on the JCA SPI work manager.
+ * <p/>
+ * <p/>
+ * This needs a JCA SPI 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. </p>
+ */
+public class JcaWorkScheduler implements WorkScheduler {
+
+ /**
+ * Underlying JCA work manager
+ */
+ private WorkManager jcaWorkManager;
+
+ /**
+ * Initializes the JCA work manager.
+ *
+ * @param jcaWorkManager JCA work manager.
+ */
+ public JcaWorkScheduler(WorkManager jcaWorkManager) {
+
+ if (jcaWorkManager == null) {
+ throw new IllegalArgumentException("Work manager cannot be null");
+ }
+ this.jcaWorkManager = jcaWorkManager;
+
+ }
+
+ /**
+ * 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 <T extends Runnable> 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 <T extends Runnable> void scheduleWork(T work, NotificationListener<T> listener) {
+
+ if (work == null) {
+ throw new IllegalArgumentException("Work cannot be null");
+ }
+
+ JcaWork<T> jcaWork = new JcaWork<T>(work);
+ try {
+ if (listener == null) {
+ jcaWorkManager.scheduleWork(jcaWork);
+ } else {
+ JcaWorkListener<T> jcaWorkListener = new JcaWorkListener<T>(listener);
+ // TODO Clarify the usage of timeout and execution context
+ jcaWorkManager.scheduleWork(jcaWork, -1, null, jcaWorkListener);
+ }
+ } 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 JcaWorkListener<T extends Runnable> implements WorkListener {
+
+ // Notification listener
+ private NotificationListener<T> listener;
+
+ /*
+ * Initializes the notification listener.
+ */
+ public JcaWorkListener(NotificationListener<T> listener) {
+ this.listener = listener;
+ }
+
+ /*
+ * Callback when the work is accepted.
+ */
+ public void workAccepted(WorkEvent workEvent) {
+ T work = getWork(workEvent);
+ listener.workAccepted(work);
+ }
+
+ /*
+ * Callback when the work is rejected.
+ */
+ public void workRejected(WorkEvent workEvent) {
+ T work = getWork(workEvent);
+ listener.workRejected(work);
+ }
+
+ /*
+ * Callback when the work is started.
+ */
+ public void workStarted(WorkEvent workEvent) {
+ T work = getWork(workEvent);
+ listener.workStarted(work);
+ }
+
+ /*
+ * Callback when the work is completed.
+ */
+ public void workCompleted(WorkEvent workEvent) {
+ T work = getWork(workEvent);
+ Exception exception = workEvent.getException();
+ if (exception != null) {
+ listener.workFailed(work, exception);
+ } else {
+ listener.workCompleted(work);
+ }
+ }
+
+ /*
+ * Gets the underlying work from the work event.
+ */
+ @SuppressWarnings("unchecked")
+ private T getWork(WorkEvent workEvent) {
+ JcaWork<T> jcaWork = (JcaWork<T>) workEvent.getWork();
+ return jcaWork.getWork();
+ }
+
+ }
+
+ /*
+ * JCA work wrapper.
+ */
+ private class JcaWork<T extends Runnable> implements Work {
+
+ // Work that is being executed.
+ private T work;
+
+ /*
+ * Initializes the work instance.
+ */
+ public JcaWork(T work) {
+ this.work = work;
+ }
+
+ /*
+ * Releases the work.
+ */
+ public void release() {
+ }
+
+ /*
+ * Performs the work.
+ */
+ public void run() {
+ work.run();
+ }
+
+ /*
+ * Returns the completed work.
+ */
+ public T getWork() {
+ return work;
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkScheduler.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkScheduler.java
new file mode 100644
index 0000000000..401960c287
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkScheduler.java
@@ -0,0 +1,217 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.services.work.jsr237;
+
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Scope;
+
+import org.apache.tuscany.spi.services.work.NotificationListener;
+import org.apache.tuscany.spi.services.work.WorkScheduler;
+import org.apache.tuscany.spi.services.work.WorkSchedulerException;
+
+import commonj.work.Work;
+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.
+ * <p/>
+ * <p/>
+ * 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. </p>
+ */
+@Scope("COMPOSITE")
+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(@Reference 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 <T extends Runnable> 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 <T extends Runnable> void scheduleWork(T work, NotificationListener<T> listener) {
+
+ if (work == null) {
+ throw new IllegalArgumentException("Work cannot be null");
+ }
+
+ Jsr237Work<T> jsr237Work = new Jsr237Work<T>(work);
+ try {
+ if (listener == null) {
+ jsr237WorkManager.schedule(jsr237Work);
+ } else {
+ Jsr237WorkListener<T> jsr237WorkListener = new Jsr237WorkListener<T>(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<T extends Runnable> implements WorkListener {
+
+ // Notification listener
+ private NotificationListener<T> listener;
+
+ // Work
+ private T work;
+
+ /*
+ * Initializes the notification listener.
+ */
+ public Jsr237WorkListener(NotificationListener<T> 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;
+ }
+
+ }
+
+ /*
+ * JCA work wrapper.
+ */
+ private class Jsr237Work<T extends Runnable> implements 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();
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/work/jsr237/workmanager/DefaultWorkEvent.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/work/jsr237/workmanager/DefaultWorkEvent.java
new file mode 100644
index 0000000000..c391d0b597
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/work/jsr237/workmanager/DefaultWorkEvent.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.core.services.work.jsr237.workmanager;
+
+import commonj.work.WorkEvent;
+import commonj.work.WorkException;
+import commonj.work.WorkItem;
+
+/**
+ * Default immutable implementation of the <code>WorkEvent</code> class.
+ */
+class DefaultWorkEvent 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 DefaultWorkEvent(final DefaultWorkItem workItem) {
+ this.workItem = workItem;
+ this.exception = workItem.getException();
+ }
+
+ /**
+ * Returns the work type based on whether the work was accepted, started,
+ * rejected or completed.
+ *
+ * @return Work type.
+ */
+ public int getType() {
+ return workItem.getStatus();
+ }
+
+ /**
+ * Returns the work item associated with this work type.
+ *
+ * @return Work item.
+ */
+ public WorkItem getWorkItem() {
+ return workItem;
+ }
+
+ /**
+ * Returns the exception if the work completed with an exception.
+ *
+ * @return Work exception.
+ */
+ public WorkException getException() {
+ return exception;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/work/jsr237/workmanager/DefaultWorkItem.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/work/jsr237/workmanager/DefaultWorkItem.java
new file mode 100644
index 0000000000..0adc005bb0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/work/jsr237/workmanager/DefaultWorkItem.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.core.services.work.jsr237.workmanager;
+
+import commonj.work.Work;
+import commonj.work.WorkException;
+import commonj.work.WorkItem;
+
+/**
+ * An identity based immutable implementation of the <code>WorkItem</code>
+ * interface.
+ *
+ */
+class DefaultWorkItem 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 DefaultWorkItem(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() == DefaultWorkItem.class) && ((DefaultWorkItem) 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() != DefaultWorkItem.class) {
+ throw new ClassCastException(o.getClass().getName());
+ } else {
+ return ((DefaultWorkItem) o).getId().compareTo(getId());
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/work/jsr237/workmanager/ThreadPoolWorkManager.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/work/jsr237/workmanager/ThreadPoolWorkManager.java
new file mode 100644
index 0000000000..1a7639b41d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/services/work/jsr237/workmanager/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.core.services.work.jsr237.workmanager;
+
+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.
+ * <p/>
+ * <p/>
+ * This implementation supports only local work.
+ * <p/>
+ * TODO Elaborate the implementation. </p>
+ */
+public class ThreadPoolWorkManager implements WorkManager {
+
+ // Map of work items currently handled by the work manager
+ private Map<DefaultWorkItem, WorkListener> workItems = new ConcurrentHashMap<DefaultWorkItem, WorkListener>();
+
+ // 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 {
+
+ DefaultWorkItem workItem = new DefaultWorkItem(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 DefaultWorkEvent(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 DefaultWorkItem workItem, final Work work) {
+ WorkListener listener = workItems.get(workItem);
+ if (listener != null) {
+ workItem.setStatus(WorkEvent.WORK_ACCEPTED);
+ WorkEvent event = new DefaultWorkEvent(workItem);
+ listener.workAccepted(event);
+ }
+ }
+
+ /*
+ * Method to indicate a work start.
+ */
+ private void workStarted(final DefaultWorkItem workItem, final Work work) {
+ WorkListener listener = workItems.get(workItem);
+ if (listener != null) {
+ workItem.setStatus(WorkEvent.WORK_STARTED);
+ WorkEvent event = new DefaultWorkEvent(workItem);
+ listener.workStarted(event);
+ }
+ }
+
+ /*
+ * Method to indicate a work completion.
+ */
+ private void workCompleted(final DefaultWorkItem workItem, final Work work) {
+ workCompleted(workItem, work, null);
+ }
+
+ /*
+ * Method to indicate a work completion.
+ */
+ private void workCompleted(final DefaultWorkItem 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 DefaultWorkEvent(workItem);
+ listener.workCompleted(event);
+ workItems.remove(workItem);
+ }
+ }
+
+ /*
+ * Schedules the work using the threadpool.
+ */
+ private boolean scheduleWork(final Work work, final DefaultWorkItem 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 DefaultWorkItem workItem;
+
+ // The original work.
+ private Work decoratedWork;
+
+ /*
+ * Initializes the work item and underlying work.
+ */
+ private DecoratingWork(final DefaultWorkItem workItem, final Work decoratedWork) {
+ this.workItem = workItem;
+ this.decoratedWork = decoratedWork;
+ }
+
+ /*
+ * Overrides the run method.
+ */
+ public void run() {
+ workStarted(workItem, decoratedWork);
+ try {
+ decoratedWork.run();
+ workCompleted(workItem, decoratedWork);
+ } catch (Throwable th) {
+ workCompleted(workItem, decoratedWork, new WorkException(th.getMessage(), th));
+ }
+ }
+
+ }
+
+ @Destroy
+ public void destroy() {
+ executor.shutdown();
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/util/FileHelper.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/util/FileHelper.java
new file mode 100644
index 0000000000..2544c90846
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/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.core.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.
+ * <p>
+ * This method will handle a file in either Unix or Windows format. The
+ * position of the last forward or backslash is returned.
+ * <p>
+ * 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.
+ * <p>
+ * 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.
+ * <p>
+ * 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.
+ * <p>
+ * This method will handle a file in either Unix or Windows format. The text
+ * after the last forward or backslash is returned.
+ *
+ * <pre>
+ * a/b/c.txt --&gt; c.txt
+ * a.txt --&gt; a.txt
+ * a/b/c --&gt; c
+ * a/b/c/ --&gt; &quot;&quot;
+ * </pre>
+ *
+ * <p>
+ * 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.
+ * <p>
+ * This method returns the textual part of the filename after the last dot.
+ * There must be no directory separator after the dot.
+ *
+ * <pre>
+ * foo.txt --&gt; &quot;txt&quot;
+ * a/b/c.jpg --&gt; &quot;jpg&quot;
+ * a/b.txt/c --&gt; &quot;&quot;
+ * a/b/c --&gt; &quot;&quot;
+ * </pre>
+ *
+ * <p>
+ * 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.
+ * <p>
+ * The difference between File.delete() and this method are:
+ * <ul>
+ * <li>A directory to be deleted does not have to be empty.</li>
+ * <li>You get exceptions when a file or directory cannot be deleted.
+ * (java.io.File methods returns a boolean)</li>
+ * </ul>
+ *
+ * @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 <code>URL</code> to a <code>File</code>.
+ * <p>
+ * From version 1.1 this method will decode the URL. Syntax such as
+ * <code>file:///my%20docs/file.txt</code> will be correctly decoded to
+ * <code>/my docs/file.txt</code>.
+ *
+ * @param url the file URL to convert, null returns null
+ * @return the equivalent <code>File</code> object, or <code>null</code>
+ * if the URL's protocol is not <code>file</code>
+ * @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 <code>null</code>
+ * @throws NullPointerException if the directory is <code>null</code>
+ * @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.
+ * <p>
+ * 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.
+ * <p>
+ * 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
+ * <code>null</code>
+ * @param destDir the new directory, must not be <code>null</code>
+ * @throws NullPointerException if source or destination is
+ * <code>null</code>
+ * @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.
+ * <p>
+ * This method copies the contents of the specified source directory to
+ * within the specified destination directory.
+ * <p>
+ * 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
+ * <code>null</code>
+ * @param destDir the new directory, must not be <code>null</code>
+ * @param preserveFileDate true if the file date of the copy should be the
+ * same as the original
+ * @throws NullPointerException if source or destination is
+ * <code>null</code>
+ * @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.
+ * <p>
+ * This method copies the source directory and all its contents to a
+ * directory of the same name in the specified destination directory.
+ * <p>
+ * 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
+ * <code>null</code>
+ * @param destDir the directory to place the copy in, must not be
+ * <code>null</code>
+ * @throws NullPointerException if source or destination is
+ * <code>null</code>
+ * @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.
+ * <p>
+ * 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 <code>null</code>
+ * @param destFile the new file, must not be <code>null</code>
+ * @throws NullPointerException if source or destination is
+ * <code>null</code>
+ * @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.
+ * <p>
+ * 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 <code>null</code>
+ * @param destFile the new file, must not be <code>null</code>
+ * @param preserveFileDate true if the file date of the copy should be the
+ * same as the original
+ * @throws NullPointerException if source or destination is
+ * <code>null</code>
+ * @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()) {
+ 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.
+ * <p>
+ * 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 <code>null</code>
+ * @param destDir the directory to place the copy in, must not be
+ * <code>null</code>
+ * @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.
+ * <p>
+ * 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 <code>null</code>
+ * @param destDir the directory to place the copy in, must not be
+ * <code>null</code>
+ * @param preserveFileDate true if the file date of the copy should be the
+ * same as the original
+ * @throws NullPointerException if source or destination is
+ * <code>null</code>
+ * @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 <code>null</code>
+ * @throws NullPointerException if the directory is <code>null</code>
+ * @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
+ * <code>null</code>
+ * @param destDir the validated destination directory, must not be
+ * <code>null</code>
+ * @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 <code>null</code>
+ * @param destFile the validated destination file, must not be
+ * <code>null</code>
+ * @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 <code>null</code>
+ * @throws NullPointerException if the file is <code>null</code>
+ * @throws IOException in case deletion is unsuccessful
+ */
+ public static void forceDeleteOnExit(File file) throws IOException {
+ if (file.isDirectory()) {
+ deleteDirectoryOnExit(file);
+ } else {
+ file.deleteOnExit();
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/util/IOHelper.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/util/IOHelper.java
new file mode 100644
index 0000000000..62a007bd05
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/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.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 <code>InputStream</code>.
+ * <p>
+ * 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 <code>OutputStream</code>.
+ * <p>
+ * 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 <code>InputStream</code> to an
+ * <code>OutputStream</code>.
+ * <p>
+ * This method buffers the input internally, so there is no need to use a
+ * <code>BufferedInputStream</code>.
+ *
+ * @param input the <code>InputStream</code> to read from
+ * @param output the <code>OutputStream</code> 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/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/util/JavaIntrospectionHelper.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/util/JavaIntrospectionHelper.java
new file mode 100644
index 0000000000..6b11725481
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/util/JavaIntrospectionHelper.java
@@ -0,0 +1,439 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.util;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Implements various reflection-related operations
+ *
+ * @version $Rev$ $Date$
+ */
+public final class JavaIntrospectionHelper {
+
+ private static final Class[] EMPTY_CLASS_ARRY = new Class[0];
+
+ /**
+ * Hide the constructor
+ */
+ private JavaIntrospectionHelper() {
+ }
+
+
+ /**
+ * Returns a collection of public, and protected fields declared by a class or one of its supertypes
+ */
+ public static Set<Field> getAllPublicAndProtectedFields(Class clazz) {
+ return getAllPublicAndProtectedFields(clazz, new HashSet<Field>());
+ }
+
+ /**
+ * Recursively evaluates the type hierachy to return all fields that are public or protected
+ */
+ private static Set<Field> getAllPublicAndProtectedFields(Class clazz, Set<Field> fields) {
+ if (clazz == null || clazz.isArray() || Object.class.equals(clazz)) {
+ return fields;
+ }
+ fields = getAllPublicAndProtectedFields(clazz.getSuperclass(), fields);
+ Field[] declaredFields = clazz.getDeclaredFields();
+ for (Field field : declaredFields) {
+ int modifiers = field.getModifiers();
+ if ((Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers)) && !Modifier.isStatic(modifiers)) {
+ field.setAccessible(true); // ignore Java accessibility
+ fields.add(field);
+ }
+ }
+ return fields;
+ }
+
+ /**
+ * Returns a collection of public and protected methods declared by a class or one of its supertypes. Note that
+ * overriden methods will not be returned in the collection (i.e. only the method override will be). <p/> This
+ * method can potentially be expensive as reflection information is not cached. It is assumed that this method will
+ * be used during a configuration phase.
+ */
+ public static Set<Method> getAllUniquePublicProtectedMethods(Class clazz) {
+ return getAllUniqueMethods(clazz, new HashSet<Method>());
+ }
+
+ /**
+ * Recursively evaluates the type hierarchy to return all unique methods
+ */
+ private static Set<Method> getAllUniqueMethods(Class pClass, Set<Method> methods) {
+ if (pClass == null || pClass.isArray() || Object.class.equals(pClass)) {
+ return methods;
+ }
+ // we first evaluate methods of the subclass and then move to the parent
+ Method[] declaredMethods = pClass.getDeclaredMethods();
+ for (Method declaredMethod : declaredMethods) {
+ int modifiers = declaredMethod.getModifiers();
+ if ((!Modifier.isPublic(modifiers) && !Modifier.isProtected(modifiers)) || Modifier.isStatic(modifiers)) {
+ continue;
+ }
+ if (methods.size() == 0) {
+ methods.add(declaredMethod);
+ } else {
+ List<Method> temp = new ArrayList<Method>();
+ boolean matched = false;
+ for (Method method : methods) {
+ // only add if not already in the set from a supclass (i.e. the
+ // method is not overrided)
+ if (exactMethodMatch(declaredMethod, method)) {
+ matched = true;
+ break;
+ }
+ }
+ if (!matched) {
+ // TODO ignore Java accessibility
+ declaredMethod.setAccessible(true);
+ temp.add(declaredMethod);
+ }
+ methods.addAll(temp);
+ temp.clear();
+ }
+ }
+ // evaluate class hierarchy - this is done last to track inherited methods
+ methods = getAllUniqueMethods(pClass.getSuperclass(), methods);
+ return methods;
+ }
+
+ /**
+ * Finds the closest matching field with the given name, that is, a field of the exact specified type or,
+ * alternately, of a supertype.
+ *
+ * @param name the name of the field
+ * @param type the field type
+ * @param fields the collection of fields to search
+ * @return the matching field or null if not found
+ */
+ public static Field findClosestMatchingField(String name, Class type, Set<Field> fields) {
+ Field candidate = null;
+ for (Field field : fields) {
+ if (field.getName().equals(name)) {
+ if (field.getType().equals(type)) {
+ return field; // exact match
+ } else if (field.getType().isAssignableFrom(type)
+ || (field.getType().isPrimitive() && primitiveAssignable(field.getType(), type))) {
+ // We could have the situation where a field parameter is a primitive and the demarshalled value is
+ // an object counterpart (e.g. Integer and int)
+ // @spec issue
+ // either an interface or super class, so keep a reference until
+ // we know there are no closer types
+ candidate = field;
+ }
+ }
+ }
+ if (candidate != null) {
+ return candidate;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Finds the closest matching method with the given name, that is, a method taking the exact parameter types or,
+ * alternately, parameter supertypes.
+ *
+ * @param name the name of the method
+ * @param types the method parameter types
+ * @param methods the collection of methods to search
+ * @return the matching method or null if not found
+ */
+ public static Method findClosestMatchingMethod(String name, Class[] types, Set<Method> methods) {
+ if (types == null) {
+ types = EMPTY_CLASS_ARRY;
+ }
+ Method candidate = null;
+ for (Method method : methods) {
+ if (method.getName().equals(name) && method.getParameterTypes().length == types.length) {
+ Class<?>[] params = method.getParameterTypes();
+ boolean disqualify = false;
+ boolean exactMatch = true;
+ for (int i = 0; i < params.length; i++) {
+ if (!params[i].equals(types[i]) && !params[i].isAssignableFrom(types[i])) {
+ // no match
+ disqualify = true;
+ exactMatch = false;
+ break;
+ } else if (!params[i].equals(types[i]) && params[i].isAssignableFrom(types[i])) {
+ // not exact match
+ exactMatch = false;
+ }
+ }
+ if (disqualify) {
+ continue;
+ } else if (exactMatch) {
+ return method;
+ } else {
+ candidate = method;
+ }
+ }
+ }
+ if (candidate != null) {
+ return candidate;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Searches a collection of fields for one that matches by name and has a multiplicity type. i.e. a List or Array of
+ * interfaces
+ *
+ * @return a matching field or null
+ */
+ public static Field findMultiplicityFieldByName(String name, Set<Field> fields) {
+ for (Field candidate : fields) {
+ if (candidate.getName().equals(name)
+ && (List.class.isAssignableFrom(candidate.getType()) || (candidate.getType().isArray()
+ && candidate.getType().getComponentType() != null && candidate.getType().getComponentType()
+ .isInterface()))) {
+ return candidate;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Searches a collection of method for one that matches by name and has single parameter of a multiplicity type.
+ * i.e. a List or Array of interfaces
+ *
+ * @return a matching method or null
+ */
+ public static Method findMultiplicityMethodByName(String name, Set<Method> methods) {
+ for (Method candidate : methods) {
+ if (candidate.getName().equals(name)
+ && candidate.getParameterTypes().length == 1
+ && (List.class.isAssignableFrom(candidate.getParameterTypes()[0])
+ || (candidate.getParameterTypes()[0].isArray()
+ && candidate.getParameterTypes()[0].getComponentType() != null
+ && candidate.getParameterTypes()[0].getComponentType().isInterface()))) {
+ return candidate;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Determines if two methods "match" - that is, they have the same method names and exact parameter types (one is
+ * not a supertype of the other)
+ */
+ public static boolean exactMethodMatch(Method method1, Method method2) {
+ if (!method1.getName().equals(method2.getName())) {
+ return false;
+ }
+ Class[] types1 = method1.getParameterTypes();
+ Class[] types2 = method2.getParameterTypes();
+ if (types1.length == 0 && types2.length == 0) {
+ return true;
+ } else if (types1.length == types2.length) {
+ for (int n = 0; n < types1.length; n++) {
+ if (!types1[n].equals(types2[n])) {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ public static <T> Constructor<T> getDefaultConstructor(Class<T> clazz) throws NoSuchMethodException {
+ return clazz.getConstructor((Class[]) null);
+ }
+
+ /**
+ * Loads a class corresponding to the class name using the current context class loader.
+ *
+ * @throws ClassNotFoundException if the class was not found on the classpath
+ */
+ public static Class loadClass(String pName) throws ClassNotFoundException {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ return Class.forName(pName, true, loader);
+ }
+
+ /**
+ * Returns the simple name of a class - i.e. the class name devoid of its package qualifier
+ *
+ * @param implClass the implmentation class
+ */
+ public static String getBaseName(Class<?> implClass) {
+ String baseName = implClass.getName();
+ int lastDot = baseName.lastIndexOf('.');
+ if (lastDot != -1) {
+ baseName = baseName.substring(lastDot + 1);
+ }
+ return baseName;
+ }
+
+ public static boolean isImmutable(Class clazz) {
+ return String.class == clazz
+ || clazz.isPrimitive()
+ || Number.class.isAssignableFrom(clazz)
+ || Boolean.class.isAssignableFrom(clazz)
+ || Character.class.isAssignableFrom(clazz)
+ || Byte.class.isAssignableFrom(clazz);
+ }
+
+ /**
+ * Takes a property name and converts it to a getter method name according to JavaBean conventions. For example,
+ * property <code>foo<code> is returned as <code>getFoo</code>
+ */
+ public static String toGetter(String name) {
+ return "get" + name.toUpperCase().substring(0, 1) + name.substring(1);
+ }
+
+ /**
+ * Takes a setter or getter method name and converts it to a property name according to JavaBean conventions. For
+ * example, <code>setFoo(var)</code> is returned as property <code>foo<code>
+ */
+ public static String toPropertyName(String name) {
+ if (!name.startsWith("set")) {
+ return name;
+ }
+ return Character.toLowerCase(name.charAt(3)) + name.substring(4);
+ }
+
+ /**
+ * Takes a property name and converts it to a setter method name according to JavaBean conventions. For example, the
+ * property <code>foo<code> is returned as <code>setFoo(var)</code>
+ */
+ public static String toSetter(String name) {
+ return "set" + name.toUpperCase().substring(0, 1) + name.substring(1);
+ }
+
+ /**
+ * Compares a two types, assuming one is a primitive, to determine if the other is its object counterpart
+ */
+ private static boolean primitiveAssignable(Class memberType, Class param) {
+ if (memberType == Integer.class) {
+ return param == Integer.TYPE;
+ } else if (memberType == Double.class) {
+ return param == Double.TYPE;
+ } else if (memberType == Float.class) {
+ return param == Float.TYPE;
+ } else if (memberType == Short.class) {
+ return param == Short.TYPE;
+ } else if (memberType == Character.class) {
+ return param == Character.TYPE;
+ } else if (memberType == Boolean.class) {
+ return param == Boolean.TYPE;
+ } else if (memberType == Byte.class) {
+ return param == Byte.TYPE;
+ } else if (param == Integer.class) {
+ return memberType == Integer.TYPE;
+ } else if (param == Double.class) {
+ return memberType == Double.TYPE;
+ } else if (param == Float.class) {
+ return memberType == Float.TYPE;
+ } else if (param == Short.class) {
+ return memberType == Short.TYPE;
+ } else if (param == Character.class) {
+ return memberType == Character.TYPE;
+ } else if (param == Boolean.class) {
+ return memberType == Boolean.TYPE;
+ } else if (param == Byte.class) {
+ return memberType == Byte.TYPE;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Returns the generic types represented in the given type. Usage as follows: <code>
+ * JavaIntrospectionHelper.getGenerics(field.getGenericType());
+ * <p/>
+ * JavaIntrospectionHelper.getGenerics(m.getGenericParameterTypes()[0];); </code>
+ *
+ * @return the generic types in order of declaration or an empty array if the type is not genericized
+ */
+ public static List<? extends Type> getGenerics(Type genericType) {
+ List<Type> classes = new ArrayList<Type>();
+ if (genericType instanceof ParameterizedType) {
+ ParameterizedType ptype = (ParameterizedType) genericType;
+ // get the type arguments
+ Type[] targs = ptype.getActualTypeArguments();
+ for (Type targ : targs) {
+ classes.add(targ);
+ }
+ }
+ return classes;
+ }
+
+ /**
+ * Returns the generic type specified by the class at the given position as in:
+ * <p/>
+ * <code> public class Foo<Bar,Baz>{ //.. }
+ * <p/>
+ * JavaIntrospectionHelper.introspectGeneric(Foo.class,1); <code>
+ * <p/>
+ * will return Baz.
+ */
+ public static Class introspectGeneric(Class<?> clazz, int pos) {
+ assert clazz != null : "No class specified";
+ Type type = clazz.getGenericSuperclass();
+ if (type instanceof ParameterizedType) {
+ Type[] args = ((ParameterizedType) type).getActualTypeArguments();
+ if (args.length <= pos) {
+ throw new IllegalArgumentException("Invalid index value for generic class " + clazz.getName());
+ }
+ return (Class) ((ParameterizedType) type).getActualTypeArguments()[pos];
+ } else {
+ Type[] interfaces = clazz.getGenericInterfaces();
+ for (Type itype : interfaces) {
+ if (!(itype instanceof ParameterizedType)) {
+ continue;
+ }
+ ParameterizedType interfaceType = (ParameterizedType) itype;
+ return (Class) interfaceType.getActualTypeArguments()[0];
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the set of interfaces implemented by the given class and its ancestors or a blank set if none
+ */
+ public static Set<Class> getAllInterfaces(Class clazz) {
+ Set<Class> implemented = new HashSet<Class>();
+ getAllInterfaces(clazz, implemented);
+ return implemented;
+ }
+
+ private static void getAllInterfaces(Class clazz, Set<Class> implemented) {
+ Class[] interfaces = clazz.getInterfaces();
+ for (Class interfaze : interfaces) {
+ implemented.add(interfaze);
+ }
+ Class<?> superClass = clazz.getSuperclass();
+ // Object has no superclass so check for null
+ if (superClass != null && !superClass.equals(Object.class)) {
+ getAllInterfaces(superClass, implemented);
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptor.java
new file mode 100644
index 0000000000..c0bf7780f5
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptor.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.core.wire;
+
+import org.osoa.sca.NoRegisteredCallbackException;
+
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+
+/**
+ * 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 Interceptor 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(Interceptor next) {
+ this.next = next;
+ }
+
+ public Interceptor getNext() {
+ return next;
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatter.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatter.java
new file mode 100644
index 0000000000..d5fca62e1b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatter.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.core.wire;
+
+import java.io.PrintWriter;
+
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.IncompatibleServiceContractException;
+
+import org.apache.tuscany.host.monitor.ExceptionFormatter;
+import org.apache.tuscany.host.monitor.FormatterRegistry;
+
+/**
+ * Formats {@link org.apache.tuscany.spi.wire.IncompatibleServiceContractException} for JDK logging
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+public class IncompatibleServiceContractExceptionFormatter implements ExceptionFormatter {
+ private FormatterRegistry factory;
+
+ public IncompatibleServiceContractExceptionFormatter(@Reference FormatterRegistry factory) {
+ this.factory = factory;
+ factory.register(this);
+ }
+
+ public boolean canFormat(Class<?> type) {
+ return IncompatibleServiceContractException.class.isAssignableFrom(type);
+ }
+
+ @Destroy
+ public void destroy() {
+ factory.unregister(this);
+ }
+
+ public PrintWriter write(PrintWriter writer, Throwable exception) {
+ assert exception instanceof IncompatibleServiceContractException;
+ IncompatibleServiceContractException e = (IncompatibleServiceContractException) exception;
+ e.appendBaseMessage(writer);
+ ServiceContract<?> source = e.getSource();
+ String sourceContractName = null;
+ if (source != null) {
+ sourceContractName = source.getInterfaceName();
+ }
+ Operation<?> sourceOperation = e.getSourceOperation();
+ String sourceOpName = null;
+ if (sourceOperation != null) {
+ sourceOpName = sourceOperation.getName();
+ }
+ if (sourceOpName == null) {
+ writer.write("\nSource Contract: " + sourceContractName);
+ } else {
+ writer.write("\nSource Contract: " + sourceContractName + "/" + sourceOpName);
+ }
+ ServiceContract<?> target = e.getTarget();
+ String targetContractName = null;
+ if (target != null) {
+ targetContractName = target.getInterfaceName();
+ }
+ Operation<?> targetOperation = e.getTargetOperation();
+ String targetOpName = null;
+ if (targetOperation != null) {
+ targetOpName = targetOperation.getName();
+ }
+ if (targetOpName == null) {
+ writer.write("\nTarget Contract: " + targetContractName + "\n");
+ } else {
+ writer.write("\nTarget Contract: " + targetContractName + "/" + targetOpName + "\n");
+
+ }
+ return writer;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/InvocationChainImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/InvocationChainImpl.java
new file mode 100644
index 0000000000..921b4e37fa
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/InvocationChainImpl.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.core.wire;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+/**
+ * Default implementation of an invocation chain
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvocationChainImpl implements InvocationChain {
+ protected Operation operation;
+ protected PhysicalOperationDefinition physicalOperation;
+ protected TargetInvoker targetInvoker;
+ protected Interceptor interceptorChainHead;
+ protected Interceptor interceptorChainTail;
+
+ public InvocationChainImpl(PhysicalOperationDefinition operation) {
+ this.physicalOperation = operation;
+ }
+
+ public InvocationChainImpl(Operation operation) {
+ assert operation != null;
+ this.operation = operation;
+ }
+
+ public Operation getOperation() {
+ return operation;
+ }
+
+ public PhysicalOperationDefinition getPhysicalOperation() {
+ return physicalOperation;
+ }
+
+ public void setTargetInvoker(TargetInvoker invoker) {
+ this.targetInvoker = invoker;
+ }
+
+ public TargetInvoker getTargetInvoker() {
+ return targetInvoker;
+ }
+
+ public void addInterceptor(Interceptor interceptor) {
+ if (interceptorChainHead == null) {
+ interceptorChainHead = interceptor;
+ } else {
+ interceptorChainTail.setNext(interceptor);
+ }
+ interceptorChainTail = interceptor;
+ }
+
+ public void addInterceptor(int index, Interceptor interceptor) {
+ int i = 0;
+ Interceptor next = interceptorChainHead;
+ Interceptor prev = null;
+ while (next != null && i < index) {
+ prev = next;
+ next = next.getNext();
+ i++;
+ }
+ if (i == index) {
+ if (prev != null) {
+ prev.setNext(interceptor);
+ } else {
+ interceptorChainHead = interceptor;
+ }
+ interceptor.setNext(next);
+ if (next == null) {
+ interceptorChainTail = interceptor;
+ }
+ } else {
+ throw new ArrayIndexOutOfBoundsException(index);
+ }
+ }
+
+ public Interceptor getHeadInterceptor() {
+ return interceptorChainHead;
+ }
+
+ public Interceptor getTailInterceptor() {
+ return interceptorChainTail;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/InvokerInterceptor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/InvokerInterceptor.java
new file mode 100644
index 0000000000..10cc254451
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/InvokerInterceptor.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.core.wire;
+
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+/**
+ * Serves as a tail interceptor on a target wire chain. This implementation dispatches to the target invoker passed
+ * inside the wire message. Target invokers are passed from the source in order to allow for caching of target
+ * instances.
+ *
+ * @version $Rev$ $Date$
+ * @Deprecated
+ * @see org.apache.tuscany.spi.wire.TargetInvoker
+ */
+public class InvokerInterceptor implements Interceptor {
+
+ public InvokerInterceptor() {
+ }
+
+ public Message invoke(Message msg) throws InvocationRuntimeException {
+ TargetInvoker invoker = msg.getTargetInvoker();
+ if (invoker == null) {
+ throw new InvocationRuntimeException("No target invoker specified on message");
+ }
+ return invoker.invoke(msg);
+ }
+
+ public void setNext(Interceptor next) {
+ throw new IllegalStateException("This interceptor must be the last one in an target interceptor chain");
+ }
+
+ public Interceptor getNext() {
+ return null;
+ }
+
+ public boolean isOptimizable() {
+ return true;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/NoMethodForOperationException.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/NoMethodForOperationException.java
new file mode 100644
index 0000000000..aec281d190
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/NoMethodForOperationException.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.core.wire;
+
+import org.apache.tuscany.spi.wire.ProxyCreationException;
+
+/**
+ * Thrown when an {@link org.apache.tuscany.spi.model.Operation} cannot be mapped to a method on an interface
+ * @version $Rev$ $Date$
+ */
+public class NoMethodForOperationException extends ProxyCreationException {
+ public NoMethodForOperationException() {
+ }
+
+ public NoMethodForOperationException(String message) {
+ super(message);
+ }
+
+ public NoMethodForOperationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public NoMethodForOperationException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptor.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptor.java
new file mode 100644
index 0000000000..d4848cde71
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptor.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.core.wire;
+
+import java.net.URI;
+import java.util.LinkedList;
+
+import org.osoa.sca.ServiceRuntimeException;
+
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.services.work.WorkScheduler;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * 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 WorkContext workContext;
+ private Interceptor next;
+
+ public NonBlockingInterceptor(WorkScheduler workScheduler, WorkContext workContext) {
+ this.workScheduler = workScheduler;
+ this.workContext = workContext;
+ }
+
+ public NonBlockingInterceptor(WorkScheduler workScheduler, WorkContext workContext, Interceptor next) {
+ this.workScheduler = workScheduler;
+ this.workContext = workContext;
+ 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 Object conversationID = workContext.getIdentifier(Scope.CONVERSATION);
+ // Schedule the invocation of the next interceptor in a new Work instance
+ try {
+ workScheduler.scheduleWork(new Runnable() {
+ public void run() {
+ workContext.setCorrelationId(null);
+ // if we got a conversation id, transfer it to new thread
+ if (conversationID != null) {
+ workContext.setIdentifier(Scope.CONVERSATION, conversationID);
+ }
+ next.invoke(msg);
+ }
+ });
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ return RESPONSE;
+ }
+
+ public Interceptor getNext() {
+ return next;
+ }
+
+ public void setNext(Interceptor next) {
+ this.next = next;
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+
+ /**
+ * A dummy message passed back on an invocation
+ */
+ private static class ImmutableMessage implements Message {
+
+ public Object getBody() {
+ return null;
+ }
+
+ public void setBody(Object body) {
+ if (body != null) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ public WorkContext getWorkContext() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setWorkContext(WorkContext workContext) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setTargetInvoker(TargetInvoker invoker) {
+ throw new UnsupportedOperationException();
+ }
+
+ public TargetInvoker getTargetInvoker() {
+ return null;
+ }
+
+ public Message getRelatedCallbackMessage() {
+ return null;
+ }
+
+ public URI getFromAddress() {
+ return null;
+ }
+
+ public void setFromAddress(URI fromAddress) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void pushCallbackUri(URI fromAddress) {
+ throw new UnsupportedOperationException();
+ }
+
+ public LinkedList<URI> getCallbackUris() {
+ return null;
+ }
+
+ public void setCallbackUris(LinkedList<URI> uris) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void pushCallbackWire(Wire wire) {
+
+ }
+
+ public LinkedList<Wire> getCallbackWires() {
+ return null;
+ }
+
+ public void setCallbackWires(LinkedList<Wire> 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 setBodyWithFault(Object fault) {
+ throw new UnsupportedOperationException();
+ }
+
+ public short getConversationSequence() {
+ return TargetInvoker.NONE;
+ }
+
+ public void setConversationSequence(short sequence) {
+
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptorBuilder.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptorBuilder.java
new file mode 100644
index 0000000000..8afcf8f6ad
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptorBuilder.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.core.wire;
+
+import javax.xml.namespace.QName;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.extension.InterceptorBuilderExtension;
+import org.apache.tuscany.spi.model.physical.PhysicalInterceptorDefinition;
+import org.apache.tuscany.spi.services.work.WorkScheduler;
+import org.apache.tuscany.spi.wire.Interceptor;
+
+/**
+ * Creates a non-blocking interceptor
+ *
+ * @version $Rev$ $Date$
+ */
+public class NonBlockingInterceptorBuilder extends InterceptorBuilderExtension {
+ public static final QName QNAME = new QName("http://tuscany.apache.org/xmlns/sca/system/2.0-alpha", "nonblocking");
+ private WorkContext workContext;
+ private WorkScheduler scheduler;
+
+ public NonBlockingInterceptorBuilder(@Reference(required = true)WorkContext workContext,
+ @Reference(required = true)WorkScheduler scheduler) {
+ this.workContext = workContext;
+ this.scheduler = scheduler;
+ }
+
+ public Interceptor build(PhysicalInterceptorDefinition definition) throws BuilderException {
+ return new NonBlockingInterceptor(scheduler, workContext);
+ }
+
+ protected QName getName() {
+ return QNAME;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptorGenerator.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptorGenerator.java
new file mode 100644
index 0000000000..3ee085b78f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/NonBlockingInterceptorGenerator.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.core.wire;
+
+import javax.xml.namespace.QName;
+
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.generator.GenerationException;
+import org.apache.tuscany.spi.generator.GeneratorContext;
+import org.apache.tuscany.spi.generator.GeneratorRegistry;
+import org.apache.tuscany.spi.generator.InterceptorGenerator;
+import org.apache.tuscany.spi.model.physical.PhysicalInterceptorDefinition;
+
+import org.apache.tuscany.core.model.NonBlockingIntentDefinition;
+
+/**
+ * Generates an interceptor definition for non-blocking operations
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+public class NonBlockingInterceptorGenerator implements InterceptorGenerator<NonBlockingIntentDefinition> {
+ public static final QName QNAME = new QName("http://tuscany.apache.org/xmlns/sca/system/2.0-alpha", "nonblocking");
+
+ public NonBlockingInterceptorGenerator(@Reference GeneratorRegistry registry) {
+ registry.register(NonBlockingIntentDefinition.class, this);
+ }
+
+ public PhysicalInterceptorDefinition generate(NonBlockingIntentDefinition definition,
+ GeneratorContext context) throws GenerationException {
+ return new PhysicalInterceptorDefinition(QNAME);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactory.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactory.java
new file mode 100644
index 0000000000..ab958234bd
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactory.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.core.wire;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * Returns a target instance directly from a wire
+ *
+ * @version $Rev$ $Date$
+ * @Deprecated
+ */
+public class OptimizedWireObjectFactory<B> implements ObjectFactory<B> {
+ private final Class<B> type;
+ private Wire wire;
+
+ public OptimizedWireObjectFactory(Class<B> type, Wire factory) {
+ this.wire = factory;
+ this.type = type;
+ }
+
+ public B getInstance() throws ObjectCreationException {
+ try {
+ return type.cast(wire.getTargetInstance());
+ } catch (TargetResolutionException e) {
+ throw new ObjectCreationException(e);
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/ProxyServiceExtension.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/ProxyServiceExtension.java
new file mode 100644
index 0000000000..7c8cf0db3a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/ProxyServiceExtension.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.core.wire;
+
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.IncompatibleServiceContractException;
+import org.apache.tuscany.spi.wire.ProxyService;
+
+/**
+ * Base class for wire service extensions
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class ProxyServiceExtension implements ProxyService {
+ protected WorkContext context;
+
+ protected ProxyServiceExtension(WorkContext context) {
+ this.context = context;
+ }
+
+ public boolean checkCompatibility(ServiceContract<?> source,
+ ServiceContract<?> target,
+ boolean ignoreCallback,
+ boolean silent)
+ throws IncompatibleServiceContractException {
+ if (source == target) {
+ // Shortcut for performance
+ return true;
+ }
+ if (source.isRemotable() != target.isRemotable()) {
+ if (!silent) {
+ throw new IncompatibleServiceContractException("Remotable settings do not match", source, target);
+ } else {
+ return false;
+ }
+ }
+ if (source.isConversational() != target.isConversational()) {
+ if (!silent) {
+ throw new IncompatibleServiceContractException("Interaction scopes do not match", source, target);
+ } else {
+ return false;
+ }
+ }
+
+ for (Operation<?> operation : source.getOperations().values()) {
+ Operation<?> targetOperation = target.getOperations().get(operation.getName());
+ if (targetOperation == null) {
+ if (!silent) {
+ throw new IncompatibleServiceContractException("Operation not found on target", source, target);
+ } else {
+ return false;
+ }
+ }
+ if (!operation.equals(targetOperation)) {
+ if (!silent) {
+ throw new IncompatibleServiceContractException("Target operations are not compatible", source,
+ target);
+ } else {
+ return false;
+ }
+ }
+ }
+
+ if (ignoreCallback) {
+ return true;
+ }
+
+ for (Operation<?> operation : source.getCallbackOperations().values()) {
+ Operation<?> targetOperation = target.getCallbackOperations().get(operation.getName());
+ if (targetOperation == null) {
+ if (!silent) {
+ throw new IncompatibleServiceContractException("Callback operation not found on target",
+ source,
+ target,
+ null,
+ targetOperation);
+ } else {
+ return false;
+ }
+ }
+ if (!operation.equals(targetOperation)) {
+ if (!silent) {
+ throw new IncompatibleServiceContractException("Target callback operation is not compatible",
+ source,
+ target,
+ operation,
+ targetOperation);
+ } else {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireImpl.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireImpl.java
new file mode 100644
index 0000000000..7f748a15db
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireImpl.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.core.wire;
+
+import java.net.URI;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * Default implementation of a Wire
+ *
+ * @version $Rev$ $Date$
+ */
+public class WireImpl implements Wire {
+ private URI sourceUri;
+ private URI targetUri;
+ private QName bindingType;
+ private ServiceContract sourceContract;
+ private ServiceContract targetContract;
+ private boolean optimizable;
+ private Map<Operation<?>, InvocationChain> chains = new HashMap<Operation<?>, InvocationChain>();
+ private Map<Operation<?>, InvocationChain> callbackChains = new HashMap<Operation<?>, InvocationChain>();
+ private Map<PhysicalOperationDefinition, InvocationChain> pChains =
+ new HashMap<PhysicalOperationDefinition, InvocationChain>();
+ private Map<PhysicalOperationDefinition, InvocationChain> pCallbackChains =
+ new HashMap<PhysicalOperationDefinition, InvocationChain>();
+ private AtomicComponent target;
+
+ /**
+ * Creates a wire with a local binding
+ */
+ public WireImpl() {
+ }
+
+ /**
+ * Creates a wire with the given binding type
+ *
+ * @param bindingType the binding type
+ */
+ public WireImpl(QName bindingType) {
+ this.bindingType = bindingType;
+ }
+
+ public URI getSourceUri() {
+ return sourceUri;
+ }
+
+ public void setSourceUri(URI sourceUri) {
+ this.sourceUri = sourceUri;
+ }
+
+ public URI getTargetUri() {
+ return targetUri;
+ }
+
+ public void setTargetUri(URI targetUri) {
+ this.targetUri = targetUri;
+ }
+
+ public QName getBindingType() {
+ return bindingType;
+ }
+
+
+ public ServiceContract getSourceContract() {
+ return sourceContract;
+ }
+
+ public void setSourceContract(ServiceContract contract) {
+ this.sourceContract = contract;
+ }
+
+
+ public ServiceContract getTargetContract() {
+ return targetContract;
+ }
+
+ public void setTargetContract(ServiceContract contract) {
+ this.targetContract = contract;
+ }
+
+ public boolean isOptimizable() {
+ return optimizable;
+ }
+
+ public void setOptimizable(boolean optimizable) {
+ this.optimizable = optimizable;
+ }
+
+ public Object getTargetInstance() throws TargetResolutionException {
+ if (target == null) {
+ return null;
+ }
+ return target.getTargetInstance();
+ }
+
+ public void setTarget(AtomicComponent target) {
+ this.target = target;
+ }
+
+ public Map<Operation<?>, InvocationChain> getInvocationChains() {
+ return Collections.unmodifiableMap(chains);
+ }
+
+ public void addInvocationChain(Operation<?> operation, InvocationChain chain) {
+ chains.put(operation, chain);
+ }
+
+ public void addInvocationChain(PhysicalOperationDefinition operation, InvocationChain chain) {
+ pChains.put(operation, chain);
+ }
+
+ public Map<PhysicalOperationDefinition, InvocationChain> getPhysicalInvocationChains() {
+ return Collections.unmodifiableMap(pChains);
+ }
+
+ public Map<Operation<?>, InvocationChain> getCallbackInvocationChains() {
+ return Collections.unmodifiableMap(callbackChains);
+ }
+
+ public void addCallbackInvocationChain(Operation<?> operation, InvocationChain chain) {
+ callbackChains.put(operation, chain);
+ }
+
+ public Map<PhysicalOperationDefinition, InvocationChain> getCallbackPhysicalInvocationChains() {
+ return Collections.unmodifiableMap(pCallbackChains);
+ }
+
+ public void addCallbackInvocationChain(PhysicalOperationDefinition operation, InvocationChain chain) {
+ pCallbackChains.put(operation, chain);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory.java
new file mode 100644
index 0000000000..3d14138d56
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory.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.core.wire;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.wire.ChainHolder;
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.ProxyService;
+
+/**
+ * Uses a wire to return an object instance
+ * @Deprecated
+ *
+ * @version $Rev$ $Date$
+ */
+public class WireObjectFactory<T> implements ObjectFactory<T> {
+ private Class<T> interfaze;
+ private Wire wire;
+ private ProxyService proxyService;
+ // the cache of proxy interface method to operation mappings
+ private Map<Method, ChainHolder> mappings;
+ 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<T> interfaze, Wire wire, ProxyService proxyService)
+ throws NoMethodForOperationException {
+ this.interfaze = interfaze;
+ this.wire = wire;
+ this.proxyService = proxyService;
+ this.mappings = WireUtils.createInterfaceToWireMapping(interfaze, wire);
+ if (wire.isOptimizable()
+ && wire.getSourceContract().getInterfaceClass() != null
+ && interfaze.isAssignableFrom(wire.getSourceContract().getInterfaceClass())) {
+ optimizable = true;
+ }
+ }
+
+ public T getInstance() throws ObjectCreationException {
+ if (optimizable) {
+ try {
+ return interfaze.cast(wire.getTargetInstance());
+ } catch (TargetResolutionException e) {
+ throw new ObjectCreationException(e);
+ }
+ } else {
+ // clone the cached mappings
+ Map<Method, ChainHolder> newChains = new HashMap<Method, ChainHolder>(mappings.size());
+ for (Map.Entry<Method, ChainHolder> entry : mappings.entrySet()) {
+ newChains.put(entry.getKey(), entry.getValue().clone());
+ }
+ return interfaze.cast(proxyService.createProxy(interfaze, wire, newChains));
+ }
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory2.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory2.java
new file mode 100644
index 0000000000..b5fab62d2f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireObjectFactory2.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.core.wire;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.ProxyService;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * Uses a wire to return an object instance
+ *
+ * @version $Rev$ $Date$
+ */
+public class WireObjectFactory2<T> implements ObjectFactory<T> {
+ private Class<T> interfaze;
+ private boolean conversational;
+ private Wire wire;
+ private ProxyService proxyService;
+ // the cache of proxy interface method to operation mappings
+ private Map<Method, InvocationChain> mappings;
+
+ /**
+ * Constructor.
+ *
+ * @param interfaze the interface to inject on the client
+ * @param conversational if the wire is conversational
+ * @param wire the backing wire
+ * @param proxyService the wire service to create the proxy
+ * @throws NoMethodForOperationException if a method matching the operation cannot be found
+ */
+ public WireObjectFactory2(Class<T> interfaze, boolean conversational, Wire wire, ProxyService proxyService)
+ throws NoMethodForOperationException {
+ this.interfaze = interfaze;
+ this.conversational = conversational;
+ this.wire = wire;
+ this.proxyService = proxyService;
+ this.mappings = WireUtils.createInterfaceToWireMapping2(interfaze, wire);
+ }
+
+ public T getInstance() throws ObjectCreationException {
+ return interfaze.cast(proxyService.createProxy2(interfaze, conversational, wire));
+ }
+}
+
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.java
new file mode 100644
index 0000000000..8b839dc8df
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/WireUtils.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.core.wire;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findMethod;
+import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findMethod2;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.wire.ChainHolder;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.ProxyCreationException;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * Utilities for operating on wires
+ *
+ * @version $Rev$ $Date$
+ */
+public final class WireUtils {
+
+ private WireUtils() {
+ }
+
+
+ /**
+ * Maps methods on an interface to operations on a wire
+ *
+ * @param interfaze the interface to map from
+ * @param wire the wire to map to
+ * @return a collection of method to operation mappings
+ * @throws NoMethodForOperationException
+ * @Deprecated
+ */
+ public static Map<Method, ChainHolder> createInterfaceToWireMapping(Class<?> interfaze, Wire wire)
+ throws NoMethodForOperationException {
+ Map<Operation<?>, InvocationChain> invocationChains = wire.getInvocationChains();
+
+ Map<Method, ChainHolder> chains = new HashMap<Method, ChainHolder>(invocationChains.size());
+ for (Map.Entry<Operation<?>, InvocationChain> entry : invocationChains.entrySet()) {
+ Operation operation = entry.getKey();
+ try {
+ Method method = findMethod(interfaze, operation);
+ chains.put(method, new ChainHolder(entry.getValue()));
+ } catch (NoSuchMethodException e) {
+ throw new NoMethodForOperationException(operation.getName());
+ }
+ }
+ return chains;
+ }
+
+ public static Map<Method, InvocationChain> createInterfaceToWireMapping2(Class<?> interfaze, Wire wire)
+ throws NoMethodForOperationException {
+ Map<PhysicalOperationDefinition, InvocationChain> invocationChains = wire.getPhysicalInvocationChains();
+
+ Map<Method, InvocationChain> chains = new HashMap<Method, InvocationChain>(invocationChains.size());
+ for (Map.Entry<PhysicalOperationDefinition, InvocationChain> entry : invocationChains.entrySet()) {
+ PhysicalOperationDefinition operation = entry.getKey();
+ try {
+ Method method = findMethod2(interfaze, operation);
+ chains.put(method, entry.getValue());
+ } catch (NoSuchMethodException e) {
+ throw new NoMethodForOperationException(operation.getName());
+ } catch (ClassNotFoundException e) {
+ throw new ProxyCreationException(e);
+ }
+ }
+ return chains;
+ }
+
+ /**
+ * Determines if the given wire is optimizable, i.e. its invocation chains may be bypassed during an invocation.
+ * This is typically calculated during the connect phase to optimize away invocation chains.
+ *
+ * @param wire the wire
+ * @return true if the wire is optimizable
+ */
+ public static boolean isOptimizable(Wire wire) {
+ for (InvocationChain chain : wire.getInvocationChains().values()) {
+ if (chain.getHeadInterceptor() != null) {
+ Interceptor current = chain.getHeadInterceptor();
+ if (current == null) {
+ break;
+ }
+ while (current != null) {
+ if (!current.isOptimizable()) {
+ return false;
+ }
+ current = current.getNext();
+ }
+ }
+ }
+ // if there is a callback, the wire is never optimizable since the callback target needs to be disambiguated
+ return wire.getCallbackInvocationChains().isEmpty();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.java
new file mode 100644
index 0000000000..f28231c7e3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler.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.core.wire.jdk;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.osoa.sca.NoRegisteredCallbackException;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ReactivationException;
+import org.apache.tuscany.spi.component.SCAExternalizable;
+import org.apache.tuscany.spi.component.WorkContext;
+import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findOperation;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.AbstractInvocationHandler;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+
+/**
+ * Responsible for dispatching to a callback through a wire.
+ * <p/>
+ * TODO cache target invoker
+ * @Deprecated
+ * @version $Rev$ $Date$
+ */
+public class JDKCallbackInvocationHandler extends AbstractInvocationHandler
+ implements InvocationHandler, Externalizable, SCAExternalizable {
+ private transient WorkContext context;
+ private transient Map<URI, Wire> wires;
+ private List<String> sourceWireNames;
+
+ /**
+ * Constructor used for deserialization only
+ */
+ public JDKCallbackInvocationHandler() {
+ sourceWireNames = new ArrayList<String>();
+ wires = new HashMap<URI, Wire>();
+ }
+
+ public JDKCallbackInvocationHandler(List<Wire> wireList, WorkContext context) {
+ this.context = context;
+ this.wires = new HashMap<URI, Wire>();
+ for (Wire wire : wireList) {
+ wires.put(wire.getSourceUri(), wire);
+ }
+ sourceWireNames = new ArrayList<String>();
+ for (URI uri : wires.keySet()) {
+ sourceWireNames.add(uri.getFragment());
+ }
+ }
+
+ @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
+ }
+ LinkedList<URI> callbackUris = context.getCallbackUris();
+ assert callbackUris != null;
+ URI targetAddress = callbackUris.getLast();
+ assert targetAddress != null;
+ Wire wire = wires.get(targetAddress);
+ assert wire != null;
+ Map<Operation<?>, InvocationChain> chains = wire.getCallbackInvocationChains();
+ Operation operation = findOperation(method, chains.keySet());
+ InvocationChain chain = chains.get(operation);
+ TargetInvoker invoker = chain.getTargetInvoker();
+ Object correlationId = context.getCorrelationId();
+ context.setCorrelationId(null);
+ try {
+ return invoke(chain, invoker, args, correlationId, callbackUris, context);
+ } catch (InvocationTargetException e) {
+ Throwable t = e.getCause();
+ if (t instanceof NoRegisteredCallbackException) {
+ throw t;
+ }
+ throw e;
+ }
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ int i = sourceWireNames.size() - 1;
+ out.writeInt(i);
+ for (String name : sourceWireNames) {
+ out.writeObject(name);
+ }
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ int num = in.readInt();
+ for (int i = 0; i <= num; i++) {
+ sourceWireNames.add((String) in.readObject());
+ }
+ }
+
+ public void setWorkContext(WorkContext context) {
+ this.context = context;
+ }
+
+ public void reactivate() throws ReactivationException {
+ AtomicComponent owner = context.getCurrentAtomicComponent();
+ if (owner == null) {
+ throw new ReactivationException("Current atomic component not set on work context");
+ }
+ for (String name : sourceWireNames) {
+ // TODO JFM support multiplicity, remove get(0)
+ Wire wire = owner.getWires(name).get(0);
+ wires.put(wire.getSourceUri(), wire);
+
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler2.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler2.java
new file mode 100644
index 0000000000..53c7444a03
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandler2.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.core.wire.jdk;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.LinkedList;
+import java.util.Map;
+
+import org.osoa.sca.NoRegisteredCallbackException;
+
+import org.apache.tuscany.spi.component.ReactivationException;
+import org.apache.tuscany.spi.component.SCAExternalizable;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.idl.java.JavaIDLUtils;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.wire.AbstractInvocationHandler;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * Responsible for dispatching to a callback through a wire.
+ * <p/>
+ * TODO cache target invoker
+ *
+ * @version $Rev$ $Date$
+ */
+public class JDKCallbackInvocationHandler2 extends AbstractInvocationHandler
+ implements InvocationHandler, Externalizable, SCAExternalizable {
+ private transient WorkContext context;
+
+ /**
+ * Constructor used for deserialization only
+ */
+ public JDKCallbackInvocationHandler2() {
+ }
+
+ public JDKCallbackInvocationHandler2(WorkContext context) {
+ this.context = context;
+ }
+
+ @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
+ }
+ LinkedList<Wire> wires = context.getCallbackWires();
+ Wire wire = wires.getLast();
+ assert wire != null;
+ Map<PhysicalOperationDefinition, InvocationChain> chains = wire.getCallbackPhysicalInvocationChains();
+ PhysicalOperationDefinition operation = JavaIDLUtils.findOperation2(method, chains.keySet());
+ InvocationChain chain = chains.get(operation);
+ Object correlationId = context.getCorrelationId();
+ context.setCorrelationId(null);
+ try {
+ return invokeTarget(chain, args, correlationId, wires);
+ } catch (InvocationTargetException e) {
+ Throwable t = e.getCause();
+ if (t instanceof NoRegisteredCallbackException) {
+ throw t;
+ }
+ throw e;
+ }
+ }
+
+
+ public Object invoke(Method method, Object[] args) throws Throwable {
+ return invoke(null, method, args);
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ // TODO re-implement
+// int i = sourceWireNames.size() - 1;
+// out.writeInt(i);
+// for (String name : sourceWireNames) {
+// out.writeObject(name);
+// }
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+// TODO re-implement
+// int num = in.readInt();
+// for (int i = 0; i <= num; i++) {
+// sourceWireNames.add((String) in.readObject());
+// }
+ }
+
+ public void setWorkContext(WorkContext context) {
+ this.context = context;
+ }
+
+ public void reactivate() throws ReactivationException {
+// AtomicComponent owner = context.getCurrentAtomicComponent();
+// if (owner == null) {
+// throw new ReactivationException("Current atomic component not set on work context");
+// }
+// for (String name : sourceWireNames) {
+// // TODO JFM support multiplicity, remove get(0)
+// Wire wire = owner.getWires(name).get(0);
+// wires.put(wire.getSourceUri(), wire);
+//
+// }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.java
new file mode 100644
index 0000000000..108b8ef0e7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler.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.core.wire.jdk;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ReactivationException;
+import org.apache.tuscany.spi.component.SCAExternalizable;
+import org.apache.tuscany.spi.component.TargetInvocationException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.AbstractInvocationHandler;
+import org.apache.tuscany.spi.wire.ChainHolder;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+import org.apache.tuscany.core.wire.NoMethodForOperationException;
+import org.apache.tuscany.core.wire.WireUtils;
+import org.apache.tuscany.core.implementation.PojoWorkContextTunnel;
+
+
+/**
+ * Dispatches to a target through a wire.
+ *
+ * @version $Rev$ $Date$
+ * @Deprecated
+ */
+public final class JDKInvocationHandler extends AbstractInvocationHandler
+ implements InvocationHandler, Externalizable, SCAExternalizable {
+ private static final long serialVersionUID = -6155278451964527325L;
+
+ // the wire this handler fronts
+ private transient Wire wire;
+ // the name of the source reference the wire is attached to, used during deserialization
+ private String referenceName;
+ // the interface the reference proxy implements
+ private Class<?> proxyInterface;
+ private transient WorkContext workContext;
+ // if the associated wire has a callback
+ private transient boolean callback;
+ // if the associated wire is conversational
+ private transient boolean conversational;
+ /*
+ * an association of an operation to chain holder. The holder contains an invocation chain
+ * and a local clone of the master TargetInvoker. TargetInvokers will be cloned by the handler and placed in the
+ * holder if they are cacheable. This allows optimizations such as avoiding target resolution when a source refers
+ * to a target of greater scope since the target reference can be maintained by the invoker. When a target invoker
+ * is not cacheable, the master associated with the wire chains will be used.
+ */
+ private transient Map<Method, ChainHolder> chains;
+
+ /**
+ * Constructor used for deserialization only
+ */
+ public JDKInvocationHandler() {
+ }
+
+ public JDKInvocationHandler(Class<?> interfaze, Wire wire, WorkContext workContext)
+ throws NoMethodForOperationException {
+ this.workContext = workContext;
+ this.proxyInterface = interfaze;
+ this.wire = wire;
+ init(interfaze, wire, null);
+ }
+
+ public JDKInvocationHandler(Class<?> interfaze,
+ Wire wire,
+ Map<Method, ChainHolder> mapping,
+ WorkContext workContext)
+ throws NoMethodForOperationException {
+ super(false);
+ this.workContext = workContext;
+ this.proxyInterface = interfaze;
+ init(interfaze, wire, mapping);
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ ChainHolder holder = chains.get(method);
+ if (holder == null) {
+ 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
+ }
+ throw new TargetInvocationException("Operation not configured", method.getName());
+ }
+ TargetInvoker invoker = getInvoker(holder);
+ InvocationChain chain = holder.getChain();
+ WorkContext workContext = PojoWorkContextTunnel.getThreadWorkContext();
+
+// JFM commonting out temporarily
+// if (wireContainerIsAtomicComponent && contractHasCallback && !callbackIsImplemented) {
+// throw new NoRegisteredCallbackException("Instance is does not implement callback: "
+// + callbackClassName);
+// }
+
+ if (conversational) {
+ Object id = workContext.getIdentifier(Scope.CONVERSATION);
+ if (id == null) {
+ String convIdFromThread = createConversationID();
+ workContext.setIdentifier(Scope.CONVERSATION, convIdFromThread);
+ }
+ }
+ LinkedList<URI> list = null;
+ if (callback) {
+ // set up callback address
+ list = workContext.getCallbackUris();
+ if (list == null) {
+ list = new LinkedList<URI>();
+ workContext.setCallbackUris(list);
+ }
+ list.add(wire.getSourceUri());
+ }
+ // send the invocation down the wire
+ Object result = invoke(chain, invoker, args, null, list, workContext);
+
+ if (callback) {
+ list = workContext.getCallbackUris();
+ if (list != null) {
+ // pop last address
+ list.removeLast();
+ }
+ }
+ return result;
+ }
+
+ public Object invoke(Method method, Object[] args) throws Throwable {
+ return invoke(null, method, args);
+ }
+
+ public void setWorkContext(WorkContext context) {
+ workContext = context;
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(referenceName);
+ out.writeObject(proxyInterface);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ referenceName = (String) in.readObject();
+ proxyInterface = (Class<?>) in.readObject();
+ }
+
+ public void reactivate() throws ReactivationException {
+ AtomicComponent owner = workContext.getCurrentAtomicComponent();
+ if (owner == null) {
+ throw new ReactivationException("Current atomic component not set on work context");
+ }
+ List<Wire> wires = owner.getWires(referenceName);
+ if (wires == null) {
+ throw new ReactivationException("Reference wire not found", referenceName, owner.getUri().toString());
+ }
+ // TODO handle multiplicity
+ Wire wire = wires.get(0);
+ try {
+ init(proxyInterface, wire, null);
+ } catch (NoMethodForOperationException e) {
+ throw new ReactivationException(e);
+ }
+ }
+
+ /**
+ * Reinitializes the proxy handler
+ *
+ * @param interfaze the interface the proxy implements
+ * @param wire the wire fronted by the proxy
+ * @param mapping a mapping from proxy interface methods to invocation chain holders
+ * @throws NoMethodForOperationException
+ */
+ private void init(Class<?> interfaze, Wire wire, Map<Method, ChainHolder> mapping)
+ throws NoMethodForOperationException {
+ ServiceContract contract = wire.getSourceContract();
+ this.referenceName = wire.getSourceUri().getFragment();
+ this.conversational = contract.isConversational();
+ this.callback = contract.getCallbackClass() != null;
+ // FIXME JFM this should not be dependent on PojoAtomicComponent
+ // JFM commenting out as this should not be specific to pojo types
+// this.wireContainerIsAtomicComponent = scaObject instanceof PojoAtomicComponent;
+// if (wireContainerIsAtomicComponent && contractHasCallback) {
+// this.callbackIsImplemented =
+// ((PojoAtomicComponent) scaObject).implementsCallback(contract.getCallbackClass());
+// } else {
+// this.callbackIsImplemented = false;
+// }
+ if (mapping == null) {
+ chains = WireUtils.createInterfaceToWireMapping(interfaze, wire);
+ } else {
+ chains = mapping;
+ }
+ }
+
+ /**
+ * Returns the cached or a new target invoker to associate with the invocation
+ *
+ * @param holder the chain holder
+ * @return the target invoker
+ * @throws TargetInvocationException
+ * @throws CloneNotSupportedException
+ */
+ private TargetInvoker getInvoker(ChainHolder holder) throws TargetInvocationException, CloneNotSupportedException {
+ InvocationChain chain = holder.getChain();
+ if (holder.getCachedInvoker() == null) {
+ assert chain != null;
+ if (chain.getTargetInvoker() == null) {
+ String name = chain.getOperation().getName();
+ throw new TargetInvocationException("No target invoker configured for operation", name);
+ }
+ if (chain.getTargetInvoker().isCacheable()) {
+ // clone and store the invoker locally
+ holder.setCachedInvoker((TargetInvoker) chain.getTargetInvoker().clone());
+ return holder.getCachedInvoker();
+ } else {
+ return chain.getTargetInvoker();
+ }
+ } else {
+ assert chain != null;
+ return chain.getTargetInvoker();
+ }
+ }
+
+ /**
+ * Creates a new conversational id
+ *
+ * @return the conversational id
+ */
+ private String createConversationID() {
+ return UUID.randomUUID().toString();
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler2.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler2.java
new file mode 100644
index 0000000000..6ac60e0480
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandler2.java
@@ -0,0 +1,187 @@
+package org.apache.tuscany.core.wire.jdk;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ReactivationException;
+import org.apache.tuscany.spi.component.SCAExternalizable;
+import org.apache.tuscany.spi.component.TargetInvocationException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.wire.AbstractInvocationHandler;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+
+import org.apache.tuscany.core.wire.NoMethodForOperationException;
+import org.apache.tuscany.core.wire.WireUtils;
+
+/**
+ * Dispatches to a target through a wire.
+ *
+ * @version $Rev$ $Date$
+ */
+public final class JDKInvocationHandler2 extends AbstractInvocationHandler
+ implements InvocationHandler, Externalizable, SCAExternalizable {
+ private static final long serialVersionUID = -6155278451964527325L;
+
+ // the wire this handler fronts
+ private transient Wire wire;
+ // the name of the source reference the wire is attached to, used during deserialization
+ private String referenceName;
+ // the interface the reference proxy implements
+ private Class<?> proxyInterface;
+ private transient WorkContext workContext;
+ // if the associated wire has a callback
+ private transient boolean callback;
+ // if the associated wire is conversational
+ private boolean conversational;
+ private transient Map<Method, InvocationChain> chains;
+
+ /**
+ * Constructor used for deserialization only
+ */
+ public JDKInvocationHandler2() {
+ }
+
+ public JDKInvocationHandler2(Class<?> interfaze, boolean conversational, Wire wire, WorkContext workContext)
+ throws NoMethodForOperationException {
+ super(conversational);
+ this.workContext = workContext;
+ this.proxyInterface = interfaze;
+ this.wire = wire;
+ this.conversational = conversational;
+ init(interfaze, wire, null);
+ }
+
+ public JDKInvocationHandler2(Class<?> interfaze,
+ Wire wire,
+ Map<Method, InvocationChain> mapping,
+ WorkContext workContext)
+ throws NoMethodForOperationException {
+ this.workContext = workContext;
+ this.proxyInterface = interfaze;
+ init(interfaze, wire, mapping);
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ InvocationChain chain = chains.get(method);
+ if (chain == null) {
+ 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
+ }
+ throw new TargetInvocationException("Operation not configured", method.getName());
+ }
+
+ if (conversational) {
+ Object id = workContext.getIdentifier(Scope.CONVERSATION);
+ if (id == null) {
+ String convIdFromThread = createConversationID();
+ workContext.setIdentifier(Scope.CONVERSATION, convIdFromThread);
+ }
+ }
+ LinkedList<Wire> list = null;
+ if (callback) {
+ // set up callback address
+ list = workContext.getCallbackWires();
+ if (list == null) {
+ list = new LinkedList<Wire>();
+ workContext.setCallbackWires(list);
+ }
+ list.add(wire);
+ }
+ // send the invocation down the wire
+ Object result = invokeTarget(chain, args, null, list);
+
+ if (callback) {
+ list = workContext.getCallbackWires();
+ if (list != null) {
+ // pop last address
+ list.removeLast();
+ }
+ }
+ return result;
+ }
+
+ public Object invoke(Method method, Object[] args) throws Throwable {
+ return invoke(null, method, args);
+ }
+
+ public void setWorkContext(WorkContext context) {
+ workContext = context;
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(referenceName);
+ out.writeObject(proxyInterface);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ referenceName = (String) in.readObject();
+ proxyInterface = (Class<?>) in.readObject();
+ }
+
+ public void reactivate() throws ReactivationException {
+ AtomicComponent owner = workContext.getCurrentAtomicComponent();
+ if (owner == null) {
+ throw new ReactivationException("Current atomic component not set on work context");
+ }
+ List<Wire> wires = owner.getWires(referenceName);
+ if (wires == null) {
+ throw new ReactivationException("Reference wire not found", referenceName, owner.getUri().toString());
+ }
+ // TODO handle multiplicity
+ Wire wire = wires.get(0);
+ try {
+ init(proxyInterface, wire, null);
+ } catch (NoMethodForOperationException e) {
+ throw new ReactivationException(e);
+ }
+ }
+
+ /**
+ * Reinitializes the proxy handler
+ *
+ * @param interfaze the interface the proxy implements
+ * @param wire the wire fronted by the proxy
+ * @param mapping a mapping from proxy interface methods to invocation chain holders
+ * @throws org.apache.tuscany.core.wire.NoMethodForOperationException
+ *
+ */
+ private void init(Class<?> interfaze, Wire wire, Map<Method, InvocationChain> mapping)
+ throws NoMethodForOperationException {
+ this.referenceName = wire.getSourceUri().getFragment();
+ this.callback = !wire.getPhysicalInvocationChains().isEmpty();
+ if (mapping == null) {
+ chains = WireUtils.createInterfaceToWireMapping2(interfaze, wire);
+ } else {
+ chains = mapping;
+ }
+ }
+
+ /**
+ * Creates a new conversational id
+ *
+ * @return the conversational id
+ */
+ private String createConversationID() {
+ return UUID.randomUUID().toString();
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKProxyService.java b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKProxyService.java
new file mode 100644
index 0000000000..189ea7a416
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/java/org/apache/tuscany/core/wire/jdk/JDKProxyService.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.core.wire.jdk;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.List;
+import java.util.Map;
+
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.wire.ChainHolder;
+import org.apache.tuscany.spi.wire.ProxyCreationException;
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.InvocationChain;
+
+import org.apache.tuscany.core.wire.ProxyServiceExtension;
+
+/**
+ * the default implementation of a wire service that uses JDK dynamic proxies
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+@EagerInit
+public class JDKProxyService extends ProxyServiceExtension {
+
+ public JDKProxyService() {
+ super(null);
+ }
+
+ @Constructor
+ public JDKProxyService(@Reference WorkContext context) {
+ super(context);
+ }
+
+ public <T> T createProxy(Class<T> interfaze, Wire wire) throws ProxyCreationException {
+ assert interfaze != null;
+ assert wire != null;
+ JDKInvocationHandler handler = new JDKInvocationHandler(interfaze, wire, context);
+ ClassLoader cl = interfaze.getClassLoader();
+ return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
+ }
+
+ public <T> T createProxy2(Class<T> interfaze, boolean conversational, Wire wire) throws ProxyCreationException {
+ assert interfaze != null;
+ assert wire != null;
+ JDKInvocationHandler2 handler = new JDKInvocationHandler2(interfaze, conversational, wire, context);
+ ClassLoader cl = interfaze.getClassLoader();
+ return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
+ }
+
+ public <T> T createProxy(Class<T> interfaze, Wire wire, Map<Method, ChainHolder> mapping)
+ throws ProxyCreationException {
+ assert interfaze != null;
+ assert wire != null;
+ assert mapping != null;
+ JDKInvocationHandler handler = new JDKInvocationHandler(interfaze, wire, context);
+ ClassLoader cl = interfaze.getClassLoader();
+ return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
+ }
+
+ public Object createCallbackProxy(Class<?> interfaze, List<Wire> wires) throws ProxyCreationException {
+ ClassLoader cl = interfaze.getClassLoader();
+ JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(wires, context);
+ return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
+ }
+
+ public Object createCallbackProxy(Class<?> interfaze) throws ProxyCreationException {
+ ClassLoader cl = interfaze.getClassLoader();
+ JDKCallbackInvocationHandler2 handler = new JDKCallbackInvocationHandler2(context);
+ return interfaze.cast(Proxy.newProxyInstance(cl, new Class[]{interfaze}, handler));
+ }
+
+ public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+ 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/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/composite.scdl b/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/composite.scdl
new file mode 100644
index 0000000000..8cdf0ac2a8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/composite.scdl
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<!--
+ Default system configuration for the launcher environment.
+
+ $Rev$ $Date$
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ name="org.apache.tuscany.core.Composite"
+ autowire="true">
+
+ <!-- Composite implementation type -->
+ <component name="composite.loader">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.composite.CompositeLoader"/>
+ </component>
+ <component name="composite.implementationLoader">
+ <system:implementation.system
+ class="org.apache.tuscany.core.implementation.composite.ImplementationCompositeLoader"/>
+ </component>
+ <component name="composite.dependencyLoader">
+ <system:implementation.system class="org.apache.tuscany.core.loader.DependencyLoader"/>
+ </component>
+ <component name="composite.componentTypeLoader">
+ <system:implementation.system
+ class="org.apache.tuscany.core.implementation.composite.CompositeComponentTypeLoader"/>
+ </component>
+ <component name="composite.builder">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.composite.CompositeBuilder"/>
+ </component>
+</composite>
diff --git a/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/databinding.scdl b/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/databinding.scdl
new file mode 100644
index 0000000000..c50422c34d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/databinding.scdl
@@ -0,0 +1,165 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ name="org.apache.tuscany.core.DataBinding"
+ autowire="true">
+
+ <component name="databinding.wirePostProcessor">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.impl.DataBindingWirePostProcessor"/>
+ </component>
+
+ <component name="databinding.javaInterfaceProcessor">
+ <system:implementation.system
+ class="org.apache.tuscany.core.databinding.impl.DataBindingJavaInterfaceProcessor"/>
+ </component>
+
+ <component name="databinding.passByValueWirePostProcessor">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.impl.PassByValueWirePostProcessor"/>
+ </component>
+
+ <!-- DataBinding registry -->
+ <component name="databinding.registry">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.impl.DataBindingRegistryImpl"/>
+ </component>
+
+ <!-- DataBinding registry -->
+ <component name="databinding.mediator">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.impl.MediatorImpl"/>
+ </component>
+
+ <!-- Transformer registry -->
+ <component name="databinding.transformerRegistry" initLevel="90">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.impl.TransformerRegistryImpl"/>
+ </component>
+
+ <component name="dataType.loader">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.impl.DataTypeLoader"/>
+ </component>
+
+ <!-- Simple databindings -->
+ <component name="databinding.dom">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.impl.SimpleDataBinding"/>
+ <property name="className">org.w3c.dom.Node</property>
+ </component>
+
+ <component name="databinding.javabeans">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.javabeans.JavaBeansDataBinding"/>
+ </component>
+
+ <!-- Transformers -->
+
+ <component name="transformer.Input2InputTransformer">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.impl.Input2InputTransformer"/>
+ </component>
+
+ <component name="transformer.Output2OutputTransformer">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.impl.Output2OutputTransformer"/>
+ </component>
+
+ <component name="transformer.InputSource2Node">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.xml.InputSource2Node"/>
+ </component>
+
+ <component name="transformer.InputSource2SAX">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.xml.InputSource2SAX"/>
+ </component>
+
+ <component name="transformer.InputStream2Node">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.xml.InputStream2Node"/>
+ </component>
+
+ <component name="transformer.InputStream2SAX">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.xml.InputStream2SAX"/>
+ </component>
+
+ <component name="transformer.DOMNode2JavaBean">
+ <system:implementation.system
+ class="org.apache.tuscany.core.databinding.javabeans.DOMNode2JavaBeanTransformer"/>
+ </component>
+
+ <component name="transformer.Node2OutputStream">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.xml.Node2OutputStream"/>
+ </component>
+
+ <component name="transformer.Node2String">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.xml.Node2String"/>
+ </component>
+
+ <component name="transformer.Node2Writer">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.xml.Node2Writer"/>
+ </component>
+
+ <component name="transformer.Node2XMLStreamReader">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.xml.Node2XMLStreamReader"/>
+ </component>
+
+ <component name="transformer.JavaBean2DOMNode">
+ <system:implementation.system
+ class="org.apache.tuscany.core.databinding.javabeans.JavaBean2DOMNodeTransformer"/>
+ </component>
+
+ <component name="transformer.Reader2Node">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.xml.Reader2Node"/>
+ </component>
+
+ <component name="transformer.Reader2SAX">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.xml.Reader2SAX"/>
+ </component>
+
+ <component name="transformer.SAX2DOMPipe">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.xml.SAX2DOMPipe"/>
+ </component>
+
+ <component name="transformer.Source2ResultTransformer">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.xml.Source2ResultTransformer"/>
+ </component>
+
+ <component name="transformer.StreamDataPipe">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.xml.StreamDataPipe"/>
+ </component>
+
+ <component name="transformer.String2Node">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.xml.String2Node"/>
+ </component>
+
+ <component name="transformer.String2SAX">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.xml.String2SAX"/>
+ </component>
+
+ <component name="transformer.String2XMLStreamReader">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.xml.String2XMLStreamReader"/>
+ </component>
+
+ <component name="transformer.Writer2ReaderDataPipe">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.xml.Writer2ReaderDataPipe"/>
+ </component>
+
+ <component name="transformer.XMLStreamReader2Node">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.xml.XMLStreamReader2Node"/>
+ </component>
+
+ <component name="transformer.XMLStreamReader2SAX">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.xml.XMLStreamReader2SAX"/>
+ </component>
+
+ <component name="transformer.XMLStreamReader2String">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.xml.XMLStreamReader2String"/>
+ </component>
+</composite> \ No newline at end of file
diff --git a/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/deployment.scdl b/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/deployment.scdl
new file mode 100644
index 0000000000..804bd0bead
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/deployment.scdl
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<!--
+ Deployment-related system components
+
+ $Rev$ $Date$
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ name="org.apache.tuscany.core.Deployment"
+ autowire="true">
+
+ <!-- Contribution Service -->
+ <component name="contributionDirectoryWatcher" initLevel="100">
+ <system:implementation.system class="org.apache.tuscany.core.services.deployment.ContributionDirectoryWatcher"/>
+ <property name="path">target/deployables</property>
+ </component>
+ <component name="contributionService" initLevel="90">
+ <system:implementation.system class="org.apache.tuscany.core.services.deployment.ContributionServiceImpl"/>
+ </component>
+ <component name="contributionRepository" initLevel="40">
+ <system:implementation.system class="org.apache.tuscany.core.services.deployment.ContributionRepositoryImpl"/>
+ <property name="repository">target/repository</property>
+ </component>
+
+ <component name="contributionProcessorRegistry" initLevel="35">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.deployment.ContributionProcessorRegistryImpl"/>
+ </component>
+ <component name="contentTypeDescriber" initLevel="30">
+ <system:implementation.system class="org.apache.tuscany.core.services.deployment.ContentTypeDescriberImpl"/>
+ </component>
+ <component name="JarContributionProcessor" initLevel="30">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.deployment.contribution.JarContributionProcessor"/>
+ </component>
+ <component name="JavaContributionProcessor" initLevel="30">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.deployment.contribution.JavaContributionProcessor"/>
+ </component>
+ <component name="ScdlContributionProcessor" initLevel="30">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.deployment.contribution.ScdlContributionProcessor"/>
+ </component>
+
+</composite>
diff --git a/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/formatters.scdl b/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/formatters.scdl
new file mode 100644
index 0000000000..5d2c0db012
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/formatters.scdl
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<!--
+ Formatter configurations for JDK logging.
+
+ $Rev: 476250 $ $Date: 2006-11-17 10:56:22 -0800 (Fri, 17 Nov 2006) $
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ name="org.apache.tuscany.core.Formatters"
+ autowire="true">
+
+ <component name="LoaderExceptionFormatter">
+ <system:implementation.system class="org.apache.tuscany.core.loader.LoaderExceptionFormatter"/>
+ </component>
+
+ <component name="IncompatibleServiceContractExceptionFormatter">
+ <system:implementation.system
+ class="org.apache.tuscany.core.wire.IncompatibleServiceContractExceptionFormatter"/>
+ </component>
+
+ <component name="WireExceptionExceptionFormatter">
+ <system:implementation.system
+ class="org.apache.tuscany.core.builder.WiringExceptionFormatter"/>
+ </component>
+
+</composite>
diff --git a/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/implementation.scdl b/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/implementation.scdl
new file mode 100644
index 0000000000..c81115aafa
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/implementation.scdl
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<!--
+ Default system configuration for the launcher environment.
+
+ $Rev$ $Date$
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ name="org.apache.tuscany.core.Implementation"
+ autowire="true">
+
+ <!-- Foundation implementation processors -->
+ <component name="implementation.ImplementationProcessorService">
+ <system:implementation.system
+ class="org.apache.tuscany.core.implementation.processor.ImplementationProcessorServiceImpl"/>
+ </component>
+ <component name="implementation.Constructor">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.processor.ConstructorProcessor"/>
+ </component>
+ <component name="implementation.Destroy">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.processor.DestroyProcessor"/>
+ </component>
+ <component name="implementation.Init">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.processor.InitProcessor"/>
+ </component>
+ <component name="implementation.EagerInit">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.processor.EagerInitProcessor"/>
+ </component>
+ <component name="implementation.Scope">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.processor.ScopeProcessor"/>
+ </component>
+ <component name="implementation.AllowsPassByReference">
+ <system:implementation.system
+ class="org.apache.tuscany.core.implementation.processor.AllowsPassByReferenceProcessor"/>
+ </component>
+ <component name="implementation.Property">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.processor.PropertyProcessor"/>
+ </component>
+ <component name="implementation.Reference">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.processor.ReferenceProcessor"/>
+ </component>
+ <component name="implementation.Service">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.processor.ServiceProcessor"/>
+ </component>
+ <component name="implementation.HeuristicPojo">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.processor.HeuristicPojoProcessor"/>
+ </component>
+ <component name="implementation.Monitor">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.processor.MonitorProcessor"/>
+ </component>
+ <component name="implementation.Resource">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.processor.ResourceProcessor"/>
+ </component>
+ <component name="implementation.Conversation">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.processor.ConversationProcessor"/>
+ </component>
+ <component name="implementation.ContextProcessor">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.processor.ContextProcessor"/>
+ </component>
+
+</composite>
diff --git a/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/interfaceJava.scdl b/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/interfaceJava.scdl
new file mode 100644
index 0000000000..b0664dc67a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/interfaceJava.scdl
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<!--
+ Configuration for Java IDL support.
+
+ $Rev$ $Date$
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ name="org.apache.tuscany.core.InterfaceJava"
+ autowire="true">
+
+ <component name="interfaceJava.interfaceProcessorRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl"/>
+ </component>
+ <component name="interfaceJava.loader">
+ <system:implementation.system class="org.apache.tuscany.core.idl.java.InterfaceJavaLoader"/>
+ </component>
+</composite>
diff --git a/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/javaImplementation.scdl b/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/javaImplementation.scdl
new file mode 100644
index 0000000000..69110ec05c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/javaImplementation.scdl
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<!--
+ Default system configuration for the launcher environment.
+
+ $Rev$ $Date$
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ name="org.apache.tuscany.core.JavaImplementation"
+ autowire="true">
+
+ <!-- Java implementation type -->
+ <component name="java.implementationLoader">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.java.JavaImplementationLoader"/>
+ </component>
+ <component name="java.componentTypeLoader">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.java.JavaComponentTypeLoader"/>
+ </component>
+ <component name="java.componentBuilder">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.java.JavaComponentBuilder"/>
+ </component>
+</composite>
diff --git a/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/loader.scdl b/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/loader.scdl
new file mode 100644
index 0000000000..b22f5d05f1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/loader.scdl
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<!--
+ Default loader configuration for the launcher environment.
+
+ $Rev$ $Date$
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ name="org.apache.tuscany.core.Loader"
+ autowire="true">
+
+ <!-- Foundation element loader implementations -->
+ <component name="elementLoader.component">
+ <system:implementation.system class="org.apache.tuscany.core.loader.ComponentLoader"/>
+ </component>
+ <component name="elementLoader.componentType">
+ <system:implementation.system class="org.apache.tuscany.core.loader.ComponentTypeElementLoader"/>
+ </component>
+ <component name="elementLoader.include">
+ <system:implementation.system class="org.apache.tuscany.core.loader.IncludeLoader"/>
+ </component>
+ <component name="elementLoader.property">
+ <system:implementation.system class="org.apache.tuscany.core.loader.PropertyLoader"/>
+ </component>
+ <component name="elementLoader.reference">
+ <system:implementation.system class="org.apache.tuscany.core.loader.ReferenceLoader"/>
+ </component>
+ <component name="elementLoader.service">
+ <system:implementation.system class="org.apache.tuscany.core.loader.ServiceLoader"/>
+ </component>
+ <component name="elementLoader.wire">
+ <system:implementation.system class="org.apache.tuscany.core.loader.WireLoader"/>
+ </component>
+
+</composite>
diff --git a/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/systemImplementation.scdl b/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/systemImplementation.scdl
new file mode 100644
index 0000000000..9a4178118f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/main/resources/org/apache/tuscany/core/systemImplementation.scdl
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<!--
+ Default system configuration for the launcher environment.
+
+ $Rev$ $Date$
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ name="org.apache.tuscany.core.SystemImplementation"
+ autowire="true">
+
+ <!-- System implementation type -->
+ <component name="system.componentTypeLoader">
+ <system:implementation.system
+ class="org.apache.tuscany.core.implementation.system.loader.SystemComponentTypeLoader"/>
+ </component>
+
+ <component name="system.compositeComponentTypeLoader">
+ <system:implementation.system
+ class="org.apache.tuscany.core.implementation.system.loader.SystemCompositeComponentTypeLoader"/>
+ </component>
+ <component name="system.implementationLoader">
+ <system:implementation.system
+ class="org.apache.tuscany.core.implementation.system.loader.SystemImplementationLoader"/>
+ </component>
+ <component name="system.componentBuilder">
+ <system:implementation.system
+ class="org.apache.tuscany.core.implementation.system.builder.SystemComponentBuilder"/>
+ </component>
+ <component name="system.compositeBuilder">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.composite.SystemCompositeBuilder"/>
+ </component>
+</composite>
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvokerTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvokerTestCase.java
new file mode 100644
index 0000000000..dfda132671
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvokerTestCase.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.core.binding.local;
+
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.mock.wire.MockTargetInvoker;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AbstractLocalTargetInvokerTestCase extends TestCase {
+
+ public void testInvokerWithInterceptor() throws Throwable {
+ AbstractLocalTargetInvoker invoker = new MockTargetInvoker();
+ Interceptor interceptor = EasyMock.createMock(Interceptor.class);
+ interceptor.invoke(EasyMock.isA(Message.class));
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ Message msg = (Message) EasyMock.getCurrentArguments()[0];
+ if (msg.getTargetInvoker() == null) {
+ fail("Target invoker not set");
+ }
+ return null;
+ }
+ });
+ EasyMock.replay(interceptor);
+ InvocationChain chain = EasyMock.createMock(InvocationChain.class);
+ EasyMock.expect(chain.getHeadInterceptor()).andReturn(interceptor);
+ EasyMock.replay(chain);
+ invoker.invoke(chain, EasyMock.createNiceMock(TargetInvoker.class), new MessageImpl());
+ EasyMock.verify(chain);
+ EasyMock.verify(interceptor);
+ }
+
+ public void testShortCircuitInvoke() throws Throwable {
+ AbstractLocalTargetInvoker invoker = new MockTargetInvoker();
+ TargetInvoker targetInvoker = EasyMock.createMock(TargetInvoker.class);
+ EasyMock.expect(targetInvoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl());
+ EasyMock.replay(targetInvoker);
+ InvocationChain chain = EasyMock.createMock(InvocationChain.class);
+ EasyMock.expect(chain.getHeadInterceptor()).andReturn(null);
+ EasyMock.replay(chain);
+ invoker.invoke(chain, targetInvoker, new MessageImpl());
+ EasyMock.verify(chain);
+ EasyMock.verify(targetInvoker);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingBuilderTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingBuilderTestCase.java
new file mode 100644
index 0000000000..e628df47e2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingBuilderTestCase.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.core.binding.local;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LocalBindingBuilderTestCase extends TestCase {
+
+ public void testBuild() throws Exception {
+ LocalBindingBuilder builder = new LocalBindingBuilder();
+ ServiceDefinition def = new ServiceDefinition();
+ def.setUri(new URI("#foo"));
+ ServiceBinding binding = builder.build(def, null, null);
+ assertEquals(LocalServiceBinding.class, binding.getClass());
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java
new file mode 100644
index 0000000000..0c35ae9a09
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.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.core.binding.local;
+
+import java.net.URI;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.loader.LoaderException;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LocalBindingLoaderTestCase extends TestCase {
+ private LocalBindingLoader loader;
+
+ public void testParse() throws Exception {
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "uri")).andReturn("foo");
+ EasyMock.replay(reader);
+ LocalBindingDefinition definition = loader.load(null, reader, null);
+ assertEquals(new URI("foo"), definition.getTargetUri());
+ EasyMock.verify(reader);
+ }
+
+ public void testNoUri() throws Exception {
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "uri")).andReturn(null);
+ EasyMock.replay(reader);
+ LocalBindingDefinition definition = loader.load(null, reader, null);
+ assertNull(definition.getTargetUri());
+ EasyMock.verify(reader);
+ }
+
+ public void testBadUri() throws Exception {
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "uri")).andReturn("foo foo");
+ EasyMock.replay(reader);
+ try {
+ loader.load(null, reader, null);
+ fail();
+ } catch (LoaderException e) {
+ // expected
+ }
+ EasyMock.verify(reader);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ loader = new LocalBindingLoader(null);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerInvocationExceptionTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerInvocationExceptionTestCase.java
new file mode 100644
index 0000000000..9b83d95918
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerInvocationExceptionTestCase.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.binding.local;
+
+import java.lang.reflect.Type;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.wire.InvocationChainImpl;
+import org.apache.tuscany.core.wire.WireImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LocalCallbackTargetInvokerInvocationExceptionTestCase extends TestCase {
+
+ /**
+ * Verfies an InvocationTargetException thrown when invoking the target is propagated to the client correctly and
+ * the originating error is unwrapped
+ */
+ public void testThrowableTargetInvocation() throws Exception {
+ Operation<Type> operation = new Operation<Type>("echo", null, null, null);
+ Interceptor head = new ErrorInterceptor();
+ InvocationChain chain = new InvocationChainImpl(operation);
+ chain.addInterceptor(head);
+ Wire wire = new WireImpl();
+ wire.addCallbackInvocationChain(operation, chain);
+ LocalCallbackTargetInvoker invoker = new LocalCallbackTargetInvoker(operation, wire);
+ Message msg = new MessageImpl();
+ msg.setBody("foo");
+ Message response = invoker.invoke(msg);
+ assertTrue(response.isFault());
+ Object body = response.getBody();
+ assertTrue(SomeException.class.equals(body.getClass()));
+ }
+
+ private class SomeException extends Exception {
+
+ }
+
+ private class ErrorInterceptor implements Interceptor {
+
+ public Message invoke(Message msg) {
+ msg.setBodyWithFault(new SomeException());
+ return msg;
+ }
+
+ public void setNext(Interceptor next) {
+
+ }
+
+ public Interceptor getNext() {
+ return null;
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerTestCase.java
new file mode 100644
index 0000000000..d922ec8033
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerTestCase.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.binding.local;
+
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LocalCallbackTargetInvokerTestCase extends TestCase {
+ private Wire wire;
+ private Message message;
+ private InvocationChain chain;
+ private Interceptor head;
+ private LocalCallbackTargetInvoker invoker;
+
+ /**
+ * Verfies the normal execution path through a callback
+ */
+ public void testNormalPathMessageInvocation() throws Exception {
+ Message response = invoker.invoke(message);
+ assertEquals("response", response.getBody());
+ EasyMock.verify(wire);
+ EasyMock.verify(chain);
+ EasyMock.verify(head);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ URI targetAddress = URI.create("from");
+ message = new MessageImpl();
+ message.pushCallbackUri(targetAddress);
+ message.setBody("foo");
+ Message response = new MessageImpl();
+ response.setBody("response");
+ Operation<Type> operation = new Operation<Type>("echo", null, null, null);
+ head = EasyMock.createMock(Interceptor.class);
+ EasyMock.expect(head.invoke(EasyMock.isA(Message.class))).andReturn(response);
+ EasyMock.replay(head);
+ chain = EasyMock.createMock(InvocationChain.class);
+ EasyMock.expect(chain.getTargetInvoker()).andReturn(null);
+ EasyMock.expect(chain.getHeadInterceptor()).andReturn(head);
+ EasyMock.replay(chain);
+ Map<Operation<?>, InvocationChain> chains = new HashMap<Operation<?>, InvocationChain>();
+ chains.put(operation, chain);
+ wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.getCallbackInvocationChains()).andReturn(chains);
+ EasyMock.replay(wire);
+
+ invoker = new LocalCallbackTargetInvoker(operation, wire);
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerThrowableTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerThrowableTestCase.java
new file mode 100644
index 0000000000..0c06842a60
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerThrowableTestCase.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.core.binding.local;
+
+import java.lang.reflect.Type;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.wire.InvocationChainImpl;
+import org.apache.tuscany.core.wire.WireImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LocalCallbackTargetInvokerThrowableTestCase extends TestCase {
+ private LocalCallbackTargetInvoker invoker;
+
+ /**
+ * Verfies an exception thrown in the target is propagated to the client correctly
+ */
+ public void testThrowableTargetInvocation() throws Exception {
+ Message message = new MessageImpl();
+ message.setBody("foo");
+ Message response = invoker.invoke(message);
+ assertTrue(response.isFault());
+ Object body = response.getBody();
+ if (!(body instanceof InsidiousException)) {
+ fail();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+ Operation<Type> operation = new Operation<Type>("echo", null, null, null);
+ InvocationChain chain = new InvocationChainImpl(operation);
+ chain.addInterceptor(new InsidiuousInterceptor());
+ Wire wire = new WireImpl();
+ wire.addCallbackInvocationChain(operation, chain);
+ invoker = new LocalCallbackTargetInvoker(operation, wire);
+ }
+
+ private class InsidiousException extends RuntimeException {
+
+ }
+
+ private class InsidiuousInterceptor implements Interceptor {
+
+ public Message invoke(Message msg) throws InsidiousException {
+ throw new InsidiousException();
+ }
+
+ public void setNext(Interceptor next) {
+
+ }
+
+ public Interceptor getNext() {
+ return null;
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java
new file mode 100644
index 0000000000..e49447164d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.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.core.binding.local;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.wire.InvocationChainImpl;
+import org.apache.tuscany.core.wire.WireImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LocalTargetInvokerTestCase extends TestCase {
+ private ServiceContract<Object> serviceContract;
+ private Operation<Object> operation;
+
+ public void testInvoke() {
+ TargetInvoker targetInvoker = EasyMock.createMock(TargetInvoker.class);
+ EasyMock.expect(targetInvoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl());
+ EasyMock.replay(targetInvoker);
+ InvocationChain chain = new InvocationChainImpl(operation);
+ chain.setTargetInvoker(targetInvoker);
+ Wire wire = new WireImpl();
+ wire.addInvocationChain(operation, chain);
+ wire.setSourceContract(serviceContract);
+ TargetInvoker invoker = new LocalTargetInvoker(operation, wire);
+ Message msg = invoker.invoke(new MessageImpl());
+ assertFalse(msg.isFault());
+ EasyMock.verify(targetInvoker);
+ }
+
+ public void testCallbackSetInvoke() {
+ ServiceContract<?> contract = new ServiceContract<Object>() {
+
+ };
+ contract.setCallbackClass(Object.class);
+ TargetInvoker targetInvoker = EasyMock.createMock(TargetInvoker.class);
+ EasyMock.expect(targetInvoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl());
+ EasyMock.replay(targetInvoker);
+
+ InvocationChain chain = new InvocationChainImpl(operation);
+ chain.setTargetInvoker(targetInvoker);
+ InvocationChain callbackChain = new InvocationChainImpl(operation);
+ Wire wire = new WireImpl();
+ wire.addInvocationChain(operation, chain);
+ wire.addCallbackInvocationChain(operation, callbackChain);
+ wire.setSourceContract(serviceContract);
+ URI uri = URI.create("foo");
+ wire.setSourceUri(uri);
+ wire.addInvocationChain(operation, chain);
+ TargetInvoker invoker = new LocalTargetInvoker(operation, wire);
+ Message msg = EasyMock.createMock(Message.class);
+ msg.pushCallbackUri(EasyMock.eq(uri));
+ EasyMock.replay(msg);
+ invoker.invoke(msg);
+ EasyMock.verify(msg);
+ EasyMock.verify(targetInvoker);
+ }
+
+ public void testFaultInvoke() {
+ TargetInvoker targetInvoker = EasyMock.createMock(TargetInvoker.class);
+ EasyMock.expect(targetInvoker.invoke(EasyMock.isA(Message.class))).andThrow(new TestException());
+ EasyMock.replay(targetInvoker);
+
+ InvocationChain chain = new InvocationChainImpl(operation);
+ chain.setTargetInvoker(targetInvoker);
+ Wire wire = new WireImpl();
+ wire.setSourceContract(serviceContract);
+ wire.addInvocationChain(operation, chain);
+ TargetInvoker invoker = new LocalTargetInvoker(operation, wire);
+ Message msg = invoker.invoke(new MessageImpl());
+ assertTrue(msg.isFault());
+ assertTrue(msg.getBody() instanceof TestException);
+ EasyMock.verify(targetInvoker);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ serviceContract = new ServiceContract<Object>() {
+ };
+ operation = new Operation<Object>("foo", null, null, null);
+ }
+
+
+ private class TestException extends RuntimeException {
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java
new file mode 100644
index 0000000000..cde10a0a2b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.builder;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.Connector;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ComponentManager;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.ComponentManagerImpl;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.composite.CompositeComponentImpl;
+import org.apache.tuscany.core.implementation.composite.ReferenceImpl;
+import org.apache.tuscany.core.implementation.composite.ServiceImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AtomicConnectorTestCase extends TestCase {
+ private static final URI PARENT = URI.create("parent");
+ private static final URI SOURCE = URI.create("source");
+ private static final URI TARGET = URI.create("parent#target");
+ private static final URI TARGET_NOFRAGMENT = URI.create("target");
+ private static final URI REFERENCE_NAME = URI.create("#ref");
+ private ComponentManager manager;
+ private Connector connector;
+ private ServiceContract<?> contract;
+
+ /**
+ * Verifies connecting a wire from an atomic component to a target atomic component
+ */
+ @SuppressWarnings({"unchecked"})
+ public void testConnectToAtomic() throws Exception {
+ AtomicComponent source = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(source.getUri()).andReturn(SOURCE).atLeastOnce();
+ EasyMock.expect(source.getScope()).andReturn(Scope.COMPOSITE);
+ source.attachWire(EasyMock.isA(Wire.class));
+ EasyMock.replay(source);
+ manager.register(source);
+
+ AtomicComponent target = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(target.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.expect(target.isOptimizable()).andReturn(false);
+ EasyMock.expect(target.getUri()).andReturn(TARGET_NOFRAGMENT).atLeastOnce();
+ target.createTargetInvoker((String) EasyMock.isNull(), EasyMock.isA(Operation.class));
+ EasyMock.expectLastCall().andReturn(null);
+ EasyMock.replay(target);
+ manager.register(target);
+
+ Implementation impl = new Implementation() {
+ };
+ ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ReferenceDefinition referenceDefinition = new ReferenceDefinition(REFERENCE_NAME, contract);
+ type.add(referenceDefinition);
+ impl.setComponentType(type);
+
+ ComponentDefinition<?> definition = new ComponentDefinition(impl);
+ definition.setUri(SOURCE);
+ ReferenceTarget referenceTarget = new ReferenceTarget();
+ referenceTarget.setReferenceName(REFERENCE_NAME);
+ referenceTarget.addTarget(TARGET_NOFRAGMENT);
+ definition.add(referenceTarget);
+
+ connector.connect(definition);
+ EasyMock.verify(source);
+ EasyMock.verify(target);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void testConnectToReference() throws Exception {
+ AtomicComponent source = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(source.getUri()).andReturn(SOURCE).atLeastOnce();
+ source.attachWire(EasyMock.isA(Wire.class));
+ EasyMock.expect(source.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.replay(source);
+ manager.register(source);
+
+ ReferenceBinding binding = EasyMock.createMock(ReferenceBinding.class);
+ binding.createTargetInvoker(EasyMock.isA(String.class), EasyMock.isA(Operation.class));
+ EasyMock.expectLastCall().andReturn(null);
+ EasyMock.replay(binding);
+
+ Reference reference = new ReferenceImpl(TARGET, contract);
+ reference.addReferenceBinding(binding);
+
+ Component component = new CompositeComponentImpl(PARENT);
+ component.register(reference);
+ manager.register(component);
+
+ Implementation impl = new Implementation() {
+ };
+ ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ReferenceDefinition referenceDefinition = new ReferenceDefinition(REFERENCE_NAME, contract);
+ type.add(referenceDefinition);
+ impl.setComponentType(type);
+
+ ComponentDefinition<?> definition = new ComponentDefinition(impl);
+ definition.setUri(SOURCE);
+ ReferenceTarget referenceTarget = new ReferenceTarget();
+ referenceTarget.setReferenceName(REFERENCE_NAME);
+ referenceTarget.addTarget(TARGET);
+ definition.add(referenceTarget);
+
+ connector.connect(definition);
+ EasyMock.verify(source);
+ EasyMock.verify(binding);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void testConnectToService() throws Exception {
+ AtomicComponent source = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(source.getUri()).andReturn(SOURCE).atLeastOnce();
+ EasyMock.expect(source.getScope()).andReturn(Scope.COMPOSITE);
+ source.attachWire(EasyMock.isA(Wire.class));
+ EasyMock.replay(source);
+ manager.register(source);
+
+ ServiceBinding binding = EasyMock.createMock(ServiceBinding.class);
+ binding.createTargetInvoker(EasyMock.isA(String.class), EasyMock.isA(Operation.class));
+ EasyMock.expectLastCall().andReturn(null);
+ EasyMock.replay(binding);
+
+ Service service = new ServiceImpl(TARGET, contract);
+ service.addServiceBinding(binding);
+
+ Component component = new CompositeComponentImpl(PARENT);
+ component.register(service);
+ manager.register(component);
+
+ Implementation impl = new Implementation() {
+ };
+ ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ReferenceDefinition referenceDefinition = new ReferenceDefinition(REFERENCE_NAME, contract);
+ type.add(referenceDefinition);
+ impl.setComponentType(type);
+
+ ComponentDefinition<?> definition = new ComponentDefinition(impl);
+ definition.setUri(SOURCE);
+ ReferenceTarget referenceTarget = new ReferenceTarget();
+ referenceTarget.setReferenceName(REFERENCE_NAME);
+ referenceTarget.addTarget(TARGET);
+ definition.add(referenceTarget);
+
+ connector.connect(definition);
+ EasyMock.verify(source);
+ EasyMock.verify(binding);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ manager = new ComponentManagerImpl();
+ connector = new ConnectorImpl(null, null, null, manager, null, null);
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ contract = registry.introspect(Foo.class);
+ }
+
+
+ private interface Foo {
+ void bar();
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryNoBindingsTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryNoBindingsTestCase.java
new file mode 100644
index 0000000000..f13ed3367d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryNoBindingsTestCase.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.core.builder;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.BuilderRegistry;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.model.Multiplicity;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.binding.local.LocalBindingBuilder;
+import org.apache.tuscany.core.binding.local.LocalBindingDefinition;
+import org.apache.tuscany.core.binding.local.LocalReferenceBinding;
+import org.apache.tuscany.core.binding.local.LocalServiceBinding;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class BuilderRegistryNoBindingsTestCase extends TestCase {
+ private DeploymentContext deploymentContext;
+ private Component parent;
+ private BuilderRegistry registry;
+
+ public void testNoServiceBindings() throws Exception {
+ ServiceBinding binding = EasyMock.createNiceMock(ServiceBinding.class);
+ EasyMock.replay(binding);
+ ServiceDefinition definition = new ServiceDefinition(URI.create("#foo"), null, false);
+ definition.setTarget(new URI("foo"));
+ EasyMock.replay(deploymentContext);
+ EasyMock.replay(parent);
+
+ Service service = registry.build(definition, deploymentContext);
+
+ assertEquals(1, service.getServiceBindings().size());
+ assertTrue(service.getServiceBindings().get(0) instanceof LocalServiceBinding);
+ EasyMock.verify(deploymentContext);
+ EasyMock.verify(parent);
+ }
+
+ public void testReferenceBindingBuilderDispatch() throws Exception {
+ ReferenceBinding binding = EasyMock.createNiceMock(ReferenceBinding.class);
+ EasyMock.replay(binding);
+ ReferenceDefinition definition = new ReferenceDefinition(URI.create("#foo"), null, Multiplicity.ONE_ONE);
+ EasyMock.replay(deploymentContext);
+ EasyMock.replay(parent);
+
+ Reference reference = registry.build(definition, deploymentContext);
+
+ assertEquals(1, reference.getReferenceBindings().size());
+ assertTrue(reference.getReferenceBindings().get(0) instanceof LocalReferenceBinding);
+ EasyMock.verify(deploymentContext);
+ EasyMock.verify(parent);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ deploymentContext = EasyMock.createMock(DeploymentContext.class);
+ parent = EasyMock.createNiceMock(Component.class);
+ registry = new BuilderRegistryImpl(null);
+ registry.register(LocalBindingDefinition.class, new LocalBindingBuilder());
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java
new file mode 100644
index 0000000000..34173154b8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.builder;
+
+import java.net.URI;
+import java.util.Map;
+
+import org.apache.tuscany.spi.builder.BindingBuilder;
+import org.apache.tuscany.spi.builder.BuilderConfigException;
+import org.apache.tuscany.spi.builder.BuilderRegistry;
+import org.apache.tuscany.spi.builder.ComponentBuilder;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.model.BindingDefinition;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+import org.apache.tuscany.spi.model.Implementation;
+import static org.apache.tuscany.spi.model.Multiplicity.ONE_ONE;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class BuilderRegistryTestCase extends TestCase {
+ private DeploymentContext deploymentContext;
+ private ScopeContainer scopeContainer;
+ private Map<URI, Component> components;
+
+ //private BuilderRegistryImpl registry;
+ private Component parent;
+
+ @SuppressWarnings({"unchecked"})
+ public void testRegistration() throws Exception {
+ URI componentId = URI.create("sca://localhost/component");
+ CompositeImplementation implementation = new CompositeImplementation();
+ ComponentDefinition<CompositeImplementation> componentDefinition =
+ new ComponentDefinition<CompositeImplementation>(implementation);
+ componentDefinition.getImplementation().setComponentType(new CompositeComponentType());
+
+ Component component = EasyMock.createMock(Component.class);
+ component.setDefaultPropertyValues(componentDefinition.getPropertyValues());
+ component.setScopeContainer(scopeContainer);
+ EasyMock.expect(component.getUri()).andReturn(componentId);
+ EasyMock.replay(component);
+
+ EasyMock.expect(deploymentContext.getCompositeScope()).andReturn(scopeContainer);
+ EasyMock.expect(deploymentContext.getComponents()).andReturn(components);
+ EasyMock.replay(deploymentContext);
+
+ EasyMock.expect(components.put(componentId, component)).andReturn(null);
+ EasyMock.replay(components);
+
+ ComponentBuilder builder = EasyMock.createMock(ComponentBuilder.class);
+ EasyMock.expect(builder.build(componentDefinition, deploymentContext)).andReturn(component);
+ EasyMock.replay(builder);
+
+ BuilderRegistry registry = new BuilderRegistryImpl(null);
+ registry.register(CompositeImplementation.class, builder);
+
+ assertSame(component, registry.build(componentDefinition, deploymentContext));
+ EasyMock.verify(builder);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void testServiceBindingBuilderDispatch() throws Exception {
+ BuilderRegistry registry = new BuilderRegistryImpl(null);
+ ServiceBinding binding = EasyMock.createNiceMock(ServiceBinding.class);
+ EasyMock.replay(binding);
+ BindingBuilder<MockBindingDefinition> builder = EasyMock.createMock(BindingBuilder.class);
+ EasyMock.expect(builder.build(
+ EasyMock.isA(ServiceDefinition.class),
+ EasyMock.isA(MockBindingDefinition.class),
+ EasyMock.isA(DeploymentContext.class))).andReturn(binding).times(2);
+ EasyMock.replay(builder);
+ registry.register(MockBindingDefinition.class, builder);
+ ServiceDefinition definition = new ServiceDefinition(URI.create("#foo"), null, false);
+ definition.addBinding(new MockBindingDefinition());
+ definition.addBinding(new MockBindingDefinition());
+ definition.setTarget(new URI("foo"));
+ Service service = registry.build(definition, deploymentContext);
+ assertEquals(2, service.getServiceBindings().size());
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void testReferenceBindingBuilderDispatch() throws Exception {
+ BuilderRegistry registry = new BuilderRegistryImpl(null);
+ ReferenceBinding binding = EasyMock.createNiceMock(ReferenceBinding.class);
+ EasyMock.replay(binding);
+ BindingBuilder<MockBindingDefinition> builder = EasyMock.createMock(BindingBuilder.class);
+ EasyMock.expect(builder.build(
+ EasyMock.isA(ReferenceDefinition.class),
+ EasyMock.isA(MockBindingDefinition.class),
+ EasyMock.isA(DeploymentContext.class))).andReturn(binding).times(2);
+ EasyMock.replay(builder);
+ registry.register(MockBindingDefinition.class, builder);
+ ReferenceDefinition definition = new ReferenceDefinition(URI.create("#foo"), null, ONE_ONE);
+ definition.addBinding(new MockBindingDefinition());
+ definition.addBinding(new MockBindingDefinition());
+ Reference reference = registry.build(definition, deploymentContext);
+ assertEquals(2, reference.getReferenceBindings().size());
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void testNoConversationalContract() throws Exception {
+ ScopeRegistry scopeRegistry = EasyMock.createMock(ScopeRegistry.class);
+ ScopeContainer scopeContainer = EasyMock.createNiceMock(ScopeContainer.class);
+ EasyMock.expect(scopeRegistry.getScopeContainer(EasyMock.isA(Scope.class))).andReturn(scopeContainer);
+ EasyMock.replay(scopeRegistry);
+ BuilderRegistry registry = new BuilderRegistryImpl(scopeRegistry);
+
+ AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class);
+ EasyMock.replay(component);
+ ComponentBuilder<FooImplementation> builder = EasyMock.createMock(ComponentBuilder.class);
+ EasyMock.expect(builder.build(
+ EasyMock.isA(ComponentDefinition.class),
+ EasyMock.isA(DeploymentContext.class))).andReturn(component);
+ EasyMock.replay(builder);
+ registry.register(FooImplementation.class, builder);
+
+ FooImplementation impl = new FooImplementation();
+ ComponentType componentType = new ComponentType();
+ componentType.setImplementationScope(Scope.CONVERSATION);
+ impl.setComponentType(componentType);
+ URI uri = URI.create("foo");
+ ComponentDefinition<FooImplementation> definition = new ComponentDefinition<FooImplementation>(uri, impl);
+ try {
+ registry.build(definition, deploymentContext);
+ fail("Should throw NoConversationalContractException");
+ } catch (NoConversationalContractException e) {
+ // expected
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ protected void setUp() throws Exception {
+ super.setUp();
+ deploymentContext = EasyMock.createMock(DeploymentContext.class);
+ parent = EasyMock.createNiceMock(Component.class);
+ scopeContainer = EasyMock.createMock(ScopeContainer.class);
+ components = EasyMock.createMock(Map.class);
+ }
+
+ private class MockBuilder implements ComponentBuilder<CompositeImplementation> {
+ public Component build(
+ ComponentDefinition componentDefinition,
+ DeploymentContext deploymentContext) throws BuilderConfigException {
+ return null;
+ }
+ }
+
+ private class MockBindingDefinition extends BindingDefinition {
+
+ }
+
+ private class FooImplementation extends Implementation<ComponentType> {
+
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplCreateWireTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplCreateWireTestCase.java
new file mode 100644
index 0000000000..e70221fdb0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplCreateWireTestCase.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.core.builder;
+
+import java.net.URI;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.builder.interceptor.InterceptorBuilder;
+import org.apache.tuscany.spi.builder.interceptor.InterceptorBuilderRegistry;
+import org.apache.tuscany.spi.model.physical.PhysicalInterceptorDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.builder.interceptor.InterceptorBuilderRegistryImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConnectorImplCreateWireTestCase extends TestCase {
+ private static final QName QNAME = new QName("test");
+
+ public void testCreateWire() throws Exception {
+ TestConnector connector = new TestConnector();
+ PhysicalWireDefinition definition = new PhysicalWireDefinition();
+ PhysicalWireSourceDefinition sourceDefinition = new PhysicalWireSourceDefinition();
+ sourceDefinition.setUri(URI.create("source"));
+ PhysicalWireTargetDefinition targetDefinition = new PhysicalWireTargetDefinition();
+ targetDefinition.setUri(URI.create("target"));
+ definition.setSource(sourceDefinition);
+ definition.setTarget(targetDefinition);
+ PhysicalOperationDefinition operation = new PhysicalOperationDefinition();
+ operation.setName("operation");
+ definition.addOperation(operation);
+ PhysicalOperationDefinition callback = new PhysicalOperationDefinition();
+ callback.setName("callback");
+ callback.setCallback(true);
+ definition.addOperation(callback);
+ Wire wire = connector.createWire(definition);
+ assertEquals(2, wire.getPhysicalInvocationChains().size());
+ }
+
+ public void testDispatchToBuilder() throws Exception {
+ QName qName = new QName("interceptor");
+ InterceptorBuilder builder = EasyMock.createMock(InterceptorBuilder.class);
+ EasyMock.expect(builder.build(EasyMock.isA(PhysicalInterceptorDefinition.class))).andReturn(null).times(2);
+ EasyMock.replay(builder);
+ InterceptorBuilderRegistryImpl regisry = new InterceptorBuilderRegistryImpl();
+ regisry.register(qName, builder);
+ TestConnector connector = new TestConnector(regisry);
+ PhysicalWireDefinition definition = new PhysicalWireDefinition();
+ PhysicalWireSourceDefinition sourceDefinition = new PhysicalWireSourceDefinition();
+ sourceDefinition.setUri(URI.create("source"));
+ PhysicalWireTargetDefinition targetDefinition = new PhysicalWireTargetDefinition();
+ targetDefinition.setUri(URI.create("target"));
+ definition.setSource(sourceDefinition);
+ definition.setTarget(targetDefinition);
+ PhysicalInterceptorDefinition interceptorDefinition = new PhysicalInterceptorDefinition(QNAME);
+ interceptorDefinition.setBuilder(qName);
+
+ PhysicalOperationDefinition operation = new PhysicalOperationDefinition();
+ operation.setName("operation");
+ operation.addInterceptor(interceptorDefinition);
+ definition.addOperation(operation);
+ PhysicalOperationDefinition callback = new PhysicalOperationDefinition();
+ callback.setName("callback");
+ callback.setCallback(true);
+ callback.addInterceptor(interceptorDefinition);
+ definition.addOperation(callback);
+ connector.createWire(definition);
+ EasyMock.verify(builder);
+ }
+
+ private class TestConnector extends ConnectorImpl {
+
+ public TestConnector() {
+ super(null);
+ }
+
+ public TestConnector(InterceptorBuilderRegistry regisry) {
+ super(regisry, null, null, null, null, null);
+ }
+
+
+ public Wire createWire(PhysicalWireDefinition definition) throws BuilderException {
+ return super.createWire(definition);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplTestCase.java
new file mode 100644
index 0000000000..4c4e1a32b0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplTestCase.java
@@ -0,0 +1,320 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.builder;
+
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ComponentManager;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.ComponentManagerImpl;
+import org.apache.tuscany.core.wire.InvokerInterceptor;
+import org.apache.tuscany.core.wire.NonBlockingInterceptor;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConnectorImplTestCase extends TestCase {
+ private TestConnector connector;
+ private ComponentManager manager;
+
+ public void testConnectTargetNotFound() throws Exception {
+ Implementation<ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>> impl =
+ new Implementation<ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>>() {
+ };
+ ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ URI refUri = URI.create("ref");
+ ReferenceDefinition referenceDefinition = new ReferenceDefinition(refUri, null);
+ referenceDefinition.setRequired(true);
+ type.add(referenceDefinition);
+ impl.setComponentType(type);
+
+ URI sourceUri = URI.create("source");
+ ComponentDefinition<?> definition =
+ new ComponentDefinition<Implementation<ComponentType<ServiceDefinition,
+ ReferenceDefinition, Property<?>>>>(impl);
+ definition.setUri(sourceUri);
+ ReferenceTarget referenceTarget = new ReferenceTarget();
+ referenceTarget.setReferenceName(refUri);
+ referenceTarget.addTarget(URI.create("NotThere"));
+ definition.add(referenceTarget);
+ Component component = EasyMock.createMock(Component.class);
+ EasyMock.expect(component.getUri()).andReturn(sourceUri);
+ EasyMock.replay(component);
+ manager.register(component);
+ try {
+ connector.connect(definition);
+ fail();
+ } catch (ComponentNotFoundException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verifies a non-existent target does not throw an error.
+ * <p/>
+ * TODO JFM when the allocator is in place it should optimize connecting to non-existent targets but keep it for
+ * now
+ */
+ public void testConnectTargetNotFoundNonRequiredReference() throws Exception {
+ Implementation<ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>> impl =
+ new Implementation<ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>>() {
+ };
+ ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ URI refUri = URI.create("ref");
+ ReferenceDefinition referenceDefinition = new ReferenceDefinition(refUri, null);
+ referenceDefinition.setRequired(false);
+ type.add(referenceDefinition);
+ impl.setComponentType(type);
+
+ URI sourceUri = URI.create("source");
+ ComponentDefinition<?> definition =
+ new ComponentDefinition<Implementation<ComponentType<ServiceDefinition,
+ ReferenceDefinition, Property<?>>>>(impl);
+ definition.setUri(sourceUri);
+ ReferenceTarget referenceTarget = new ReferenceTarget();
+ referenceTarget.setReferenceName(refUri);
+ referenceTarget.addTarget(URI.create("NotThere"));
+ definition.add(referenceTarget);
+ Component component = EasyMock.createMock(Component.class);
+ EasyMock.expect(component.getUri()).andReturn(sourceUri);
+ EasyMock.replay(component);
+ manager.register(component);
+ connector.connect(definition);
+ }
+
+ public void testNonOptimizableTargetComponent() throws Exception {
+ AtomicComponent source = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(source.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.replay(source);
+
+ AtomicComponent target = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(target.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.expect(target.isOptimizable()).andReturn(false);
+ EasyMock.replay(target);
+
+ Wire wire = EasyMock.createMock(Wire.class);
+ wire.setOptimizable(false);
+ EasyMock.replay(wire);
+ connector.optimize(source, target, wire);
+ EasyMock.verify(source);
+ EasyMock.verify(target);
+ EasyMock.verify(wire);
+ }
+
+ public void testOptimizableTargetComponent() throws Exception {
+ AtomicComponent source = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(source.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.replay(source);
+
+ AtomicComponent target = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(target.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.expect(target.isOptimizable()).andReturn(true);
+ EasyMock.replay(target);
+
+ Wire wire = EasyMock.createMock(Wire.class);
+ wire.setOptimizable(true);
+ wire.setTarget(EasyMock.eq(target));
+ wire.getInvocationChains();
+ EasyMock.expectLastCall().andReturn(Collections.emptyMap());
+ wire.getCallbackInvocationChains();
+ EasyMock.expectLastCall().andReturn(Collections.emptyMap());
+ EasyMock.replay(wire);
+ connector.optimize(source, target, wire);
+ EasyMock.verify(source);
+ EasyMock.verify(target);
+ }
+
+ public void testIsOptimizable() {
+ assertTrue(connector.isOptimizable(Scope.STATELESS, Scope.STATELESS));
+ assertTrue(connector.isOptimizable(Scope.STATELESS, Scope.COMPOSITE));
+ assertFalse(connector.isOptimizable(Scope.STATELESS, Scope.CONVERSATION));
+ assertTrue(connector.isOptimizable(Scope.STATELESS, Scope.REQUEST));
+ assertTrue(connector.isOptimizable(Scope.STATELESS, Scope.SESSION));
+ assertTrue(connector.isOptimizable(Scope.STATELESS, Scope.SYSTEM));
+
+ assertTrue(connector.isOptimizable(Scope.COMPOSITE, Scope.COMPOSITE));
+ assertFalse(connector.isOptimizable(Scope.COMPOSITE, Scope.CONVERSATION));
+ assertFalse(connector.isOptimizable(Scope.COMPOSITE, Scope.REQUEST));
+ assertFalse(connector.isOptimizable(Scope.COMPOSITE, Scope.SESSION));
+ assertFalse(connector.isOptimizable(Scope.COMPOSITE, Scope.STATELESS));
+ assertTrue(connector.isOptimizable(Scope.COMPOSITE, Scope.SYSTEM));
+
+ assertFalse(connector.isOptimizable(Scope.CONVERSATION, Scope.COMPOSITE));
+ assertFalse(connector.isOptimizable(Scope.CONVERSATION, Scope.CONVERSATION));
+ assertFalse(connector.isOptimizable(Scope.CONVERSATION, Scope.REQUEST));
+ assertFalse(connector.isOptimizable(Scope.CONVERSATION, Scope.SESSION));
+ assertFalse(connector.isOptimizable(Scope.CONVERSATION, Scope.STATELESS));
+ assertFalse(connector.isOptimizable(Scope.CONVERSATION, Scope.SYSTEM));
+
+ assertTrue(connector.isOptimizable(Scope.REQUEST, Scope.COMPOSITE));
+ assertFalse(connector.isOptimizable(Scope.REQUEST, Scope.CONVERSATION));
+ assertTrue(connector.isOptimizable(Scope.REQUEST, Scope.REQUEST));
+ assertTrue(connector.isOptimizable(Scope.REQUEST, Scope.SESSION));
+ assertFalse(connector.isOptimizable(Scope.REQUEST, Scope.STATELESS));
+ assertTrue(connector.isOptimizable(Scope.REQUEST, Scope.SYSTEM));
+
+ assertTrue(connector.isOptimizable(Scope.SESSION, Scope.COMPOSITE));
+ assertFalse(connector.isOptimizable(Scope.SESSION, Scope.CONVERSATION));
+ assertFalse(connector.isOptimizable(Scope.SESSION, Scope.REQUEST));
+ assertTrue(connector.isOptimizable(Scope.SESSION, Scope.SESSION));
+ assertFalse(connector.isOptimizable(Scope.SESSION, Scope.STATELESS));
+ assertTrue(connector.isOptimizable(Scope.SESSION, Scope.SYSTEM));
+
+ assertTrue(connector.isOptimizable(Scope.SYSTEM, Scope.COMPOSITE));
+ assertFalse(connector.isOptimizable(Scope.SYSTEM, Scope.CONVERSATION));
+ assertFalse(connector.isOptimizable(Scope.SYSTEM, Scope.REQUEST));
+ assertFalse(connector.isOptimizable(Scope.SYSTEM, Scope.SESSION));
+ assertFalse(connector.isOptimizable(Scope.SYSTEM, Scope.STATELESS));
+ assertTrue(connector.isOptimizable(Scope.SYSTEM, Scope.SYSTEM));
+
+ assertFalse(connector.isOptimizable(Scope.UNDEFINED, Scope.COMPOSITE));
+ assertFalse(connector.isOptimizable(Scope.UNDEFINED, Scope.CONVERSATION));
+ assertFalse(connector.isOptimizable(Scope.UNDEFINED, Scope.REQUEST));
+ assertFalse(connector.isOptimizable(Scope.UNDEFINED, Scope.SESSION));
+ assertFalse(connector.isOptimizable(Scope.UNDEFINED, Scope.STATELESS));
+ assertFalse(connector.isOptimizable(Scope.UNDEFINED, Scope.SYSTEM));
+
+ }
+
+ public void testCreateSyncForwardWire() throws Exception {
+ ServiceContract<Type> contract = new ServiceContract<Type>() {
+
+ };
+ Operation<Type> operation = new Operation<Type>("operation", null, null, null);
+ Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>();
+ operations.put("operation", operation);
+ contract.setOperations(operations);
+ Wire wire = connector.createWire(URI.create("target"), URI.create("#ref"), contract, Wire.LOCAL_BINDING);
+ assertEquals(1, wire.getInvocationChains().size());
+ InvocationChain chain = wire.getInvocationChains().get(operation);
+ Interceptor head = chain.getHeadInterceptor();
+ assertTrue(head instanceof InvokerInterceptor);
+ }
+
+ public void testCreateSyncCallbackWire() throws Exception {
+ ServiceContract<Type> contract = new ServiceContract<Type>() {
+
+ };
+
+ Operation<Type> operation = new Operation<Type>("operation", null, null, null);
+ Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>();
+ operations.put("operation", operation);
+ contract.setOperations(operations);
+
+ Operation<Type> callbackOperation = new Operation<Type>("operation", null, null, null);
+ Map<String, Operation<Type>> callbackOperations = new HashMap<String, Operation<Type>>();
+ callbackOperations.put("operation", callbackOperation);
+ contract.setCallbackOperations(callbackOperations);
+
+ Wire wire = connector.createWire(URI.create("target"), URI.create("#ref"), contract, Wire.LOCAL_BINDING);
+ assertEquals(1, wire.getCallbackInvocationChains().size());
+ InvocationChain chain = wire.getCallbackInvocationChains().get(callbackOperation);
+ Interceptor head = chain.getHeadInterceptor();
+ assertTrue(head instanceof InvokerInterceptor);
+ }
+
+ public void testCreateNonBlockingForwardWire() throws Exception {
+ ServiceContract<Type> contract = new ServiceContract<Type>() {
+
+ };
+ Operation<Type> operation = new Operation<Type>("operation", null, null, null);
+ operation.setNonBlocking(true);
+ Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>();
+ operations.put("operation", operation);
+ contract.setOperations(operations);
+ Wire wire = connector.createWire(URI.create("target"), URI.create("#ref"), contract, Wire.LOCAL_BINDING);
+ assertEquals(1, wire.getInvocationChains().size());
+ InvocationChain chain = wire.getInvocationChains().get(operation);
+ Interceptor head = chain.getHeadInterceptor();
+ assertTrue(head instanceof NonBlockingInterceptor);
+ assertTrue(head.getNext() instanceof InvokerInterceptor);
+ }
+
+ public void testCreateNonBlockingCallbackWire() throws Exception {
+ ServiceContract<Type> contract = new ServiceContract<Type>() {
+
+ };
+
+ Operation<Type> operation = new Operation<Type>("operation", null, null, null);
+ operation.setNonBlocking(true);
+ Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>();
+ operations.put("operation", operation);
+ contract.setOperations(operations);
+
+ Operation<Type> callbackOperation = new Operation<Type>("operation", null, null, null);
+ callbackOperation.setNonBlocking(true);
+ Map<String, Operation<Type>> callbackOperations = new HashMap<String, Operation<Type>>();
+ callbackOperations.put("operation", callbackOperation);
+ contract.setCallbackOperations(callbackOperations);
+
+ Wire wire = connector.createWire(URI.create("target"), URI.create("#ref"), contract, Wire.LOCAL_BINDING);
+ assertEquals(1, wire.getCallbackInvocationChains().size());
+ InvocationChain chain = wire.getCallbackInvocationChains().get(callbackOperation);
+ Interceptor head = chain.getHeadInterceptor();
+ assertTrue(head instanceof NonBlockingInterceptor);
+ assertTrue(head.getNext() instanceof InvokerInterceptor);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ manager = new ComponentManagerImpl();
+ connector = new TestConnector(manager);
+ }
+
+ private class TestConnector extends ConnectorImpl {
+
+ public TestConnector(ComponentManager componentManager) {
+ super(componentManager);
+ }
+
+ protected Wire createWire(URI sourceURI, URI targetUri, ServiceContract<?> contract, QName bindingType) {
+ return super.createWire(sourceURI, targetUri, contract, bindingType);
+ }
+
+ public boolean isOptimizable(Scope pReferrer, Scope pReferee) {
+ return super.isOptimizable(pReferrer, pReferee);
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplWireTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplWireTestCase.java
new file mode 100644
index 0000000000..f81116eea8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplWireTestCase.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.core.builder;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.Connector;
+import org.apache.tuscany.spi.builder.physical.WireAttacherRegistry;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ComponentManager;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.ComponentManagerImpl;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConnectorImplWireTestCase extends TestCase {
+ private static final URI SOURCE_URI = URI.create("source");
+ private static final URI TARGET_URI = URI.create("target");
+ private ComponentManager manager;
+ private Connector connector;
+ private ServiceContract<?> contract;
+
+ public void testConnectWireDefinition() throws Exception {
+ AtomicComponent source = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(source.getUri()).andReturn(SOURCE_URI).atLeastOnce();
+ EasyMock.replay(source);
+ manager.register(source);
+
+ AtomicComponent target = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(target.getUri()).andReturn(TARGET_URI).atLeastOnce();
+ EasyMock.replay(target);
+ manager.register(target);
+
+ PhysicalWireDefinition definition = new PhysicalWireDefinition();
+ PhysicalWireSourceDefinition pwsd = new PhysicalWireSourceDefinition();
+ pwsd.setUri(SOURCE_URI);
+ definition.setSource(pwsd);
+ PhysicalWireTargetDefinition pwtd = new PhysicalWireTargetDefinition();
+ pwtd.setUri(TARGET_URI);
+ definition.setTarget(pwtd);
+ PhysicalOperationDefinition op = new PhysicalOperationDefinition();
+ definition.addOperation(op);
+ connector.connect(definition);
+ EasyMock.verify(source);
+ EasyMock.verify(target);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ manager = new ComponentManagerImpl();
+ WireAttacherRegistry attacherRegistry = EasyMock.createNiceMock(WireAttacherRegistry.class);
+ EasyMock.replay(attacherRegistry);
+ connector = new ConnectorImpl(null, attacherRegistry, null, manager, null, null);
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ contract = registry.introspect(Foo.class);
+ }
+
+ private interface Foo {
+ void bar();
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/IllegalCallbackExceptionTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/IllegalCallbackExceptionTestCase.java
new file mode 100644
index 0000000000..c6a9927db3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/IllegalCallbackExceptionTestCase.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.core.builder;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class IllegalCallbackExceptionTestCase extends TestCase {
+
+ public void testInstantiation() throws Exception {
+ URI sourceUri = URI.create("source");
+ URI targetUri = URI.create("target");
+ IllegalCallbackException e = new IllegalCallbackException("message", "identifier", sourceUri, targetUri);
+ assertEquals("message", e.getMessage());
+ assertEquals("identifier", e.getIdentifier());
+ assertEquals(sourceUri, e.getSourceUri());
+ assertEquals(targetUri, e.getTargetUri());
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/IncompatibleInterfacesExceptionTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/IncompatibleInterfacesExceptionTestCase.java
new file mode 100644
index 0000000000..5d370fcfc5
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/IncompatibleInterfacesExceptionTestCase.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.core.builder;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class IncompatibleInterfacesExceptionTestCase extends TestCase {
+
+ public void testInstantiation() throws Exception {
+ URI sourceUri = URI.create("source");
+ URI targetUri = URI.create("target");
+ IncompatibleInterfacesException e = new IncompatibleInterfacesException(sourceUri, targetUri);
+ assertNotNull(e.getMessage());
+ assertEquals("source", e.getSourceUri().toString());
+ assertEquals("target", e.getTargetUri().toString());
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/InvalidSourceTypeExceptionTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/InvalidSourceTypeExceptionTestCase.java
new file mode 100644
index 0000000000..67ad003d58
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/InvalidSourceTypeExceptionTestCase.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.core.builder;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InvalidSourceTypeExceptionTestCase extends TestCase {
+
+ public void testInstantiation() throws Exception {
+ URI sourceUri = URI.create("source");
+ URI targetUri = URI.create("target");
+ InvalidSourceTypeException e = new InvalidSourceTypeException("message", sourceUri, targetUri);
+ assertEquals("message", e.getMessage());
+ assertEquals(sourceUri, e.getSourceUri());
+ assertEquals(targetUri, e.getTargetUri());
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/InvalidTargetTypeExceptionTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/InvalidTargetTypeExceptionTestCase.java
new file mode 100644
index 0000000000..61060293ce
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/InvalidTargetTypeExceptionTestCase.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.core.builder;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InvalidTargetTypeExceptionTestCase extends TestCase {
+
+ public void testInstantiation() throws Exception {
+ URI sourceUri = URI.create("source");
+ URI targetUri = URI.create("target");
+ InvalidTargetTypeException e = new InvalidTargetTypeException("message", sourceUri, targetUri);
+ assertEquals("message", e.getMessage());
+ assertEquals(sourceUri, e.getSourceUri());
+ assertEquals(targetUri, e.getTargetUri());
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.java
new file mode 100644
index 0000000000..e32db6b1a7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.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.core.builder;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.WiringException;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ComponentManager;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.model.BindingDefinition;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.ComponentManagerImpl;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.composite.CompositeComponentImpl;
+import org.apache.tuscany.core.implementation.composite.ReferenceImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReferenceConnectorTestCase extends TestCase {
+ private static final URI PARENT = URI.create("parent");
+ private static final URI SOURCE = URI.create("parent#source");
+ private static final URI TARGET = URI.create("parent/target");
+ private static final URI REFERENCE_TARGET = URI.create("parent#target");
+ private ComponentManager manager;
+ private MockConnnector connector;
+ private ServiceContract<?> contract;
+
+ /**
+ * Verifies connecting a wire from an atomic component to a target atomic component
+ */
+ @SuppressWarnings({"unchecked"})
+ public void testConnectToAtomic() throws Exception {
+ ReferenceBinding binding = EasyMock.createMock(ReferenceBinding.class);
+ EasyMock.expect(binding.getTargetUri()).andReturn(TARGET);
+ EasyMock.expect(binding.getBindingType()).andReturn(Wire.LOCAL_BINDING).atLeastOnce();
+ binding.getBindingServiceContract();
+ EasyMock.expectLastCall().andReturn(contract);
+ binding.setWire(EasyMock.isA(Wire.class));
+ EasyMock.replay(binding);
+
+ Reference reference = new ReferenceImpl(SOURCE, contract);
+ reference.addReferenceBinding(binding);
+
+ Component component = new CompositeComponentImpl(PARENT);
+ component.register(reference);
+ manager.register(component);
+
+
+ AtomicComponent target = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(target.getUri()).andReturn(TARGET).atLeastOnce();
+ target.createTargetInvoker((String) EasyMock.isNull(), EasyMock.isA(Operation.class));
+ EasyMock.expectLastCall().andReturn(null);
+ EasyMock.replay(target);
+ manager.register(target);
+
+ ReferenceDefinition definition = new ReferenceDefinition(SOURCE, contract);
+ BindingDefinition bindingDefinition = new BindingDefinition(TARGET) {
+ };
+ definition.addBinding(bindingDefinition);
+
+ connector.connect(definition);
+
+ EasyMock.verify(binding);
+ EasyMock.verify(target);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void testConnectToReference() throws Exception {
+ ReferenceBinding binding = EasyMock.createMock(ReferenceBinding.class);
+ EasyMock.expect(binding.getTargetUri()).andReturn(REFERENCE_TARGET);
+ EasyMock.expect(binding.getBindingType()).andReturn(Wire.LOCAL_BINDING).atLeastOnce();
+ binding.getBindingServiceContract();
+ EasyMock.expectLastCall().andReturn(contract);
+ binding.setWire(EasyMock.isA(Wire.class));
+ EasyMock.replay(binding);
+
+ Reference reference = new ReferenceImpl(SOURCE, contract);
+ reference.addReferenceBinding(binding);
+
+ Component component = new CompositeComponentImpl(PARENT);
+ component.register(reference);
+
+ ReferenceBinding refBinding = EasyMock.createMock(ReferenceBinding.class);
+ refBinding.createTargetInvoker(EasyMock.isA(String.class), EasyMock.isA(Operation.class));
+ EasyMock.expectLastCall().andReturn(null);
+ EasyMock.replay(refBinding);
+ Reference target = new ReferenceImpl(REFERENCE_TARGET, contract);
+ target.addReferenceBinding(refBinding);
+ component.register(target);
+ manager.register(component);
+
+ ReferenceDefinition definition = new ReferenceDefinition(SOURCE, contract);
+ BindingDefinition bindingDefinition = new BindingDefinition(TARGET) {
+ };
+ definition.addBinding(bindingDefinition);
+
+ connector.connect(definition);
+
+ EasyMock.verify(binding);
+ EasyMock.verify(refBinding);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ manager = new ComponentManagerImpl();
+ connector = new MockConnnector(manager);
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ contract = registry.introspect(Foo.class);
+ }
+
+
+ private interface Foo {
+ void bar();
+ }
+
+ private class MockConnnector extends ConnectorImpl {
+
+ public MockConnnector(ComponentManager componentManager) {
+ super(componentManager);
+ }
+
+ public void connect(ReferenceDefinition definition) throws WiringException {
+ super.connect(definition);
+ }
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/ServiceConnectorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/ServiceConnectorTestCase.java
new file mode 100644
index 0000000000..bc27df19c1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/ServiceConnectorTestCase.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.builder;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.WiringException;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ComponentManager;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.model.BindingDefinition;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.ComponentManagerImpl;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.composite.CompositeComponentImpl;
+import org.apache.tuscany.core.implementation.composite.ServiceImpl;
+import org.apache.tuscany.core.implementation.composite.ReferenceImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ServiceConnectorTestCase extends TestCase {
+ private static final URI PARENT = URI.create("parent");
+ private static final URI SOURCE = URI.create("parent#source");
+ private static final URI TARGET = URI.create("parent/target");
+ private static final URI REFERENCE_TARGET = URI.create("parent#target");
+ private ComponentManager manager;
+ private MockConnnector connector;
+ private ServiceContract<?> contract;
+
+ /**
+ * Verifies connecting a wire from an atomic component to a target atomic component
+ */
+ @SuppressWarnings({"unchecked"})
+ public void testConnectToAtomic() throws Exception {
+ ServiceBinding binding = EasyMock.createMock(ServiceBinding.class);
+ EasyMock.expect(binding.getBindingType()).andReturn(Wire.LOCAL_BINDING);
+ binding.setWire(EasyMock.isA(Wire.class));
+ EasyMock.replay(binding);
+
+ Service service = new ServiceImpl(SOURCE, contract);
+ service.addServiceBinding(binding);
+
+ Component component = new CompositeComponentImpl(PARENT);
+ component.register(service);
+ manager.register(component);
+
+
+ AtomicComponent target = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(target.getUri()).andReturn(TARGET).atLeastOnce();
+ target.createTargetInvoker((String) EasyMock.isNull(), EasyMock.isA(Operation.class));
+ EasyMock.expectLastCall().andReturn(null);
+ EasyMock.replay(target);
+ manager.register(target);
+
+ ServiceDefinition definition = new ServiceDefinition(SOURCE, contract, false);
+ definition.setTarget(TARGET);
+ BindingDefinition bindingDefinition = new BindingDefinition(TARGET) {
+ };
+ definition.addBinding(bindingDefinition);
+ connector.connect(definition);
+
+ EasyMock.verify(binding);
+ EasyMock.verify(target);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void testConnectToReference() throws Exception {
+ ServiceBinding binding = EasyMock.createMock(ServiceBinding.class);
+ EasyMock.expect(binding.getBindingType()).andReturn(Wire.LOCAL_BINDING);
+ binding.setWire(EasyMock.isA(Wire.class));
+ EasyMock.replay(binding);
+
+ Service service = new ServiceImpl(SOURCE, contract);
+ service.addServiceBinding(binding);
+
+ Component component = new CompositeComponentImpl(PARENT);
+ component.register(service);
+
+ ReferenceBinding refBinding = EasyMock.createMock(ReferenceBinding.class);
+ refBinding.createTargetInvoker(EasyMock.isA(String.class), EasyMock.isA(Operation.class));
+ EasyMock.expectLastCall().andReturn(null);
+ EasyMock.replay(refBinding);
+ Reference target = new ReferenceImpl(REFERENCE_TARGET, contract);
+ target.addReferenceBinding(refBinding);
+ component.register(target);
+ manager.register(component);
+
+ ServiceDefinition definition = new ServiceDefinition(SOURCE, contract, false);
+ definition.setTarget(REFERENCE_TARGET);
+ BindingDefinition bindingDefinition = new BindingDefinition(REFERENCE_TARGET) {
+ };
+ definition.addBinding(bindingDefinition);
+ connector.connect(definition);
+
+ EasyMock.verify(binding);
+ EasyMock.verify(refBinding);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ manager = new ComponentManagerImpl();
+ connector = new MockConnnector(manager);
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ contract = registry.introspect(Foo.class);
+ }
+
+
+ private interface Foo {
+ void bar();
+ }
+
+ private class MockConnnector extends ConnectorImpl {
+
+ public MockConnnector(ComponentManager componentManager) {
+ super(componentManager);
+ }
+
+ public void connect(ServiceDefinition definition) throws WiringException {
+ super.connect(definition);
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/TargetServiceNotFoundExceptionTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/TargetServiceNotFoundExceptionTestCase.java
new file mode 100644
index 0000000000..2d056ac964
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/TargetServiceNotFoundExceptionTestCase.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.core.builder;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TargetServiceNotFoundExceptionTestCase extends TestCase {
+
+ public void testInstantiation() throws Exception {
+ URI sourceUri = URI.create("source");
+ URI targetUri = URI.create("target");
+ TargetServiceNotFoundException e = new TargetServiceNotFoundException("message", sourceUri, targetUri);
+ assertEquals("message", e.getMessage());
+ assertEquals(sourceUri, e.getSourceUri());
+ assertEquals(targetUri, e.getTargetUri());
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImplTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImplTestCase.java
new file mode 100644
index 0000000000..fcd5f03189
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImplTestCase.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.core.builder;
+
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.WirePostProcessor;
+import org.apache.tuscany.spi.wire.WirePostProcessorRegistry;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.verify;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WirePostProcessorRegistryImplTestCase extends TestCase {
+
+ public void testRegisterUnregister() throws Exception {
+ WirePostProcessorRegistry registry = new WirePostProcessorRegistryImpl();
+ Wire wire = EasyMock.createMock(Wire.class);
+ WirePostProcessor processor = createMock(WirePostProcessor.class);
+ processor.process(EasyMock.eq(wire));
+ EasyMock.replay(processor);
+ registry.register(processor);
+ registry.process(wire);
+ registry.unregister(processor);
+ registry.process(wire);
+ verify(processor);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/WiringExceptionFormatterTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/WiringExceptionFormatterTestCase.java
new file mode 100644
index 0000000000..e05a162d7a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/WiringExceptionFormatterTestCase.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.core.builder;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.WiringException;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.host.monitor.FormatterRegistry;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WiringExceptionFormatterTestCase extends TestCase {
+ WiringExceptionFormatter formatter = new WiringExceptionFormatter(EasyMock.createNiceMock(FormatterRegistry.class));
+
+ public void testFormat() throws Exception {
+ WiringException e =
+ new MockWiringException("message", "identifier", URI.create("source"), URI.create("target"));
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ formatter.write(pw, e);
+ String buffer = writer.toString();
+ assertTrue(buffer.indexOf("message") >= 0);
+ assertTrue(buffer.indexOf("identifier") >= 0);
+ assertTrue(buffer.indexOf("source") >= 0);
+ assertTrue(buffer.indexOf("target") >= 0);
+ }
+
+
+ public void testFormatNulls() throws Exception {
+ WiringException e = new MockWiringException("message",
+ "identifier",
+ null,
+ null);
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ formatter.write(pw, e);
+ String buffer = writer.toString();
+ assertTrue(buffer.indexOf("message") >= 0);
+ assertTrue(buffer.indexOf("identifier") >= 0);
+ }
+
+ private class MockWiringException extends WiringException {
+
+ public MockWiringException(String message, String identifier, URI source, URI reference) {
+ super(message, identifier, source, reference);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/interceptor/InterceptorBuilderRegistryImplTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/interceptor/InterceptorBuilderRegistryImplTestCase.java
new file mode 100644
index 0000000000..50e4656836
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/interceptor/InterceptorBuilderRegistryImplTestCase.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.core.builder.interceptor;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.builder.interceptor.InterceptorBuilder;
+import org.apache.tuscany.spi.builder.interceptor.InterceptorBuilderRegistry;
+import org.apache.tuscany.spi.model.physical.PhysicalInterceptorDefinition;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InterceptorBuilderRegistryImplTestCase extends TestCase {
+ private static final QName QNAME = new QName("builder");
+ private static final QName INTERCEPTOR_QNAME = new QName("interceptor");
+
+ private InterceptorBuilderRegistry registry = new InterceptorBuilderRegistryImpl();
+
+ public void testDispatch() throws Exception {
+ InterceptorBuilder builder = EasyMock.createMock(InterceptorBuilder.class);
+ EasyMock.expect(builder.build(EasyMock.isA(PhysicalInterceptorDefinition.class))).andReturn(null);
+ EasyMock.replay(builder);
+ registry.register(QNAME, builder);
+ PhysicalInterceptorDefinition definition = new PhysicalInterceptorDefinition(INTERCEPTOR_QNAME);
+ definition.setBuilder(QNAME);
+ registry.build(definition);
+ EasyMock.verify(builder);
+ }
+
+ public void testUnregister() throws Exception {
+ InterceptorBuilder builder = EasyMock.createMock(InterceptorBuilder.class);
+ EasyMock.replay(builder);
+ registry.register(QNAME, builder);
+ registry.unregister(QNAME);
+ PhysicalInterceptorDefinition definition = new PhysicalInterceptorDefinition(INTERCEPTOR_QNAME);
+ definition.setBuilder(QNAME);
+ try {
+ registry.build(definition);
+ //fail
+ } catch (InterceptorBuilderNotFoundException e) {
+ // expected
+ }
+ EasyMock.verify(builder);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/physical/WireAttacherRegistryTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/physical/WireAttacherRegistryTestCase.java
new file mode 100644
index 0000000000..36296b7810
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/builder/physical/WireAttacherRegistryTestCase.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.core.builder.physical;
+
+import org.apache.tuscany.spi.builder.physical.WireAttacher;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WireAttacherRegistryTestCase extends TestCase {
+ WireAttacherRegistryImpl registry;
+ private Component source;
+ private Component target;
+ private Wire wire;
+ private WireAttacher attacher;
+ private PhysicalWireSourceDefinition pwsd;
+ private PhysicalWireTargetDefinition pwtd;
+
+ @SuppressWarnings("unchecked")
+ public void testSourceAttachDispatch() throws Exception {
+ attacher.attachToSource(source, pwsd, target, pwtd, wire);
+ EasyMock.replay(attacher);
+
+ registry.register(PhysicalWireSourceDefinition.class, attacher);
+ registry.attachToSource(source, pwsd, target, pwtd, wire);
+ EasyMock.verify(attacher);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testTargetAttachDispatch() throws Exception {
+ attacher.attachToTarget(source, pwsd, target, pwtd, wire);
+ EasyMock.replay(attacher);
+
+ registry.register(PhysicalWireTargetDefinition.class, attacher);
+ registry.attachToTarget(source, pwsd, target, pwtd, wire);
+ EasyMock.verify(attacher);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ source = EasyMock.createMock(Component.class);
+ EasyMock.replay(source);
+ target = EasyMock.createMock(Component.class);
+ EasyMock.replay(target);
+ wire = EasyMock.createMock(Wire.class);
+ EasyMock.replay(wire);
+ attacher = EasyMock.createMock(WireAttacher.class);
+
+ pwsd = new PhysicalWireSourceDefinition();
+ pwtd = new PhysicalWireTargetDefinition();
+ registry = new WireAttacherRegistryImpl();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/ComponentContextImplTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/ComponentContextImplTestCase.java
new file mode 100644
index 0000000000..8bd25d3a16
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/ComponentContextImplTestCase.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.core.component;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+import org.easymock.classextension.EasyMock;
+
+import org.apache.tuscany.core.implementation.PojoAtomicComponent;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ComponentContextImplTestCase extends TestCase {
+ private PojoAtomicComponent component;
+ private ComponentContextImpl context;
+
+ public void testURI() {
+ URI uri = URI.create("foo");
+ EasyMock.expect(component.getUri()).andReturn(uri);
+ EasyMock.replay(component);
+ assertEquals(uri.toString(), context.getURI());
+ EasyMock.verify(component);
+ }
+
+ public void testGetProperty() {
+ String name = "foo";
+ String value = "bar";
+ EasyMock.expect(component.getProperty(String.class, name)).andReturn(value);
+ EasyMock.replay(component);
+ assertSame(value, context.getProperty(String.class, name));
+ EasyMock.verify(component);
+ }
+
+ public void testGetPropertyThatIsIncompatible() {
+ String name = "foo";
+ EasyMock.expect(component.getProperty(Integer.class, name)).andThrow(new ClassCastException());
+ EasyMock.replay(component);
+ try {
+ context.getProperty(Integer.class, name);
+ fail();
+ } catch (ClassCastException e) {
+ // expected
+ }
+ EasyMock.verify(component);
+ }
+
+ public void testGetPropertyThatIsSubclass() {
+ String name = "foo";
+ String value = "bar";
+ EasyMock.expect(component.getProperty(Object.class, name)).andReturn(value);
+ EasyMock.replay(component);
+ assertSame(value, context.getProperty(Object.class, name));
+ EasyMock.verify(component);
+ }
+
+ public void testGetService() {
+ String name = "foo";
+ FooService service = EasyMock.createMock(FooService.class);
+ EasyMock.expect(component.getService(FooService.class, name)).andReturn(service);
+ EasyMock.replay(component);
+ assertSame(service, context.getService(FooService.class, name));
+ EasyMock.verify(component);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ component = EasyMock.createMock(PojoAtomicComponent.class);
+ context = new ComponentContextImpl(component);
+ }
+
+ public interface FooService {
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/ComponentManagerImplTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/ComponentManagerImplTestCase.java
new file mode 100644
index 0000000000..c1710e9b8e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/ComponentManagerImplTestCase.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.core.component;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.DuplicateNameException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ComponentManagerImplTestCase extends TestCase {
+ private static final URI DOMAIN = URI.create("sca://localhost/");
+ private static final URI ROOT1 = DOMAIN.resolve("root1");
+ private static final URI GRANDCHILD = DOMAIN.resolve("parent/child2/grandchild");
+
+ private ComponentManagerImpl manager;
+
+ public void testRegister() throws Exception {
+ Component root = EasyMock.createMock(Component.class);
+ EasyMock.expect(root.getUri()).andReturn(ROOT1);
+ EasyMock.replay(root);
+ manager.register(root);
+ assertEquals(root, manager.getComponent(ROOT1));
+ EasyMock.verify(root);
+
+ EasyMock.reset(root);
+ EasyMock.expect(root.getUri()).andReturn(ROOT1);
+ EasyMock.replay(root);
+ manager.unregister(root);
+ EasyMock.verify(root);
+ assertEquals(null, manager.getComponent(ROOT1));
+ }
+
+ public void testRegisterGrandchild() throws Exception {
+ Component root = EasyMock.createMock(Component.class);
+ EasyMock.expect(root.getUri()).andReturn(GRANDCHILD);
+ EasyMock.replay(root);
+ manager.register(root);
+ assertEquals(root, manager.getComponent(GRANDCHILD));
+ EasyMock.verify(root);
+ }
+
+ public void testRegisterDuplicate() throws Exception {
+ Component root = EasyMock.createMock(Component.class);
+ EasyMock.expect(root.getUri()).andReturn(ROOT1);
+ EasyMock.replay(root);
+
+ Component duplicate = EasyMock.createMock(Component.class);
+ EasyMock.expect(duplicate.getUri()).andReturn(ROOT1);
+ EasyMock.replay(duplicate);
+
+ manager.register(root);
+ assertEquals(root, manager.getComponent(ROOT1));
+ try {
+ manager.register(duplicate);
+ fail();
+ } catch (DuplicateNameException e) {
+ // expected
+ }
+ assertEquals(root, manager.getComponent(ROOT1));
+ EasyMock.verify(root);
+ EasyMock.verify(duplicate);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ manager = new ComponentManagerImpl();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/JavaObjectRegistrationTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/JavaObjectRegistrationTestCase.java
new file mode 100644
index 0000000000..2d00a13716
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/JavaObjectRegistrationTestCase.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.core.component;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ComponentManager;
+import org.apache.tuscany.spi.component.DuplicateNameException;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaObjectRegistrationTestCase extends TestCase {
+ private ComponentManager componentManager;
+
+ public void testRegistration() throws Exception {
+ MockComponent instance = new MockComponent();
+ URI uri = URI.create("foo");
+ JavaServiceContract<MockComponent> contract = new JavaServiceContract<MockComponent>(MockComponent.class) {
+ };
+ componentManager.registerJavaObject(uri, contract, instance);
+ Component component = componentManager.getComponent(URI.create("foo"));
+ assertTrue(component instanceof AtomicComponent);
+ MockComponent resolvedInstance = (MockComponent) ((AtomicComponent) component).getTargetInstance();
+ assertSame(instance, resolvedInstance);
+ }
+
+ public void testDuplicateRegistration() throws Exception {
+ MockComponent instance = new MockComponent();
+ URI uri = URI.create("foo");
+ JavaServiceContract<MockComponent> contract = new JavaServiceContract<MockComponent>(MockComponent.class) {
+ };
+ componentManager.registerJavaObject(uri, contract, instance);
+ try {
+ componentManager.registerJavaObject(uri, contract, instance);
+ fail();
+ } catch (DuplicateNameException e) {
+ // ok
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ componentManager = new ComponentManagerImpl();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ private static class MockComponent {
+ public String hello(String message) {
+ return message;
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/ReflectiveInstanceFactoryProviderTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/ReflectiveInstanceFactoryProviderTestCase.java
new file mode 100644
index 0000000000..b0854e65ce
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/ReflectiveInstanceFactoryProviderTestCase.java
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+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 junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+import org.apache.tuscany.core.injection.FieldInjector;
+import org.apache.tuscany.core.injection.Injector;
+import org.apache.tuscany.core.injection.MethodInjector;
+import org.apache.tuscany.core.model.physical.instancefactory.InjectionSource;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.TargetInitializationException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReflectiveInstanceFactoryProviderTestCase extends TestCase {
+ private Constructor<Foo> argConstructor;
+ private List<InjectionSource> ctrNames;
+ private Map<InjectionSource, Member> sites;
+ private ObjectFactory intFactory;
+ private ObjectFactory stringFactory;
+ private ReflectiveInstanceFactoryProvider<Foo> provider;
+ private Field intField;
+ private Field stringField;
+ private Method intSetter;
+ private Method stringSetter;
+ private InjectionSource intProperty = new InjectionSource(InjectionSource.ValueSourceType.PROPERTY, "int");
+ private InjectionSource stringProperty = new InjectionSource(InjectionSource.ValueSourceType.PROPERTY, "string");
+
+ public void testNoConstructorArgs() {
+ ObjectFactory<?>[] args = provider.getConstructorArgs();
+ assertEquals(0, args.length);
+ }
+
+ public void testConstructorArgs() {
+ ctrNames.add(intProperty);
+ ctrNames.add(stringProperty);
+ provider = new ReflectiveInstanceFactoryProvider<Foo>(argConstructor,
+ ctrNames,
+ sites,
+ null,
+ null);
+ provider.setObjectFactory(intProperty, intFactory);
+ provider.setObjectFactory(stringProperty, stringFactory);
+ ObjectFactory<?>[] args = provider.getConstructorArgs();
+ assertEquals(2, args.length);
+ assertSame(intFactory, args[0]);
+ assertSame(stringFactory, args[1]);
+ }
+
+ public void testFieldInjectors() {
+ sites.put(intProperty, intField);
+ sites.put(stringProperty, stringField);
+ Injector<Foo>[] injectors = provider.getInjectors();
+ assertEquals(2, injectors.length);
+
+ Foo foo = new Foo();
+ for (Injector<Foo> injector : injectors) {
+ assertTrue(injector instanceof FieldInjector);
+ injector.inject(foo);
+ }
+ EasyMock.verify(intFactory, stringFactory);
+ assertEquals(34, foo.intField);
+ assertEquals("Hello", foo.stringField);
+ }
+
+ public void testMethodInjectors() {
+ sites.put(intProperty, intSetter);
+ sites.put(stringProperty, stringSetter);
+ Injector<Foo>[] injectors = provider.getInjectors();
+ assertEquals(2, injectors.length);
+
+ Foo foo = new Foo();
+ for (Injector<Foo> injector : injectors) {
+ assertTrue(injector instanceof MethodInjector);
+ injector.inject(foo);
+ }
+ EasyMock.verify(intFactory, stringFactory);
+ assertEquals(34, foo.intField);
+ assertEquals("Hello", foo.stringField);
+ }
+
+ public void testFactory() {
+ sites.put(intProperty, intSetter);
+ sites.put(stringProperty, stringField);
+ InstanceFactory<Foo> instanceFactory = provider.createFactory();
+ InstanceWrapper<Foo> instanceWrapper = instanceFactory.newInstance();
+ try {
+ instanceWrapper.start();
+ } catch (TargetInitializationException e) {
+ fail();
+ }
+ Foo foo = instanceWrapper.getInstance();
+ EasyMock.verify(intFactory, stringFactory);
+ assertEquals(34, foo.intField);
+ assertEquals("Hello", foo.stringField);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+ Constructor<Foo> noArgConstructor = Foo.class.getConstructor();
+ argConstructor = Foo.class.getConstructor(int.class, String.class);
+ intField = Foo.class.getField("intField");
+ stringField = Foo.class.getField("stringField");
+ intSetter = Foo.class.getMethod("setIntField", int.class);
+ stringSetter = Foo.class.getMethod("setStringField", String.class);
+ ctrNames = new ArrayList<InjectionSource>();
+ sites = new HashMap<InjectionSource, Member>();
+ provider = new ReflectiveInstanceFactoryProvider<Foo>(noArgConstructor,
+ ctrNames,
+ sites,
+ null,
+ null);
+ intFactory = EasyMock.createMock(ObjectFactory.class);
+ stringFactory = EasyMock.createMock(ObjectFactory.class);
+ EasyMock.expect(intFactory.getInstance()).andReturn(34);
+ EasyMock.expect(stringFactory.getInstance()).andReturn("Hello");
+ EasyMock.replay(intFactory, stringFactory);
+
+ provider.setObjectFactory(intProperty, intFactory);
+ provider.setObjectFactory(stringProperty, stringFactory);
+ }
+
+ public static class Foo {
+ public int intField;
+ public String stringField;
+
+ public Foo() {
+ }
+
+ public Foo(int intField, String stringField) {
+ this.intField = intField;
+ this.stringField = stringField;
+ }
+
+ public void setIntField(int intField) {
+ this.intField = intField;
+ }
+
+ public void setStringField(String stringField) {
+ this.stringField = stringField;
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/SystemSingletonAtomicComponentTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/SystemSingletonAtomicComponentTestCase.java
new file mode 100644
index 0000000000..fac45ebfb5
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/SystemSingletonAtomicComponentTestCase.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.core.component;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.spi.component.TargetException;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SystemSingletonAtomicComponentTestCase extends TestCase {
+
+ public void testGetInstance() throws TargetException {
+ JavaServiceContract<Foo> contract = new JavaServiceContract<Foo>(Foo.class) {
+
+ };
+ FooImpl foo = new FooImpl();
+ SystemSingletonAtomicComponent<Foo, FooImpl> component =
+ new SystemSingletonAtomicComponent<Foo, FooImpl>(URI.create("foo"), contract, foo);
+ assertEquals(foo, component.getTargetInstance());
+ }
+
+ public void testGetInstanceMultipleServices() throws TargetException {
+ FooImpl foo = new FooImpl();
+ List<JavaServiceContract<?>> services = new ArrayList<JavaServiceContract<?>>();
+ services.add(new JavaServiceContract<Foo>(Foo.class) {
+ });
+ services.add(new JavaServiceContract<Bar>(Bar.class) {
+ });
+ SystemSingletonAtomicComponent<Foo, FooImpl> component =
+ new SystemSingletonAtomicComponent<Foo, FooImpl>(URI.create("foo"), services, foo);
+ assertEquals(foo, component.getTargetInstance());
+ }
+
+ public void testOptimizable() {
+ JavaServiceContract<Foo> contract = new JavaServiceContract<Foo>(Foo.class) {
+ };
+ FooImpl foo = new FooImpl();
+ SystemSingletonAtomicComponent<Foo, FooImpl> component =
+ new SystemSingletonAtomicComponent<Foo, FooImpl>(URI.create("foo"), contract, foo);
+ assertTrue(component.isOptimizable());
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ private interface Foo {
+
+ }
+
+ private interface Bar {
+
+ }
+
+ private class FooImpl implements Foo, Bar {
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/WorkContextImplTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/WorkContextImplTestCase.java
new file mode 100644
index 0000000000..aee910ddaf
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/WorkContextImplTestCase.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.core.component;
+
+import org.apache.tuscany.spi.component.WorkContext;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WorkContextImplTestCase extends TestCase {
+
+ public void testPushPopServiceNames() throws Exception {
+ WorkContext context = new WorkContextImpl();
+ context.pushServiceName("foo");
+ context.pushServiceName("bar");
+ assertEquals("bar", context.getCurrentServiceName());
+ assertEquals("bar", context.popServiceName());
+ assertEquals("foo", context.getCurrentServiceName());
+ assertEquals("foo", context.popServiceName());
+ assertNull(context.getCurrentServiceName());
+ }
+
+ public void testGetCurrentServiceNamesNull() throws Exception {
+ WorkContext context = new WorkContextImpl();
+ assertNull(context.getCurrentServiceName());
+ }
+
+ public void testPopCurrentServiceNamesNull() throws Exception {
+ WorkContext context = new WorkContextImpl();
+ assertNull(context.popServiceName());
+ }
+
+ public void testClearServiceNames() throws Exception {
+ WorkContext context = new WorkContextImpl();
+ context.pushServiceName("foo");
+ context.pushServiceName("bar");
+ context.clearServiceNames();
+ assertNull(context.getCurrentServiceName());
+ }
+
+ public void testClearServiceNamesNull() throws Exception {
+ WorkContext context = new WorkContextImpl();
+ context.clearServiceNames();
+ assertNull(context.getCurrentServiceName());
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java
new file mode 100644
index 0000000000..93cb50ddcb
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/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.core.component.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();
+ HttpSessionEvent event = new HttpSessionStart(this, id);
+ assertEquals(this, event.getSource());
+ assertEquals(id, event.getId());
+ }
+
+ public void testHttpSessionEnd() {
+ Object id = new Object();
+ HttpSessionEvent event = new HttpSessionEnd(this, id);
+ assertEquals(this, event.getSource());
+ assertEquals(id, event.getId());
+ }
+
+ 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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/instancefactory/impl/Bar.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/instancefactory/impl/Bar.java
new file mode 100644
index 0000000000..b5ca39abff
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/instancefactory/impl/Bar.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.core.component.instancefactory.impl;
+
+/**
+ *
+ * @version $Date$ $Revision$
+ *
+ */
+public class Bar {
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/instancefactory/impl/Foo.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/instancefactory/impl/Foo.java
new file mode 100644
index 0000000000..71c38d1aff
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/instancefactory/impl/Foo.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.core.component.instancefactory.impl;
+
+/**
+ *
+ * @version $Date$ $Revision$
+ *
+ */
+public class Foo {
+
+ protected Bar xyz;
+
+ public void setAbc(Bar abc) {
+ }
+
+ public Foo(String a, Long b) {
+ }
+
+ public void init() {
+ }
+
+ public void destroy() {
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/instancefactory/impl/ReflectiveIFProviderBuilderTest.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/instancefactory/impl/ReflectiveIFProviderBuilderTest.java
new file mode 100644
index 0000000000..4d88bcf48f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/instancefactory/impl/ReflectiveIFProviderBuilderTest.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.core.component.instancefactory.impl;
+
+import java.lang.annotation.ElementType;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.component.ReflectiveInstanceFactoryProvider;
+import org.apache.tuscany.core.model.physical.instancefactory.InjectionSiteMapping;
+import org.apache.tuscany.core.model.physical.instancefactory.InjectionSource;
+import org.apache.tuscany.core.model.physical.instancefactory.MemberSite;
+import org.apache.tuscany.core.model.physical.instancefactory.ReflectiveIFProviderDefinition;
+import org.apache.tuscany.core.model.physical.instancefactory.InjectionSource.ValueSourceType;
+
+/**
+ *
+ * @version $Date$ $Revision$
+ *
+ */
+public class ReflectiveIFProviderBuilderTest extends TestCase {
+
+ public void testBuild() throws Exception {
+
+ ReflectiveIFProviderDefinition def = new ReflectiveIFProviderDefinition();
+
+ def.setImplementationClass("org.apache.tuscany.core.component.instancefactory.impl.Foo");
+ def.setDestroyMethod("destroy");
+ def.setInitMethod("init");
+
+ def.addConstructorArgument("java.lang.String");
+ def.addConstructorArgument("java.lang.Long");
+
+ InjectionSource cdiSource = new InjectionSource();
+ cdiSource.setName("abc");
+ cdiSource.setValueType(ValueSourceType.REFERENCE);
+ def.addCdiSource(cdiSource);
+
+ InjectionSiteMapping injectionSite = new InjectionSiteMapping();
+ InjectionSource injectionSource = new InjectionSource();
+ injectionSource.setName("xyz");
+ injectionSource.setValueType(ValueSourceType.PROPERTY);
+ MemberSite memberSite = new MemberSite();
+ memberSite.setName("xyz");
+ memberSite.setElementType(ElementType.FIELD);
+ injectionSite.setSite(memberSite);
+ injectionSite.setSource(injectionSource);
+ def.addInjectionSite(injectionSite);
+
+ injectionSite = new InjectionSiteMapping();
+ injectionSource = new InjectionSource();
+ injectionSource.setName("abc");
+ injectionSource.setValueType(ValueSourceType.CALLBACK);
+ memberSite = new MemberSite();
+ memberSite.setName("abc");
+ memberSite.setElementType(ElementType.METHOD);
+ injectionSite.setSite(memberSite);
+ injectionSite.setSource(injectionSource);
+ def.addInjectionSite(injectionSite);
+
+ ReflectiveIFProviderBuilder builder = new ReflectiveIFProviderBuilder();
+ ClassLoader cl = getClass().getClassLoader();
+
+
+ ReflectiveInstanceFactoryProvider provider = builder.build(def, cl);
+ assertNotNull(provider);
+
+ Class<?> clazz = provider.getMemberType(injectionSource);
+ assertNotNull(clazz);
+ assertEquals(Bar.class, clazz);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java
new file mode 100644
index 0000000000..a6e4de3c48
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.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.core.component.scope;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractScopeContainerTestCase<T, KEY> extends TestCase {
+ protected IMocksControl control;
+ protected ScopeContainer<KEY> scopeContainer;
+ protected URI groupId;
+ protected KEY contextId;
+ protected AtomicComponent<T> component;
+ protected InstanceWrapper<T> wrapper;
+
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+ control = EasyMock.createStrictControl();
+ component = control.createMock(AtomicComponent.class);
+ wrapper = control.createMock(InstanceWrapper.class);
+ }
+
+ protected void preRegisterComponent() throws Exception {
+ scopeContainer.start();
+ scopeContainer.register(component, groupId);
+ EasyMock.expect(component.isEagerInit()).andStubReturn(false);
+ }
+
+ protected void expectCreateWrapper() throws Exception {
+ EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper);
+ wrapper.start();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicCompositeScopeTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicCompositeScopeTestCase.java
new file mode 100644
index 0000000000..cb66af27b0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicCompositeScopeTestCase.java
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.component.scope;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.model.Scope;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public class BasicCompositeScopeTestCase<T> extends TestCase {
+ protected IMocksControl control;
+ protected ScopeContainer<URI> scopeContainer;
+ protected URI groupId;
+ protected URI contextId;
+ protected AtomicComponent<T> component;
+ protected InstanceWrapper<T> wrapper;
+
+ public void testCorrectScope() {
+ assertEquals(Scope.COMPOSITE, scopeContainer.getScope());
+ }
+
+ public void testWrapperCreation() throws Exception {
+ EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper);
+ wrapper.start();
+ control.replay();
+ scopeContainer.register(component, groupId);
+ assertSame(wrapper, scopeContainer.getWrapper(component, contextId));
+ assertSame(wrapper, scopeContainer.getWrapper(component, contextId));
+ assertSame(wrapper, scopeContainer.getAssociatedWrapper(component, contextId));
+ control.verify();
+ }
+
+ public void testGetAssociatedInstanceNonExistent() throws Exception {
+ URI uri = URI.create("oops");
+ EasyMock.expect(component.getUri()).andReturn(uri);
+ control.replay();
+ scopeContainer.register(component, groupId);
+ try {
+ scopeContainer.getAssociatedWrapper(component, contextId);
+ fail();
+ } catch (TargetResolutionException e) {
+ assertEquals(uri.toString(), e.getMessage());
+ }
+ control.verify();
+ }
+
+ /*
+ public void testLifecycleWithNoEagerInit() throws Exception {
+ EasyMock.expect(component.getInitLevel()).andReturn(0);
+ control.replay();
+ scopeContainer.startContext(contextId, groupId);
+ scopeContainer.stopContext(contextId);
+ control.verify();
+ }
+
+ public void testLifecycleWithEagerInit() throws Exception {
+ EasyMock.expect(component.getInitLevel()).andReturn(1);
+ EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper);
+ wrapper.start();
+ wrapper.stop();
+ EasyMock.replay(component, wrapper);
+ scopeContainer.onEvent(new ComponentStart(this, null));
+ scopeContainer.onEvent(new ComponentStop(this, null));
+ EasyMock.verify(component, wrapper);
+ }
+
+ public void testDestroyOrder() throws Exception {
+ scopeContainer = new CompositeScopeContainer(null);
+ scopeContainer.start();
+ IMocksControl control = EasyMock.createStrictControl();
+ InstanceWrapper wrapper1 = control.createMock(InstanceWrapper.class);
+ InstanceWrapper wrapper2 = control.createMock(InstanceWrapper.class);
+ InstanceWrapper wrapper3 = control.createMock(InstanceWrapper.class);
+ AtomicComponent component1 = control.createMock(AtomicComponent.class);
+ AtomicComponent component2 = control.createMock(AtomicComponent.class);
+ AtomicComponent component3 = control.createMock(AtomicComponent.class);
+
+ EasyMock.expect(component1.getInitLevel()).andStubReturn(-1);
+ EasyMock.expect(component2.getInitLevel()).andStubReturn(1);
+ EasyMock.expect(component3.getInitLevel()).andStubReturn(-1);
+
+ EasyMock.expect(component2.createInstanceWrapper()).andReturn(wrapper2);
+ wrapper2.start();
+ EasyMock.expect(component1.createInstanceWrapper()).andReturn(wrapper1);
+ wrapper1.start();
+ EasyMock.expect(component3.createInstanceWrapper()).andReturn(wrapper3);
+ wrapper3.start();
+ wrapper3.stop();
+ wrapper1.stop();
+ wrapper2.stop();
+ control.replay();
+
+ scopeContainer.register(component1, contextId);
+ scopeContainer.register(component2, contextId);
+ scopeContainer.register(component3, contextId);
+ scopeContainer.onEvent(new ComponentStart(this, null));
+ assertSame(wrapper1, scopeContainer.getWrapper(component1));
+ assertSame(wrapper2, scopeContainer.getWrapper(component2));
+ assertSame(wrapper3, scopeContainer.getWrapper(component3));
+ scopeContainer.onEvent(new ComponentStop(this, null));
+ control.verify();
+ }
+ */
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+ groupId = contextId = URI.create("compositeId");
+ control = EasyMock.createStrictControl();
+ component = control.createMock(AtomicComponent.class);
+ EasyMock.expect(component.isEagerInit()).andStubReturn(false);
+ wrapper = control.createMock(InstanceWrapper.class);
+
+ scopeContainer = new CompositeScopeContainer<URI>(null);
+ scopeContainer.start();
+ scopeContainer.startContext(contextId, groupId);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicConversationalScopeTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicConversationalScopeTestCase.java
new file mode 100644
index 0000000000..2b8c83c959
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicConversationalScopeTestCase.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.core.component.scope;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.services.store.StoreMonitor;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.services.store.memory.MemoryStore;
+import org.easymock.EasyMock;
+
+/**
+ * @version $$Rev: 471111 $$ $$Date: 2006-11-03 23:06:48 -0500 (Fri, 03 Nov 2006) $$
+ */
+public class BasicConversationalScopeTestCase extends TestCase {
+ private AtomicComponent component;
+ private InstanceWrapper wrapper;
+ private ScopeContainer scopeContainer;
+ private WorkContext workContext;
+
+/*
+ public void testLifecycleManagement() throws Exception {
+ // start the request
+ String conversation = "conv";
+ workContext.setIdentifier(Scope.CONVERSATION, conversation);
+
+ EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper);
+ wrapper.start();
+ // FIXME shouldn't stop be called when the component is removed?
+// wrapper.stop();
+ EasyMock.replay(component, wrapper);
+ assertSame(wrapper, scopeContainer.getWrapper(component));
+ assertSame(wrapper, scopeContainer.getWrapper(component));
+ scopeContainer.remove(component);
+ EasyMock.verify(component, wrapper);
+ }
+*/
+
+/*
+ public void testCoversationIsolation() throws Exception {
+ String conversation1 = "conv";
+ String conversation2 = "conv2";
+
+ InstanceWrapper wrapper2 = EasyMock.createStrictMock(InstanceWrapper.class);
+ EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper);
+ wrapper.start();
+ EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper2);
+ wrapper2.start();
+ EasyMock.replay(component, wrapper, wrapper2);
+ workContext.setIdentifier(Scope.CONVERSATION, conversation1);
+ assertSame(wrapper, scopeContainer.getWrapper(component));
+ workContext.setIdentifier(Scope.CONVERSATION, conversation2);
+ assertSame(wrapper2, scopeContainer.getWrapper(component));
+ EasyMock.verify(component, wrapper);
+ }
+*/
+ public void testX() {
+}
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ component = EasyMock.createStrictMock(AtomicComponent.class);
+ EasyMock.expect(component.getMaxAge()).andStubReturn(-1);
+ EasyMock.expect(component.getMaxIdleTime()).andStubReturn(-1);
+ wrapper = EasyMock.createStrictMock(InstanceWrapper.class);
+
+ StoreMonitor monitor = EasyMock.createMock(StoreMonitor.class);
+ monitor.start(EasyMock.isA(String.class));
+ monitor.stop(EasyMock.isA(String.class));
+ MemoryStore store = new MemoryStore(monitor);
+ workContext = new WorkContextImpl();
+ scopeContainer = new ConversationalScopeContainer(store, workContext, null);
+ scopeContainer.start();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicHttpSessionScopeTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicHttpSessionScopeTestCase.java
new file mode 100644
index 0000000000..2408aae6d7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicHttpSessionScopeTestCase.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.core.component.scope;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeContainerMonitor;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public abstract class BasicHttpSessionScopeTestCase extends TestCase {
+ private ScopeContainerMonitor monitor;
+ private ScopeContainer scopeContainer;
+ private AtomicComponent component;
+ private InstanceWrapper wrapper;
+ private WorkContext workContext;
+
+ public void testLifecycleManagement() throws Exception {
+/*
+ // start the request
+ Object session = new Object();
+ workContext.setIdentifier(Scope.SESSION, session);
+
+ EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper);
+ wrapper.start();
+ wrapper.stop();
+ EasyMock.replay(component, wrapper);
+ assertSame(wrapper, scopeContainer.getWrapper(component));
+ assertSame(wrapper, scopeContainer.getWrapper(component));
+ scopeContainer.onEvent(new HttpSessionEnd(this, session));
+ EasyMock.verify(component, wrapper);
+*/
+ }
+
+ public void testGetAssociatedInstance() throws Exception {
+/*
+ // start the request
+ Object session = new Object();
+ workContext.setIdentifier(Scope.SESSION, session);
+
+ EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper);
+ wrapper.start();
+ EasyMock.replay(component, wrapper);
+ assertSame(wrapper, scopeContainer.getWrapper(component));
+ assertSame(wrapper, scopeContainer.getAssociatedWrapper(component));
+ EasyMock.verify(component, wrapper);
+*/
+ }
+
+ public void testGetAssociatedInstanceNonExistent() throws Exception {
+/*
+ URI id = URI.create("oops");
+ EasyMock.expect(component.getUri()).andReturn(id);
+ EasyMock.replay(component);
+
+ // start the request
+ Object session = new Object();
+ workContext.setIdentifier(Scope.SESSION, session);
+ try {
+ scopeContainer.getAssociatedWrapper(component);
+ fail();
+ } catch (TargetNotFoundException e) {
+ assertEquals(id.toString(), e.getMessage());
+ EasyMock.verify(component);
+ }
+*/
+ }
+
+ public void testSessionIsolation() throws Exception {
+/*
+ // start the request
+ Object session1 = new Object();
+ Object session2 = new Object();
+
+ InstanceWrapper wrapper2 = EasyMock.createNiceMock(InstanceWrapper.class);
+ EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper);
+ wrapper.start();
+ EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper2);
+ wrapper2.start();
+ EasyMock.replay(component, wrapper);
+ workContext.setIdentifier(Scope.SESSION, session1);
+ assertSame(wrapper, scopeContainer.getWrapper(component));
+ assertSame(wrapper, scopeContainer.getAssociatedWrapper(component));
+ workContext.setIdentifier(Scope.SESSION, session2);
+ assertSame(wrapper2, scopeContainer.getWrapper(component));
+ assertSame(wrapper2, scopeContainer.getAssociatedWrapper(component));
+ workContext.setIdentifier(Scope.SESSION, session1);
+ assertSame(wrapper, scopeContainer.getWrapper(component));
+ EasyMock.verify(component, wrapper);
+*/
+ }
+
+ public void testDestroyErrorMonitor() throws Exception {
+/*
+ TargetDestructionException ex = new TargetDestructionException("oops", "again");
+ monitor.destructionError(ex);
+ EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper);
+ wrapper.start();
+ wrapper.stop();
+ EasyMock.expectLastCall().andThrow(ex);
+ EasyMock.replay(component, wrapper, monitor);
+
+ Object id = new Object();
+ scopeContainer.onEvent(new HttpSessionStart(this, id));
+ workContext.setIdentifier(Scope.SESSION, id);
+ assertSame(wrapper, scopeContainer.getWrapper(component));
+ scopeContainer.onEvent(new HttpSessionEnd(this, id));
+ EasyMock.verify(component, wrapper, monitor);
+*/
+ }
+
+ public void testDestroyOrder() throws Exception {
+/*
+ Object session = new Object();
+ workContext.setIdentifier(Scope.SESSION, session);
+
+ IMocksControl control = EasyMock.createStrictControl();
+ InstanceWrapper wrapper1 = control.createMock(InstanceWrapper.class);
+ InstanceWrapper wrapper2 = control.createMock(InstanceWrapper.class);
+ InstanceWrapper wrapper3 = control.createMock(InstanceWrapper.class);
+ AtomicComponent component1 = control.createMock(AtomicComponent.class);
+ AtomicComponent component2 = control.createMock(AtomicComponent.class);
+ AtomicComponent component3 = control.createMock(AtomicComponent.class);
+
+ component1.addListener(scopeContainer);
+ component2.addListener(scopeContainer);
+ component3.addListener(scopeContainer);
+ EasyMock.expect(component1.createInstanceWrapper()).andReturn(wrapper1);
+ wrapper1.start();
+ EasyMock.expect(component2.createInstanceWrapper()).andReturn(wrapper2);
+ wrapper2.start();
+ EasyMock.expect(component3.createInstanceWrapper()).andReturn(wrapper3);
+ wrapper3.start();
+ wrapper3.stop();
+ wrapper2.stop();
+ wrapper1.stop();
+ control.replay();
+
+ scopeContainer.register(component1, null);
+ scopeContainer.register(component2, null);
+ scopeContainer.register(component3, null);
+ scopeContainer.onEvent(new HttpSessionStart(this, session));
+ assertSame(wrapper1, scopeContainer.getWrapper(component1));
+ assertSame(wrapper2, scopeContainer.getWrapper(component2));
+ assertSame(wrapper3, scopeContainer.getWrapper(component3));
+ scopeContainer.onEvent(new HttpSessionEnd(this, session));
+ control.verify();
+*/
+ }
+
+ public void testReuseSession() throws Exception {
+/*
+ Object session = new Object();
+ workContext.setIdentifier(Scope.SESSION, session);
+
+ IMocksControl control = EasyMock.createStrictControl();
+ InstanceWrapper wrapper1 = control.createMock(InstanceWrapper.class);
+ InstanceWrapper wrapper2 = control.createMock(InstanceWrapper.class);
+ AtomicComponent component1 = control.createMock(AtomicComponent.class);
+
+ component1.addListener(scopeContainer);
+ EasyMock.expect(component1.createInstanceWrapper()).andReturn(wrapper1);
+ wrapper1.start();
+ wrapper1.stop();
+ EasyMock.expect(component1.createInstanceWrapper()).andReturn(wrapper2);
+ wrapper2.start();
+ wrapper2.stop();
+ control.replay();
+
+ scopeContainer.register(component1, null);
+ scopeContainer.onEvent(new HttpSessionStart(this, session));
+ assertSame(wrapper1, scopeContainer.getWrapper(component1));
+ scopeContainer.onEvent(new HttpSessionEnd(this, session));
+
+ scopeContainer.onEvent(new HttpSessionStart(this, session));
+ assertSame(wrapper2, scopeContainer.getWrapper(component1));
+ scopeContainer.onEvent(new HttpSessionEnd(this, session));
+ control.verify();
+*/
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ component = EasyMock.createStrictMock(AtomicComponent.class);
+ wrapper = EasyMock.createStrictMock(InstanceWrapper.class);
+
+ workContext = new WorkContextImpl();
+ monitor = EasyMock.createStrictMock(ScopeContainerMonitor.class);
+ scopeContainer = new HttpSessionScopeContainer(workContext, monitor);
+ scopeContainer.start();
+
+ component.addListener(scopeContainer);
+ EasyMock.replay(component);
+ scopeContainer.register(component, null);
+ EasyMock.reset(component);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicRequestScopeTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicRequestScopeTestCase.java
new file mode 100644
index 0000000000..4aad2dc0c6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicRequestScopeTestCase.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.core.component.scope;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeContainerMonitor;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public abstract class BasicRequestScopeTestCase extends TestCase {
+ private ScopeContainerMonitor monitor;
+ private ScopeContainer scopeContainer;
+ private AtomicComponent component;
+ private InstanceWrapper wrapper;
+
+ public void testLifecycleManagement() throws Exception {
+/*
+ EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper);
+ wrapper.start();
+ EasyMock.replay(component, wrapper);
+ assertSame(wrapper, scopeContainer.getWrapper(component));
+ assertSame(wrapper, scopeContainer.getWrapper(component));
+ EasyMock.verify(component, wrapper);
+*/
+ }
+
+ public void testGetAssociatedInstance() throws Exception {
+/*
+ EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper);
+ wrapper.start();
+ EasyMock.replay(component, wrapper);
+ assertSame(wrapper, scopeContainer.getWrapper(component));
+ assertSame(wrapper, scopeContainer.getAssociatedWrapper(component));
+ EasyMock.verify(component, wrapper);
+*/
+ }
+
+ public void testGetAssociatedInstanceNonExistent() throws Exception {
+/*
+ URI id = URI.create("oops");
+ EasyMock.expect(component.getUri()).andReturn(id);
+ EasyMock.replay(component);
+
+ try {
+ scopeContainer.getAssociatedWrapper(component);
+ fail();
+ } catch (TargetNotFoundException e) {
+ assertEquals(id.toString(), e.getMessage());
+ EasyMock.verify(component);
+ }
+*/
+ }
+
+ public void testRequestIsolation() throws Exception {
+/*
+ IMocksControl control = EasyMock.createStrictControl();
+ InstanceWrapper wrapper1 = control.createMock(InstanceWrapper.class);
+ InstanceWrapper wrapper2 = control.createMock(InstanceWrapper.class);
+ AtomicComponent component1 = control.createMock(AtomicComponent.class);
+ AtomicComponent component2 = control.createMock(AtomicComponent.class);
+
+ EasyMock.expect(component1.createInstanceWrapper()).andReturn(wrapper1);
+ wrapper1.start();
+ wrapper1.stop();
+ EasyMock.expect(component2.createInstanceWrapper()).andReturn(wrapper2);
+ wrapper2.start();
+ wrapper2.stop();
+ control.replay();
+
+ scopeContainer.register(component1, null);
+ scopeContainer.register(component2, null);
+ scopeContainer.onEvent(new RequestStart(this));
+ assertSame(wrapper1, scopeContainer.getWrapper(component1));
+ scopeContainer.onEvent(new RequestEnd(this));
+ scopeContainer.onEvent(new RequestStart(this));
+ assertSame(wrapper2, scopeContainer.getWrapper(component2));
+ scopeContainer.onEvent(new RequestEnd(this));
+ control.verify();
+*/
+ }
+
+ public void testDestroyErrorMonitor() throws Exception {
+/*
+ TargetDestructionException ex = new TargetDestructionException("oops", "again");
+ monitor.destructionError(ex);
+ EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper);
+ wrapper.start();
+ wrapper.stop();
+ EasyMock.expectLastCall().andThrow(ex);
+ EasyMock.replay(component, wrapper, monitor);
+
+ scopeContainer.onEvent(new RequestStart(this));
+ assertSame(wrapper, scopeContainer.getWrapper(component));
+ scopeContainer.onEvent(new RequestEnd(this));
+ EasyMock.verify(component, wrapper, monitor);
+*/
+ }
+
+ public void testDestroyOrder() throws Exception {
+/*
+ IMocksControl control = EasyMock.createStrictControl();
+ InstanceWrapper wrapper1 = control.createMock(InstanceWrapper.class);
+ InstanceWrapper wrapper2 = control.createMock(InstanceWrapper.class);
+ InstanceWrapper wrapper3 = control.createMock(InstanceWrapper.class);
+ AtomicComponent component1 = control.createMock(AtomicComponent.class);
+ AtomicComponent component2 = control.createMock(AtomicComponent.class);
+ AtomicComponent component3 = control.createMock(AtomicComponent.class);
+
+ EasyMock.expect(component1.createInstanceWrapper()).andReturn(wrapper1);
+ wrapper1.start();
+ EasyMock.expect(component2.createInstanceWrapper()).andReturn(wrapper2);
+ wrapper2.start();
+ EasyMock.expect(component3.createInstanceWrapper()).andReturn(wrapper3);
+ wrapper3.start();
+ wrapper3.stop();
+ wrapper2.stop();
+ wrapper1.stop();
+ control.replay();
+
+ scopeContainer.register(component1, null);
+ scopeContainer.register(component2, null);
+ scopeContainer.register(component3, null);
+ scopeContainer.onEvent(new RequestStart(this));
+ assertSame(wrapper1, scopeContainer.getWrapper(component1));
+ assertSame(wrapper2, scopeContainer.getWrapper(component2));
+ assertSame(wrapper3, scopeContainer.getWrapper(component3));
+ scopeContainer.onEvent(new RequestEnd(this));
+ control.verify();
+*/
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ component = EasyMock.createStrictMock(AtomicComponent.class);
+ wrapper = EasyMock.createStrictMock(InstanceWrapper.class);
+ monitor = EasyMock.createStrictMock(ScopeContainerMonitor.class);
+ scopeContainer = new RequestScopeContainer(monitor);
+ scopeContainer.start();
+
+ component.addListener(scopeContainer);
+ EasyMock.replay(component);
+ scopeContainer.register(component, null);
+ EasyMock.reset(component);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicStatelessScopeTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicStatelessScopeTestCase.java
new file mode 100644
index 0000000000..a7cab71ade
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicStatelessScopeTestCase.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.core.component.scope;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.model.Scope;
+
+/**
+ * Unit tests for the composite scope container
+ *
+ * @version $Rev$ $Date$
+ */
+public class BasicStatelessScopeTestCase<T> extends TestCase {
+ private StatelessScopeContainer<String> scopeContainer;
+ private String contextId;
+ private IMocksControl control;
+ private AtomicComponent<T> component;
+ private InstanceWrapper<T> wrapper;
+
+ public void testCorrectScope() {
+ assertEquals(Scope.STATELESS, scopeContainer.getScope());
+ }
+
+ public void testInstanceCreation() throws Exception {
+ @SuppressWarnings("unchecked")
+ InstanceWrapper<T> wrapper2 = control.createMock(InstanceWrapper.class);
+
+ EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper);
+ wrapper.start();
+ EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper2);
+ wrapper2.start();
+ control.replay();
+
+ assertSame(wrapper, scopeContainer.getWrapper(component, contextId));
+ assertSame(wrapper2, scopeContainer.getWrapper(component, contextId));
+ control.verify();
+ }
+
+ public void testGetAssociatedInstance() throws Exception {
+ control.replay();
+ try {
+ // always throws an exception, which is the semantic for stateless implementations
+ scopeContainer.getAssociatedWrapper(component, contextId);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // ok
+ }
+ control.verify();
+ }
+
+ public void testReturnWrapper() throws Exception {
+ wrapper.stop();
+ control.replay();
+ scopeContainer.returnWrapper(component, wrapper, contextId);
+ control.verify();
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+ scopeContainer = new StatelessScopeContainer<String>(null);
+ contextId = "context";
+
+ control = EasyMock.createStrictControl();
+ component = control.createMock(AtomicComponent.class);
+ wrapper = control.createMock(InstanceWrapper.class);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInitDestroyErrorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInitDestroyErrorTestCase.java
new file mode 100644
index 0000000000..01c426e917
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInitDestroyErrorTestCase.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.core.component.scope;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainerMonitor;
+import org.apache.tuscany.spi.component.TargetDestructionException;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.component.GroupInitializationException;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.event.ComponentStart;
+import org.apache.tuscany.core.component.event.ComponentStop;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CompositeScopeInitDestroyErrorTestCase extends TestCase {
+ private URI groupId;
+
+ public void testInitializeError() throws Exception {
+ CompositeScopeContainer scope = new CompositeScopeContainer(null);
+ scope.start();
+
+ ObjectCreationException ex = new ObjectCreationException("");
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.createInstanceWrapper()).andThrow(ex);
+ EasyMock.expect(component.isEagerInit()).andStubReturn(true);
+ EasyMock.expect(component.getInitLevel()).andStubReturn(1);
+ EasyMock.replay(component);
+ scope.register(component, groupId);
+ try {
+ scope.startContext(groupId, groupId);
+ } catch (GroupInitializationException e) {
+ assertSame(ex, e.getCauses().get(0));
+ }
+ EasyMock.verify(component);
+ }
+
+ public void testDestroyErrorMonitor() throws Exception {
+ InstanceWrapper wrapper = EasyMock.createMock(InstanceWrapper.class);
+ wrapper.start();
+ wrapper.stop();
+ EasyMock.expectLastCall().andThrow(new TargetDestructionException("", ""));
+ EasyMock.replay(wrapper);
+
+ ScopeContainerMonitor monitor;
+ monitor = EasyMock.createMock(ScopeContainerMonitor.class);
+ monitor.destructionError(EasyMock.isA(TargetDestructionException.class));
+ EasyMock.replay(monitor);
+ CompositeScopeContainer scope = new CompositeScopeContainer(monitor);
+ scope.start();
+
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper);
+ EasyMock.expect(component.isEagerInit()).andStubReturn(true);
+ EasyMock.expect(component.getInitLevel()).andStubReturn(1);
+ EasyMock.replay(component);
+ scope.register(component, groupId);
+ scope.startContext(groupId, groupId);
+ scope.stopContext(groupId);
+ EasyMock.verify(monitor);
+ EasyMock.verify(component);
+ EasyMock.verify(wrapper);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ groupId = URI.create("composite");
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerDestroyOnExpirationTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerDestroyOnExpirationTestCase.java
new file mode 100644
index 0000000000..ca8222e7fd
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerDestroyOnExpirationTestCase.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.core.component.scope;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+import org.apache.tuscany.spi.services.store.Store;
+import org.apache.tuscany.spi.services.store.StoreExpirationEvent;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConversationalScopeContainerDestroyOnExpirationTestCase extends TestCase {
+ private Store store;
+ private RuntimeEventListener listener;
+ private WorkContext context;
+ private InstanceWrapper wrapper;
+ private AtomicComponent component;
+
+ /**
+ * Verifies the scope container registers a callback listener for component instance destroy events when a
+ * conversational instance expires
+ */
+ public void testDestroyNotification() throws Exception {
+ store.addListener(EasyMock.isA(RuntimeEventListener.class));
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>(){
+ public Object answer() throws Throwable {
+ listener = (RuntimeEventListener) EasyMock.getCurrentArguments()[0];
+ return null;
+ }
+ });
+ wrapper.stop();
+ EasyMock.replay(store);
+ EasyMock.replay(wrapper);
+
+ new ConversationalScopeContainer(store, context, null);
+ listener.onEvent(new StoreExpirationEvent(this, component, wrapper));
+ EasyMock.verify(store);
+ EasyMock.verify(wrapper);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ store = EasyMock.createMock(Store.class);
+ wrapper = EasyMock.createMock(InstanceWrapper.class);
+ component = EasyMock.createMock(AtomicComponent.class);
+ context = new WorkContextImpl();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxAgeTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxAgeTestCase.java
new file mode 100644
index 0000000000..6cc29513d4
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxAgeTestCase.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.core.component.scope;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.services.store.Store;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConversationalScopeContainerMaxAgeTestCase extends TestCase {
+
+ private ScopeContainer container;
+ private WorkContext context;
+ private Store store;
+ private AtomicComponent component;
+ private InstanceWrapper wrapper;
+
+ public void testMaxAgeUpdate() throws Exception {
+/*
+ context.setIdentifier(Scope.CONVERSATION, "12345");
+ assertSame(wrapper, container.getWrapper(component));
+ EasyMock.verify(store);
+*/
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ context = new WorkContextImpl();
+ component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.getMaxIdleTime()).andReturn(-1L).atLeastOnce();
+ EasyMock.expect(component.getMaxAge()).andReturn(600000L).atLeastOnce();
+ EasyMock.replay(component);
+
+ wrapper = EasyMock.createMock(InstanceWrapper.class);
+
+ store = EasyMock.createMock(Store.class);
+ EasyMock.expect(store.readRecord(EasyMock.isA(SCAObject.class), EasyMock.isA(String.class))).andReturn(wrapper);
+ store.addListener(EasyMock.isA(RuntimeEventListener.class));
+ EasyMock.replay(store);
+ container = new ConversationalScopeContainer(store, context, null);
+ container.start();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ context.clearIdentifier(Scope.CONVERSATION);
+ container.stop();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxIdleTimeTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxIdleTimeTestCase.java
new file mode 100644
index 0000000000..ad6ae44807
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxIdleTimeTestCase.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.core.component.scope;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.services.store.Store;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConversationalScopeContainerMaxIdleTimeTestCase extends TestCase {
+
+ private ScopeContainer container;
+ private WorkContext context;
+ private Store store;
+ private AtomicComponent component;
+ private InstanceWrapper wrapper;
+
+ public void testMaxIdleTimeUpdate() throws Exception {
+/*
+ context.setIdentifier(Scope.CONVERSATION, "12345");
+ assertSame(wrapper, container.getWrapper(component));
+ EasyMock.verify(store);
+*/
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ wrapper = EasyMock.createMock(InstanceWrapper.class);
+ context = new WorkContextImpl();
+ component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.getMaxIdleTime()).andStubReturn(600000L);
+ EasyMock.replay(component);
+ store = EasyMock.createMock(Store.class);
+ EasyMock.expect(store.readRecord(EasyMock.isA(SCAObject.class), EasyMock.isA(String.class))).andReturn(wrapper);
+ store.addListener(EasyMock.isA(RuntimeEventListener.class));
+ store.updateRecord(EasyMock.isA(SCAObject.class),
+ EasyMock.isA(String.class),
+ EasyMock.eq(wrapper),
+ EasyMock.anyLong());
+ EasyMock.replay(store);
+ container = new ConversationalScopeContainer(store, context, null);
+ container.start();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ context.clearIdentifier(Scope.CONVERSATION);
+ container.stop();
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerPersistenceTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerPersistenceTestCase.java
new file mode 100644
index 0000000000..0c938e892a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerPersistenceTestCase.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.core.component.scope;
+
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.services.store.Store;
+import org.apache.tuscany.spi.services.store.StoreMonitor;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.services.store.memory.MemoryStore;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public abstract class ConversationalScopeContainerPersistenceTestCase extends TestCase {
+ private ConversationalScopeContainer container;
+ private WorkContext context;
+
+ public void testNotYetPersistedInMemory() throws Exception {
+/*
+ InstanceWrapper wrapper = EasyMock.createMock(InstanceWrapper.class);
+ wrapper.start();
+ EasyMock.replay(wrapper);
+
+ String id = UUID.randomUUID().toString();
+ context.setIdentifier(Scope.CONVERSATION, id);
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ component.addListener(EasyMock.eq(container));
+ EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper);
+ EasyMock.expect(component.getMaxAge()).andReturn(600000L).atLeastOnce();
+ EasyMock.replay(component);
+
+ container.register(component, null);
+ assertSame(wrapper, container.getWrapper(component));
+ EasyMock.verify(component);
+ EasyMock.verify(wrapper);
+*/
+ }
+
+ public void testPersistNewInMemory() throws Exception {
+/*
+ String id = UUID.randomUUID().toString();
+ String id2 = UUID.randomUUID().toString();
+ context.setIdentifier(Scope.CONVERSATION, id);
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ component.addListener(EasyMock.eq(container));
+ EasyMock.expect(component.getMaxIdleTime()).andReturn(-1L).atLeastOnce();
+ EasyMock.replay(component);
+ container.register(component, null);
+ InstanceWrapper fooWrapper = EasyMock.createMock(InstanceWrapper.class);
+ InstanceWrapper fooWrapper2 = EasyMock.createMock(InstanceWrapper.class);
+ container.persistNew(component, id, fooWrapper, System.currentTimeMillis() + 100000);
+ assertEquals(fooWrapper, container.getWrapper(component));
+ container.persistNew(component, id2, fooWrapper2, System.currentTimeMillis() + 100000);
+ context.setIdentifier(Scope.CONVERSATION, id2);
+ assertEquals(fooWrapper2, container.getWrapper(component));
+ EasyMock.verify(component);
+*/
+ }
+
+ public void testPersistInMemory() throws Exception {
+/*
+ String id = UUID.randomUUID().toString();
+ context.setIdentifier(Scope.CONVERSATION, id);
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ component.addListener(EasyMock.eq(container));
+ EasyMock.expect(component.getMaxIdleTime()).andReturn(-1L).atLeastOnce();
+ EasyMock.replay(component);
+ container.register(component, null);
+ InstanceWrapper fooWrapper = EasyMock.createMock(InstanceWrapper.class);
+ container.persistNew(component, id, fooWrapper, System.currentTimeMillis() + 100000);
+ assertEquals(fooWrapper, container.getWrapper(component));
+ container.persist(component, id, fooWrapper, System.currentTimeMillis() + 100000);
+ assertEquals(fooWrapper, container.getWrapper(component));
+ EasyMock.verify(component);
+*/
+ }
+
+ public void testRemoveInMemory() throws Exception {
+/*
+ String id = UUID.randomUUID().toString();
+ context.setIdentifier(Scope.CONVERSATION, id);
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ component.addListener(EasyMock.eq(container));
+ EasyMock.expect(component.getMaxIdleTime()).andReturn(-1L).atLeastOnce();
+ EasyMock.expect(component.getUri()).andReturn(URI.create("foo")).atLeastOnce();
+ EasyMock.replay(component);
+ container.register(component, null);
+ InstanceWrapper fooWrapper = EasyMock.createMock(InstanceWrapper.class);
+ container.persistNew(component, id, fooWrapper, System.currentTimeMillis() + 100000);
+ assertEquals(fooWrapper, container.getWrapper(component));
+ container.remove(component);
+ try {
+ container.getAssociatedWrapper(component);
+ fail();
+ } catch (TargetNotFoundException e) {
+ //expected
+ }
+ EasyMock.verify(component);
+*/
+ }
+
+ public void testRecreateAfterRemoveInMemory() throws Exception {
+/*
+ InstanceWrapper wrapper = EasyMock.createMock(InstanceWrapper.class);
+ wrapper.start();
+ EasyMock.replay(wrapper);
+
+ String id = UUID.randomUUID().toString();
+ context.setIdentifier(Scope.CONVERSATION, id);
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ component.addListener(EasyMock.eq(container));
+ EasyMock.expect(component.getMaxAge()).andReturn(600000L).atLeastOnce();
+ EasyMock.expect(component.getMaxIdleTime()).andReturn(-1L).atLeastOnce();
+ EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper);
+ EasyMock.replay(component);
+
+ container.register(component, null);
+ InstanceWrapper fooWrapper = EasyMock.createMock(InstanceWrapper.class);
+ container.persistNew(component, id, fooWrapper, System.currentTimeMillis() + 100000);
+ assertEquals(fooWrapper, container.getWrapper(component));
+ container.remove(component);
+ assertSame(wrapper, container.getWrapper(component));
+ EasyMock.verify(component);
+*/
+ }
+
+ public void testGetPersistedInstance() throws Exception {
+/*
+ String id = UUID.randomUUID().toString();
+ String id2 = UUID.randomUUID().toString();
+ context.setIdentifier(Scope.CONVERSATION, id);
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.getUri()).andReturn(URI.create("foo")).atLeastOnce();
+ EasyMock.expect(component.getMaxIdleTime()).andReturn(-1L).atLeastOnce();
+ component.addListener(EasyMock.eq(container));
+ EasyMock.replay(component);
+ container.register(component, null);
+
+ InstanceWrapper fooWrapper = EasyMock.createMock(InstanceWrapper.class);
+ container.persistNew(component, id, fooWrapper, System.currentTimeMillis() + 100000);
+ assertEquals(fooWrapper, container.getAssociatedWrapper(component));
+ assertEquals(fooWrapper, container.getAssociatedWrapper(component));
+ context.setIdentifier(Scope.CONVERSATION, id2);
+ try {
+ container.getAssociatedWrapper(component);
+ fail();
+ } catch (TargetNotFoundException e) {
+ //expected
+ }
+ EasyMock.verify(component);
+*/
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ context = new WorkContextImpl();
+ StoreMonitor mock = EasyMock.createNiceMock(StoreMonitor.class);
+ EasyMock.replay(mock);
+ Store store = new MemoryStore(mock);
+ container = new ConversationalScopeContainer(store, context, null);
+ container.start();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ context.clearIdentifier(Scope.CONVERSATION);
+ container.stop();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeRestartTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeRestartTestCase.java
new file mode 100644
index 0000000000..e70ef065e1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeRestartTestCase.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.core.component.scope;
+
+import java.lang.reflect.Constructor;
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.services.store.StoreMonitor;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.component.event.ConversationEnd;
+import org.apache.tuscany.core.component.event.ConversationStart;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.system.component.SystemAtomicComponentImpl;
+import org.apache.tuscany.core.injection.MethodEventInvoker;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.services.store.memory.MemoryStore;
+import org.easymock.EasyMock;
+
+/**
+ * Verifies the scope container properly disposes resources and can be restarted
+ *
+ * @version $$Rev: 471111 $$ $$Date: 2006-11-03 23:06:48 -0500 (Fri, 03 Nov 2006) $$
+ */
+public abstract class ConversationalScopeRestartTestCase extends TestCase {
+
+ public void testRestart() throws Exception {
+ StoreMonitor monitor = EasyMock.createMock(StoreMonitor.class);
+ monitor.start(EasyMock.isA(String.class));
+ monitor.stop(EasyMock.isA(String.class));
+ MemoryStore store = new MemoryStore(monitor);
+ WorkContext ctx = new WorkContextImpl();
+ ConversationalScopeContainer scope = new ConversationalScopeContainer(store, ctx, null);
+ scope.start();
+ MethodEventInvoker<Object> initInvoker = new MethodEventInvoker<Object>(
+ ConversationalScopeRestartTestCase.InitDestroyOnce.class.getMethod("init"));
+ MethodEventInvoker<Object> destroyInvoker =
+ new MethodEventInvoker<Object>(InitDestroyOnce.class.getMethod("destroy"));
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setInitInvoker(initInvoker);
+ configuration.setDestroyInvoker(destroyInvoker);
+ Constructor<InitDestroyOnce> ctr = InitDestroyOnce.class.getConstructor((Class<?>[]) null);
+ configuration.setInstanceFactory(new PojoObjectFactory<InitDestroyOnce>(ctr));
+ configuration.setName(new URI("InitDestroy"));
+ AtomicComponent component = new SystemAtomicComponentImpl(configuration);
+ component.setScopeContainer(scope);
+ component.start();
+
+ String conversation = "conv";
+ ctx.setIdentifier(Scope.CONVERSATION, conversation);
+ scope.onEvent(new ConversationStart(this, conversation));
+ Object instance = component.getTargetInstance();
+ assertSame(instance, component.getTargetInstance());
+
+ scope.onEvent(new ConversationEnd(this, conversation));
+ scope.stop();
+ component.stop();
+
+ scope.start();
+ scope.onEvent(new ConversationStart(this, conversation));
+ component.start();
+ //assertNotSame(instance, context.getServiceInstance());
+ scope.onEvent(new ConversationEnd(this, conversation));
+ scope.stop();
+ component.stop();
+ }
+
+ public static class InitDestroyOnce {
+
+ private boolean initialized;
+ private boolean destroyed;
+
+ public InitDestroyOnce() {
+ }
+
+ public void init() {
+ if (!initialized) {
+ initialized = true;
+ } else {
+ fail("Scope did not clean up properly - Init called more than once");
+ }
+ }
+
+ public void destroy() {
+ if (!destroyed) {
+ destroyed = true;
+ } else {
+ fail("Scope did not clean up properly - Destroyed called more than once");
+ }
+ }
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperBaseTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperBaseTestCase.java
new file mode 100644
index 0000000000..c583ff19c6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperBaseTestCase.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.core.component.scope;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InstanceWrapperBaseTestCase extends TestCase {
+ private static final Object INSTANCE = new Object();
+ private InstanceWrapperBase<Object> wrapper;
+
+ public void testLifecycle() throws Exception {
+ assertFalse(wrapper.isStarted());
+ try {
+ wrapper.getInstance();
+ fail();
+ } catch (AssertionError e) {
+ // expected
+ }
+ wrapper.start();
+ assertTrue(wrapper.isStarted());
+ assertSame(INSTANCE, wrapper.getInstance());
+ wrapper.stop();
+ assertFalse(wrapper.isStarted());
+ try {
+ wrapper.getInstance();
+ fail();
+ } catch (AssertionError e) {
+ // expected
+ }
+ }
+
+ public void testNullCheck() {
+ try {
+ new InstanceWrapperBase<Object>(null);
+ fail();
+ } catch (AssertionError e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ wrapper = new InstanceWrapperBase<Object>(INSTANCE);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ReflectiveInstanceWrapperTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ReflectiveInstanceWrapperTestCase.java
new file mode 100644
index 0000000000..58ed092dab
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ReflectiveInstanceWrapperTestCase.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.component.scope;
+
+import junit.framework.TestCase;
+import static org.easymock.EasyMock.createMock;
+import org.easymock.EasyMock;
+
+import org.apache.tuscany.core.injection.EventInvoker;
+import org.apache.tuscany.spi.component.TargetDestructionException;
+import org.apache.tuscany.spi.component.TargetInitializationException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReflectiveInstanceWrapperTestCase extends TestCase {
+ private ReflectiveInstanceWrapper<Object> wrapper;
+ private Object instance;
+ private EventInvoker<Object> initInvoker;
+ private EventInvoker<Object> destroyInvoker;
+
+ public void testWithNoCallbacks() {
+ wrapper = new ReflectiveInstanceWrapper<Object>(instance, null, null);
+ try {
+ wrapper.start();
+ } catch (TargetInitializationException e) {
+ fail();
+ }
+ try {
+ wrapper.stop();
+ } catch (TargetDestructionException e) {
+ fail();
+ }
+ }
+
+ public void testWithStartCallback() {
+ initInvoker.invokeEvent(instance);
+ EasyMock.replay(initInvoker);
+ wrapper = new ReflectiveInstanceWrapper<Object>(instance, initInvoker, null);
+ try {
+ wrapper.start();
+ } catch (TargetInitializationException e) {
+ fail();
+ }
+ EasyMock.verify(initInvoker);
+ }
+
+ public void testWithStopCallback() {
+ destroyInvoker.invokeEvent(instance);
+ EasyMock.replay(destroyInvoker);
+ wrapper = new ReflectiveInstanceWrapper<Object>(instance, null, destroyInvoker);
+ try {
+ wrapper.stop();
+ } catch (TargetDestructionException e) {
+ fail();
+ }
+ EasyMock.verify(destroyInvoker);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+ instance = new Object();
+ initInvoker = createMock(EventInvoker.class);
+ destroyInvoker = createMock(EventInvoker.class);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeRestartTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeRestartTestCase.java
new file mode 100644
index 0000000000..821aa7954c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeRestartTestCase.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.core.component.scope;
+
+import java.lang.reflect.Constructor;
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.WorkContext;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.component.event.RequestEnd;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.system.component.SystemAtomicComponentImpl;
+import org.apache.tuscany.core.injection.MethodEventInvoker;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+
+/**
+ * Verifies the scope container properly disposes resources and canbe restarted
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public abstract class RequestScopeRestartTestCase extends TestCase {
+
+ public void testRestart() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ RequestScopeContainer scope = new RequestScopeContainer(null);
+ scope.start();
+ MethodEventInvoker<Object> initInvoker =
+ new MethodEventInvoker<Object>(InitDestroyOnce.class.getMethod("init"));
+ MethodEventInvoker<Object> destroyInvoker =
+ new MethodEventInvoker<Object>(InitDestroyOnce.class.getMethod("destroy"));
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setInitInvoker(initInvoker);
+ configuration.setDestroyInvoker(destroyInvoker);
+ Constructor<InitDestroyOnce> ctr = InitDestroyOnce.class.getConstructor((Class<?>[]) null);
+ configuration.setInstanceFactory(new PojoObjectFactory<InitDestroyOnce>(ctr));
+ configuration.setName(new URI("InitDestroy"));
+ AtomicComponent component = new SystemAtomicComponentImpl(configuration);
+ component.setScopeContainer(scope);
+ component.start();
+
+ Object instance = component.getTargetInstance();
+ assertSame(instance, component.getTargetInstance());
+
+ scope.onEvent(new RequestEnd(this));
+ scope.stop();
+ component.stop();
+
+ scope.start();
+ component.start();
+ assertNotSame(instance, component.getTargetInstance());
+ scope.onEvent(new RequestEnd(this));
+ scope.stop();
+ component.stop();
+ }
+
+ public static class InitDestroyOnce {
+
+ private boolean initialized;
+ private boolean destroyed;
+
+ public InitDestroyOnce() {
+ }
+
+ public void init() {
+ if (!initialized) {
+ initialized = true;
+ } else {
+ fail("Scope did not clean up properly - Init called more than once");
+ }
+ }
+
+ public void destroy() {
+ if (!destroyed) {
+ destroyed = true;
+ } else {
+ fail("Scope did not clean up properly - Destroyed called more than once");
+ }
+ }
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java
new file mode 100644
index 0000000000..7dd547d91d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.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.core.component.scope;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.WorkContext;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WorkContextTestCase extends TestCase {
+
+ public void testSetCurrentAtomicComponent() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class);
+ AtomicComponent component2 = EasyMock.createNiceMock(AtomicComponent.class);
+ ctx.setCurrentAtomicComponent(component);
+ assertEquals(component, ctx.getCurrentAtomicComponent());
+ ctx.setCurrentAtomicComponent(component2);
+ assertEquals(component2, ctx.getCurrentAtomicComponent());
+ }
+
+ public void testNonSetCurrentAtomicComponent() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ assertNull(ctx.getCurrentAtomicComponent());
+ }
+
+ public void testIndentifier() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ Object id = new Object();
+ ctx.setIdentifier(this, id);
+ assertEquals(id, ctx.getIdentifier(this));
+ }
+
+ public void testClearIndentifier() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ Object id = new Object();
+ ctx.setIdentifier(this, id);
+ ctx.clearIdentifier(this);
+ assertNull(ctx.getIdentifier(this));
+ }
+
+ public void testClearIndentifiers() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ Object id = new Object();
+ Object id2 = new Object();
+ ctx.setIdentifier(id, id);
+ ctx.setIdentifier(id2, id2);
+ ctx.clearIdentifiers();
+ assertNull(ctx.getIdentifier(id));
+ assertNull(ctx.getIdentifier(id2));
+ }
+
+ public void testClearNonExistentIndentifier() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ ctx.clearIdentifier(this);
+ }
+
+ public void testNullIndentifier() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ Object id = new Object();
+ ctx.setIdentifier(this, id);
+ ctx.clearIdentifier(null);
+ assertEquals(id, ctx.getIdentifier(this));
+ }
+
+ public void testNoIndentifier() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ assertNull(ctx.getIdentifier(this));
+ }
+
+ public void testSetGetCorrelationId() {
+ WorkContext context = new WorkContextImpl();
+ context.setCorrelationId("msg-005");
+ assertEquals(context.getCorrelationId(), "msg-005");
+ context.setCorrelationId(null);
+ assertNull(context.getCorrelationId());
+ }
+
+ public void testSetGetCorrelationIdInNewThread() throws InterruptedException {
+ WorkContext context = new WorkContextImpl();
+ context.setCorrelationId("msg-005");
+ assertEquals(context.getCorrelationId(), "msg-005");
+ context.setIdentifier("TX", "002");
+ ChildThread t = new ChildThread(context);
+ t.start();
+ t.join();
+ assertTrue(t.passed);
+ context.setCorrelationId(null);
+ assertNull(context.getCorrelationId());
+ }
+
+ public void testCurrentAtomicComponentDoesNotPropagateToChildThread() throws InterruptedException {
+ // NOTE should behaviour be to propagate?
+ WorkContext context = new WorkContextImpl();
+ context.setCurrentAtomicComponent(EasyMock.createNiceMock(AtomicComponent.class));
+ TestCurrentAtomicComponentChildThread t = new TestCurrentAtomicComponentChildThread(context);
+ t.start();
+ t.join();
+ assertTrue(t.passed);
+ context.setCurrentAtomicComponent(null);
+ assertNull(context.getCurrentAtomicComponent());
+ }
+
+ private static final class ChildThread extends Thread {
+ private WorkContext context;
+ private boolean passed = true;
+
+ private ChildThread(WorkContext context) {
+ this.context = context;
+ }
+
+ @Override
+ public void run() {
+ try {
+ assertNull(context.getCorrelationId());
+ assertEquals("002", context.getIdentifier("TX"));
+ } catch (AssertionError e) {
+ passed = false;
+ }
+ }
+
+ }
+
+ private static final class TestCurrentAtomicComponentChildThread extends Thread {
+ private WorkContext context;
+ private boolean passed = true;
+
+ private TestCurrentAtomicComponentChildThread(WorkContext context) {
+ this.context = context;
+ }
+
+ @Override
+ public void run() {
+ try {
+ assertNull(context.getCurrentAtomicComponent());
+ } catch (AssertionError e) {
+ passed = false;
+ }
+ }
+
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingInterceptorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingInterceptorTestCase.java
new file mode 100644
index 0000000000..086649ea75
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingInterceptorTestCase.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.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.databinding.Mediator;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DataBindingInterceptorTestCase extends TestCase {
+
+ @SuppressWarnings("unchecked")
+ public final void testInvoke() {
+ DataType<Class> type1 = new DataType<Class>("xml:string", String.class, String.class);
+ List<DataType<Class>> types1 = new ArrayList<DataType<Class>>();
+ types1.add(type1);
+ DataType<List<DataType<Class>>> inputType1 =
+ new DataType<List<DataType<Class>>>("xml:string", Object[].class, types1);
+
+ DataType<Class> type2 = new DataType<Class>("foo", Foo.class, Foo.class);
+ List<DataType<Class>> types2 = new ArrayList<DataType<Class>>();
+ types2.add(type2);
+ DataType<List<DataType<Class>>> inputType2 =
+ new DataType<List<DataType<Class>>>("foo", Object[].class, types2);
+
+ Operation<Class> operation1 =
+ new Operation<Class>("call", inputType1, type1, null, false, "xml:string", NO_CONVERSATION);
+ Operation<Class> operation2 =
+ new Operation<Class>("call", inputType2, type2, null, false, "org.w3c.dom.Node", NO_CONVERSATION);
+
+ DataType<DataType> outputType1 =
+ new DataType<DataType>("idl:output", Object.class, operation1.getOutputType());
+ DataType<DataType> outputType2 =
+ new DataType<DataType>("idl:output", Object.class, operation2.getOutputType());
+
+ Wire outboundWire = EasyMock.createMock(Wire.class);
+ Component composite = EasyMock.createMock(Component.class);
+ Component component = EasyMock.createMock(Component.class);
+ EasyMock.replay(outboundWire, composite, component);
+
+ DataBindingInteceptor interceptor = new DataBindingInteceptor(outboundWire, operation1, operation2);
+ Mediator mediator = createMock(Mediator.class);
+ Object[] source = new Object[]{"<foo>bar</foo>"};
+ Foo foo = new Foo();
+ foo.bar = "bar";
+ Object[] target = new Object[]{foo};
+ expect(mediator.mediate(EasyMock.same(source),
+ EasyMock.same(inputType1),
+ EasyMock.same(inputType2),
+ EasyMock.isA(Map.class))).andReturn(target);
+ // expect(mediator.mediate(target[0], type2,
+ // type1)).andReturn(source[0]);
+ expect(mediator.mediate(EasyMock.same(target[0]),
+ EasyMock.eq(outputType2),
+ EasyMock.eq(outputType1),
+ EasyMock.isA(Map.class))).andReturn(source[0]);
+ replay(mediator);
+ interceptor.setMediator(mediator);
+ Message msg = createMock(Message.class);
+ msg.setBody(EasyMock.anyObject());
+ expectLastCall().anyTimes();
+ expect(msg.getBody()).andReturn(source).once().andReturn(target[0]).once().andReturn(source[0]);
+ expect(msg.isFault()).andReturn(false).once();
+ replay(msg);
+ Interceptor next = createMock(Interceptor.class);
+ expect(next.invoke(msg)).andReturn(msg);
+ replay(next);
+ interceptor.setNext(next);
+ interceptor.invoke(msg);
+ String result = (String) msg.getBody();
+ Assert.assertEquals(source[0], result);
+ EasyMock.verify(mediator, msg, next);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ private static class Foo {
+ private String bar;
+
+ public String getBar() {
+ return bar;
+ }
+
+ public void setBar(String bar) {
+ this.bar = bar;
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingJavaInterfaceProcessorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingJavaInterfaceProcessorTestCase.java
new file mode 100644
index 0000000000..a928449e4d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingJavaInterfaceProcessorTestCase.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.core.databinding.impl;
+
+import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION;
+
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.api.annotation.DataContext;
+import org.apache.tuscany.api.annotation.DataType;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+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 indicates an error occurs
+ */
+ public final void testVisitInterface() throws InvalidServiceContractException {
+ DataBindingJavaInterfaceProcessor processor = new DataBindingJavaInterfaceProcessor();
+ JavaServiceContract<MockInterface> contract = new JavaServiceContract<MockInterface>(MockInterface.class);
+ Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>();
+ Operation<Type> operation = new Operation<Type>("call", null, null, null, false, null, NO_CONVERSATION);
+ Operation<Type> operation1 = new Operation<Type>("call1", null, null, null, false, null, NO_CONVERSATION);
+ operations.put("call", operation);
+ operations.put("call1", operation1);
+ contract.setOperations(operations);
+ processor.visitInterface(MockInterface.class, null, contract);
+ Assert.assertEquals("org.w3c.dom.Node", contract.getDataBinding());
+ Assert.assertEquals("element", (String)contract.getMetaData().get("nodeType"));
+ Assert.assertEquals("org.w3c.dom.Node", contract.getOperations().get("call").getDataBinding());
+ Assert.assertEquals("xml:string", contract.getOperations().get("call1").getDataBinding());
+ }
+
+ @DataType(name = "org.w3c.dom.Node", context = {@DataContext(key = "nodeType", value = "element")})
+ @Remotable
+ public static interface MockInterface {
+ Node call(Node msg);
+
+ @DataType(name = "xml:string")
+ String call1(String msg);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingLoaderTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingLoaderTestCase.java
new file mode 100644
index 0000000000..6941e10a0c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingLoaderTestCase.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.core.databinding.impl;
+
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.loader.InvalidValueException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.easymock.EasyMock;
+
+/**
+ * Testcase for DataBindingLoader
+ */
+public class DataBindingLoaderTestCase extends TestCase {
+ private XMLStreamReader reader;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public final void testLoad() throws LoaderException, XMLStreamException {
+ reader = EasyMock.createMock(XMLStreamReader.class);
+ // EasyMock.expect(reader.getEventType()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.hasNext()).andReturn(true).anyTimes();
+ EasyMock.expect(reader.getName()).andReturn(DataTypeLoader.DATA_BINDING);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn("ABC");
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(reader);
+
+ ModelObject mo = new DataTypeLoader(null).load(null, reader, null);
+ Assert.assertTrue(mo instanceof DataType);
+ Assert.assertEquals("ABC", ((DataType<?>)mo).getDataBinding());
+ EasyMock.verify(reader);
+
+ EasyMock.reset(reader);
+
+ // EasyMock.expect(reader.getEventType()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.hasNext()).andReturn(true).anyTimes();
+ EasyMock.expect(reader.getName()).andReturn(DataTypeLoader.DATA_BINDING);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn(null);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(reader);
+ try {
+ mo = new DataTypeLoader(null).load(null, reader, null);
+ Assert.fail("InvalidValueException should have been thrown");
+ } catch (InvalidValueException e) {
+ Assert.assertTrue(true);
+ }
+ EasyMock.verify(reader);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingRegistryImplTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingRegistryImplTestCase.java
new file mode 100644
index 0000000000..75eafe8380
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingRegistryImplTestCase.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.databinding.impl;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.databinding.DataBinding;
+import org.apache.tuscany.spi.databinding.DataBindingRegistry;
+import org.apache.tuscany.spi.model.DataType;
+import org.easymock.EasyMock;
+import org.xml.sax.ContentHandler;
+
+/**
+ *
+ */
+public class DataBindingRegistryImplTestCase extends TestCase {
+ private DataBindingRegistry registry;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ registry = new DataBindingRegistryImpl();
+ }
+
+ public void testRegistry() {
+ DataBinding db1 = createMock(DataBinding.class);
+ expect(db1.getName()).andReturn(ContentHandler.class.getName()).anyTimes();
+ DataType<Class> dataType1 = new DataType<Class>(ContentHandler.class, ContentHandler.class);
+ expect(db1.introspect(ContentHandler.class)).andReturn(dataType1);
+ expect(db1.introspect((Class)EasyMock.anyObject())).andReturn(null).anyTimes();
+ replay(db1);
+
+ registry.register(db1);
+
+ DataBinding db2 = createMock(DataBinding.class);
+ expect(db2.getName()).andReturn(XMLStreamReader.class.getName()).anyTimes();
+ DataType<Class> dataType2 = new DataType<Class>(XMLStreamReader.class, XMLStreamReader.class);
+ expect(db2.introspect(XMLStreamReader.class)).andReturn(dataType2);
+ expect(db2.introspect((Class)EasyMock.anyObject())).andReturn(null).anyTimes();
+ replay(db2);
+
+ registry.register(db2);
+
+ String name = db1.getName();
+ DataBinding db3 = registry.getDataBinding(name);
+ Assert.assertTrue(db1 == db3);
+
+ DataType<?> dt = registry.introspectType(ContentHandler.class);
+ Assert.assertEquals(dataType1, dt);
+ Assert.assertTrue(dt.getDataBinding().equalsIgnoreCase(name));
+
+ registry.unregister(name);
+ DataBinding db4 = registry.getDataBinding(name);
+ Assert.assertNull(db4);
+
+
+ dt = registry.introspectType(ContentHandler.class);
+ Assert.assertNotNull(dt);
+ Assert.assertEquals("java.lang.Object", dt.getDataBinding());
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingTestCase.java
new file mode 100644
index 0000000000..de5c537274
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingTestCase.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.core.databinding.impl;
+
+import java.lang.reflect.Method;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.api.annotation.DataContext;
+import org.apache.tuscany.api.annotation.DataType;
+
+public class DataBindingTestCase extends TestCase {
+ @SuppressWarnings("unused")
+ public void testDataType() throws Exception {
+ Class<Test> testClass = Test.class;
+ DataType d = testClass.getAnnotation(DataType.class);
+ Assert.assertEquals(d.name(), "sdo");
+ Assert.assertEquals(d.context().length, 0);
+
+ Method method = testClass.getMethod("test", new Class[] {Object.class});
+ DataType d2 = method.getAnnotation(DataType.class);
+ Assert.assertEquals(d2.name(), "jaxb");
+ Assert.assertEquals(d2.context()[0].key(), "contextPath");
+ Assert.assertEquals(d2.context()[0].value(), "com.example.ipo.jaxb");
+ }
+
+ @DataType(name = "sdo")
+ private static interface Test {
+ @DataType(name = "jaxb", context = {@DataContext(key = "contextPath", value = "com.example.ipo.jaxb")})
+ Object test(Object object);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorOptimizationTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorOptimizationTestCase.java
new file mode 100644
index 0000000000..de46eb0542
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorOptimizationTestCase.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.core.databinding.impl;
+
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.databinding.Mediator;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * Verifies that data binding interceptor is not added to invocation chains when the data binding types are not set on
+ * service contracts
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataBindingWirePostProcessorOptimizationTestCase extends TestCase {
+ private DataBindingWirePostProcessor processor;
+ private InvocationChain outboundChain;
+ private InvocationChain callbackChain;
+ private Wire wire;
+
+ public void testNoInterceptorInterposed() {
+ processor.process(wire);
+ EasyMock.verify(outboundChain);
+ EasyMock.verify(callbackChain);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ Mediator mediator = new MediatorImpl();
+ processor = new DataBindingWirePostProcessor(mediator);
+
+ ServiceContract<Type> contract = new JavaServiceContract(null);
+ Operation<Type> operation = new Operation<Type>("test", null, null, null);
+ operation.setServiceContract(contract);
+ Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>();
+ operations.put("test", operation);
+ contract.setOperations(operations);
+ contract.setCallbackOperations(operations);
+
+ outboundChain = EasyMock.createMock(InvocationChain.class);
+ EasyMock.replay(outboundChain);
+ Map<Operation<?>, InvocationChain> outboundChains = new HashMap<Operation<?>, InvocationChain>();
+ outboundChains.put(operation, outboundChain);
+
+ callbackChain = EasyMock.createMock(InvocationChain.class);
+ EasyMock.replay(callbackChain);
+ Map<Operation<?>, InvocationChain> callbackChains = new HashMap<Operation<?>, InvocationChain>();
+ callbackChains.put(operation, callbackChain);
+
+ wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.getInvocationChains()).andReturn(outboundChains);
+ EasyMock.expect(wire.getSourceContract()).andReturn(contract).anyTimes();
+ EasyMock.expect(wire.getTargetContract()).andReturn(contract).anyTimes();
+ EasyMock.expect(wire.getCallbackInvocationChains()).andReturn(callbackChains).anyTimes();
+ URI uri = URI.create("foo");
+ EasyMock.expect(wire.getSourceUri()).andReturn(uri).anyTimes();
+
+ EasyMock.replay(wire);
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorTestCase.java
new file mode 100644
index 0000000000..ccc522c0cb
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorTestCase.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.core.databinding.impl;
+
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.databinding.Mediator;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DataBindingWirePostProcessorTestCase extends TestCase {
+ private DataBindingWirePostProcessor processor;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ Mediator mediator = new MediatorImpl();
+ this.processor = new DataBindingWirePostProcessor(mediator);
+ }
+
+ public void testProcess1() {
+ Wire outboundWire = createMock(Wire.class);
+
+ Component component = createMock(Component.class);
+ Component composite = createMock(Component.class);
+
+ Map<Operation<?>, InvocationChain> outboundChains =
+ new HashMap<Operation<?>, InvocationChain>();
+ DataType<Type> type1 = new DataType<Type>(String.class, String.class);
+ List<DataType<Type>> types = new ArrayList<DataType<Type>>();
+ types.add(type1);
+ DataType<List<DataType<Type>>> inputType1 = new DataType<List<DataType<Type>>>(Object[].class, types);
+ DataType<Type> outputType1 = new DataType<Type>(String.class, String.class);
+ Operation<Type> op1 = new Operation<Type>("test", inputType1, outputType1, null);
+ ServiceContract<Type> outboundContract = new JavaServiceContract(null);
+ outboundContract.setDataBinding(String.class.getName());
+ op1.setServiceContract(outboundContract);
+ Map<String, Operation<Type>> outboundOperations = new HashMap<String, Operation<Type>>();
+ outboundOperations.put("test", op1);
+
+ outboundContract.setOperations(outboundOperations);
+ InvocationChain outboundChain = createMock(InvocationChain.class);
+ outboundChains.put(op1, outboundChain);
+ expect(outboundWire.getInvocationChains()).andReturn(outboundChains);
+ outboundChain.addInterceptor(EasyMock.anyInt(), (Interceptor) EasyMock.anyObject());
+
+
+ ServiceContract<Type> contract = new JavaServiceContract();
+ Map<String, Operation<Type>> operations = Collections.emptyMap();
+ contract.setCallbackOperations(operations);
+ expect(outboundWire.getSourceContract()).andReturn(outboundContract);
+ expect(outboundWire.getTargetContract()).andReturn(outboundContract);
+
+ EasyMock.replay(composite, component, outboundWire, outboundChain);
+
+ processor.process(outboundWire);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DirectedGraphTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DirectedGraphTestCase.java
new file mode 100755
index 0000000000..70244df8e2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DirectedGraphTestCase.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.core.databinding.impl;
+
+import java.util.List;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.databinding.impl.DirectedGraph.Edge;
+import org.apache.tuscany.core.databinding.impl.DirectedGraph.Vertex;
+
+public class DirectedGraphTestCase extends TestCase {
+ private DirectedGraph<String, Object> graph;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ graph = new DirectedGraph<String, Object>();
+ graph.addEdge("a", "b", null, 3);
+ graph.addEdge("b", "c", null, 1);
+ graph.addEdge("a", "c", null, 8);
+ graph.addEdge("a", "d", null, 3);
+ graph.addEdge("b", "d", null, 2);
+ graph.addEdge("c", "b", null, 1);
+ graph.addEdge("c", "d", null, 2);
+ graph.addEdge("d", "b", null, 1);
+ graph.addEdge("a", "e", null, 8);
+ graph.addEdge("c", "c", null, 2);
+ }
+
+ public void testGraph() {
+ // System.out.println(graph);
+
+ Vertex vertex = graph.getVertex("a");
+ Assert.assertNotNull(vertex);
+ Assert.assertEquals(vertex.getValue(), "a");
+
+ Assert.assertNull(graph.getVertex("1"));
+
+ Edge edge = graph.getEdge("a", "b");
+ Assert.assertNotNull(edge);
+ Assert.assertEquals(edge.getWeight(), 3);
+
+ edge = graph.getEdge("b", "a");
+ Assert.assertNull(edge);
+
+ DirectedGraph<String, Object>.Path path = graph.getShortestPath("a", "c");
+
+ List<DirectedGraph<String, Object>.Edge> edges = path.getEdges();
+ Assert.assertEquals(edges.size(), 2);
+ Assert.assertEquals(edges.get(0), graph.getEdge("a", "b"));
+ Assert.assertEquals(edges.get(1), graph.getEdge("b", "c"));
+
+ Assert.assertEquals(path.getWeight(), 4);
+
+ DirectedGraph<String, Object>.Path path2 = graph.getShortestPath("b", "e");
+ Assert.assertNull(path2);
+
+ DirectedGraph<String, Object>.Path path3 = graph.getShortestPath("a", "a");
+ Assert.assertTrue(path3.getWeight() == 0 && path3.getEdges().isEmpty());
+
+ DirectedGraph<String, Object>.Path path4 = graph.getShortestPath("c", "c");
+ Assert.assertTrue(path4.getWeight() == 2 && path4.getEdges().size() == 1);
+
+ // System.out.println(path);
+
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/IDLTransformerTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/IDLTransformerTestCase.java
new file mode 100644
index 0000000000..cba980ae4a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/IDLTransformerTestCase.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.core.databinding.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.databinding.javabeans.DOMNode2JavaBeanTransformer;
+import org.apache.tuscany.core.databinding.javabeans.JavaBean2DOMNodeTransformer;
+import org.apache.tuscany.core.databinding.xml.DOMDataBinding;
+import org.apache.tuscany.core.databinding.xml.Node2String;
+import org.apache.tuscany.core.databinding.xml.String2Node;
+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.apache.tuscany.spi.model.ElementInfo;
+import org.apache.tuscany.spi.model.TypeInfo;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.WrapperInfo;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class IDLTransformerTestCase extends TestCase {
+ private static final String IPO_XML =
+ "<?xml version=\"1.0\"?>" + "<order1"
+ + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ + " xmlns:ipo=\"http://www.example.com/IPO\""
+ + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\""
+ + " orderDate=\"1999-12-01\">"
+ + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">"
+ + " <name>Helen Zoe</name>"
+ + " <street>47 Eden Street</street>"
+ + " <city>Cambridge</city>"
+ + " <postcode>CB1 1JR</postcode>"
+ + " </shipTo>"
+ + " <billTo xsi:type=\"ipo:USAddress\">"
+ + " <name>Robert Smith</name>"
+ + " <street>8 Oak Avenue</street>"
+ + " <city>Old Town</city>"
+ + " <state>PA</state>"
+ + " <zip>95819</zip>"
+ + " </billTo>"
+ + " <items>"
+ + " <item partNum=\"833-AA\">"
+ + " <productName>Lapis necklace</productName>"
+ + " <quantity>1</quantity>"
+ + " <USPrice>99.95</USPrice>"
+ + " <ipo:comment>Want this for the holidays</ipo:comment>"
+ + " <shipDate>1999-12-05</shipDate>"
+ + " </item>"
+ + " </items>"
+ + "</order1>";
+
+ 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<DataType<QName>> types0 = new ArrayList<DataType<QName>>();
+ DataType<QName> wrapperType =
+ new DataType<QName>(null, Object.class, new QName(URI_ORDER_XSD, "checkOrderStatus"));
+ types0.add(wrapperType);
+ DataType<List<DataType<QName>>> inputType0 =
+ new DataType<List<DataType<QName>>>("idl:input", Object[].class, types0);
+
+ List<DataType<QName>> types1 = new ArrayList<DataType<QName>>();
+ DataType<QName> customerIdType =
+ new DataType<QName>(null, Object.class, new QName(URI_ORDER_XSD, "customerId"));
+ DataType<QName> orderType =
+ new DataType<QName>(null, Object.class, new QName(URI_ORDER_XSD, "order"));
+ DataType<QName> flagType = new DataType<QName>(null, Object.class, new QName(URI_ORDER_XSD, "flag"));
+ types1.add(customerIdType);
+ types1.add(orderType);
+ types1.add(flagType);
+ DataType<List<DataType<QName>>> inputType =
+ new DataType<List<DataType<QName>>>("idl:input", Object[].class, types1);
+
+ DataType<QName> statusType =
+ new DataType<QName>(null, Object.class, new QName(URI_ORDER_XSD, "status"));
+ DataType<QName> responseType =
+ new DataType<QName>(null, Object.class, new QName(URI_ORDER_XSD, "checkOrderStatusResponse"));
+
+ org.apache.tuscany.spi.model.Operation<QName> op =
+ new org.apache.tuscany.spi.model.Operation<QName>("checkOrderStatus", inputType0, responseType,
+ null);
+ 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<ElementInfo> inputElements = new ArrayList<ElementInfo>();
+ 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<ElementInfo> outputElements = new ArrayList<ElementInfo>();
+ 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);
+
+ 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.setDataBindingRegistry(dataBindingRegistry);
+ t.setMediator(m);
+
+ TransformationContext context = new TransformationContextImpl();
+ List<DataType<Class>> types = new ArrayList<DataType<Class>>();
+ types.add(new DataType<Class>(Object.class.getName(), String.class, String.class));
+ types.add(new DataType<Class>("java.lang.String", String.class, String.class));
+ types.add(new DataType<Class>(Object.class.getName(), int.class, int.class));
+ DataType<List<DataType<Class>>> inputType1 =
+ new DataType<List<DataType<Class>>>("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<DataType> sourceType =
+ new DataType<DataType>("idl:output", Object.class, op.getOutputType());
+ sourceType.setOperation(op.getOutputType().getOperation());
+
+ sourceType.setMetadata(ElementInfo.class.getName(), outputElement);
+ context1.setSourceDataType(sourceType);
+ DataType<DataType> targetType =
+ new DataType<DataType>("idl:output", Object.class,
+ new DataType<Class>("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);
+ t2.setDataBindingRegistry(dataBindingRegistry);
+ Object st = t2.transform(responseElement, context1);
+ assertEquals("shipped", st);
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/MediatorImplTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/MediatorImplTestCase.java
new file mode 100644
index 0000000000..3cb7f243a9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/MediatorImplTestCase.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.core.databinding.impl;
+
+import java.io.StringWriter;
+import java.io.Writer;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.databinding.xml.Node2String;
+import org.apache.tuscany.core.databinding.xml.Node2Writer;
+import org.apache.tuscany.core.databinding.xml.SAX2DOMPipe;
+import org.apache.tuscany.core.databinding.xml.String2SAX;
+import org.apache.tuscany.spi.databinding.DataBindingRegistry;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformerRegistry;
+import org.apache.tuscany.spi.model.DataType;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Test case for MediatorImpl
+ */
+public class MediatorImplTestCase extends TestCase {
+ private static final String IPO_XML =
+ "<?xml version=\"1.0\"?>" + "<ipo:purchaseOrder"
+ + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ + " xmlns:ipo=\"http://www.example.com/IPO\""
+ + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\""
+ + " orderDate=\"1999-12-01\">"
+ + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">"
+ + " <name>Helen Zoe</name>"
+ + " <street>47 Eden Street</street>"
+ + " <city>Cambridge</city>"
+ + " <postcode>CB1 1JR</postcode>"
+ + " </shipTo>"
+ + " <billTo xsi:type=\"ipo:USAddress\">"
+ + " <name>Robert Smith</name>"
+ + " <street>8 Oak Avenue</street>"
+ + " <city>Old Town</city>"
+ + "<state>PA</state>"
+ + " <zip>95819</zip>"
+ + " </billTo>"
+ + " <items>"
+ + " <item partNum=\"833-AA\">"
+ + " <productName>Lapis necklace</productName>"
+ + " <quantity>1</quantity>"
+ + "<USPrice>99.95</USPrice>"
+ + " <ipo:comment>Want this for the holidays</ipo:comment>"
+ + " <shipDate>1999-12-05</shipDate>"
+ + " </item>"
+ + " </items>"
+ + "</ipo:purchaseOrder>";
+
+ private MediatorImpl mediator;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ TransformerRegistry registry = new TransformerRegistryImpl();
+ registry.registerTransformer(new String2SAX());
+ registry.registerTransformer(new SAX2DOMPipe());
+ registry.registerTransformer(new Node2String());
+ registry.registerTransformer(new Node2Writer());
+
+ mediator = new MediatorImpl();
+ mediator.setTransformerRegistry(registry);
+
+ DataBindingRegistry dataBindingRegistry = new DataBindingRegistryImpl();
+ mediator.setDataBindingRegistry(dataBindingRegistry);
+ }
+
+ private TransformationContext createTransformationContext(Class sourceType, Class targetType) {
+ TransformationContext context = new TransformationContextImpl();
+ DataType sourceDataType = new DataType<Class>(sourceType, sourceType);
+ DataType targetDataType = new DataType<Class>(targetType, targetType);
+ context.setSourceDataType(sourceDataType);
+ context.setTargetDataType(targetDataType);
+ return context;
+ }
+
+ public void testTransform1() {
+ TransformationContext context = createTransformationContext(String.class, Node.class);
+ Object node =
+ mediator.mediate(IPO_XML, context.getSourceDataType(), context.getTargetDataType(), null);
+ Assert.assertTrue(node instanceof Document);
+ Element root = ((Document)node).getDocumentElement();
+ Assert.assertEquals(root.getNamespaceURI(), "http://www.example.com/IPO");
+ Assert.assertEquals(root.getLocalName(), "purchaseOrder");
+ }
+
+ public void testTransform2() {
+ TransformationContext context = createTransformationContext(String.class, Writer.class);
+ Writer writer = new StringWriter();
+ mediator.mediate(IPO_XML, writer, context.getSourceDataType(), context.getTargetDataType(), null);
+ String str = writer.toString();
+ Assert.assertTrue(str != null && str.indexOf("<shipDate>1999-12-05</shipDate>") != -1);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueInterceptorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueInterceptorTestCase.java
new file mode 100644
index 0000000000..571f5ae7ab
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueInterceptorTestCase.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.core.databinding.impl;
+
+import java.io.Serializable;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case for ByValueInterceptor
+ */
+public class PassByValueInterceptorTestCase extends TestCase {
+ private MySerialiable serialiable = new MySerialiable();
+ private String str = "ABC";
+ private Integer i = new Integer(1);
+ private String[] array = new String[] {"1", "2"};
+ private Object[] values;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ values = new Object[] {serialiable, str, i, serialiable, array};
+ }
+
+ private static class MySerialiable implements Serializable {
+ private static final long serialVersionUID = 7827201707529055310L;
+ private final String name = "Serializable";
+ private final int age = 100;
+
+ public int getAge() {
+ return age;
+ }
+
+ public String getName() {
+ return name;
+ }
+ }
+
+ public void testCopy() {
+ Object[] copy = new PassByValueInterceptor().copy(values);
+ assertTrue(copy[0] instanceof MySerialiable);
+ MySerialiable copied = (MySerialiable)copy[0];
+ assertNotSame(serialiable, copy[0]);
+ assertEquals(serialiable.getName(), copied.getName());
+ assertEquals(serialiable.getAge(), copied.getAge());
+ assertSame(copy[1], str);
+ assertSame(copy[2], i);
+ assertSame(copy[0], copy[3]);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessorTestCase.java
new file mode 100644
index 0000000000..03cc28735e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessorTestCase.java
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.databinding.impl;
+
+import java.net.URI;
+import java.util.List;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.databinding.DataBindingRegistry;
+import org.apache.tuscany.spi.extension.AtomicComponentExtension;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import static org.easymock.EasyMock.createMock;
+
+/**
+ * Testcase for testing if the PassByValueWireProcessor adds the PassByValueInterceptor to the invocation chains and
+ * also ensure that the outbound and inbound chain of interceptors are linked after this insertion
+ *
+ * @version $Rev$ $Date$
+ */
+public class PassByValueWirePostProcessorTestCase extends TestCase {
+ private PassByValueWirePostProcessor processor;
+
+ public void testProcessInclusionOfInterceptor() {
+//
+// InboundWire inboundWire = createMock(InboundWire.class);
+// OutboundWire outboundWire = createMock(OutboundWire.class);
+//
+// ServiceContract<Type> serviceContract = new JavaServiceContract(null);
+// serviceContract.setRemotable(true);
+// Map<Operation<?>, InboundInvocationChain> inChainsMap =
+// new Hashtable<Operation<?>, InboundInvocationChain>();
+//
+// Operation<Type> operation1 = new Operation<Type>("testMethod", null, null, null);
+// operation1.setServiceContract(serviceContract);
+// InboundInvocationChainImpl inChain = new InboundInvocationChainImpl(operation1);
+// inChainsMap.put(operation1, inChain);
+//
+// AtomicComponentExtension componentExtn = new FooComponent();
+//
+// Map<Operation<?>, OutboundInvocationChain> outChainsMap =
+// new Hashtable<Operation<?>, OutboundInvocationChain>();
+// OutboundInvocationChainImpl outChain = new OutboundInvocationChainImpl(operation1);
+// outChainsMap.put(operation1, outChain);
+//
+// expect(inboundWire.getSourceContract()).andReturn(serviceContract);
+// expect(inboundWire.getInboundInvocationChains()).andReturn(inChainsMap);
+// expect(outboundWire.getSourceContract()).andReturn(serviceContract).times(2);
+// expect(outboundWire.getOutboundInvocationChains()).andReturn(outChainsMap).times(2);
+//
+// Interceptor inInterceptor = createMock(Interceptor.class);
+// Interceptor outInterceptor = createMock(Interceptor.class);
+// inChain.addInterceptor(0, inInterceptor);
+// outChain.addInterceptor(0, outInterceptor);
+// //outChain.addInterceptor(new SynchronousBridgingInterceptor(inChain.getHeadInterceptor()));
+//
+// EasyMock.replay(inboundWire, outboundWire);
+// processor.process(componentExtn, outboundWire, componentExtn, inboundWire);
+//
+// assertEquals(true, inChain.getHeadInterceptor() instanceof PassByValueInterceptor);
+// assertEquals(true,
+// outChain.getTailInterceptor().getNext() instanceof PassByValueInterceptor);
+// assertEquals(true, outChain.getTailInterceptor().getNext().equals(
+// inChain.getHeadInterceptor()));
+//
+ }
+
+ public void testProcessExclusionOfInterceptorWhenAllowsPassByReference() {
+// Wire inboundWire = createMock(Wire.class);
+// Wire outboundWire = createMock(Wire.class);
+//
+// ServiceContract<Type> serviceContract = new JavaServiceContract(null);
+// serviceContract.setRemotable(true);
+// Map<Operation<?>, InvocationChain> inChainsMap =
+// new Hashtable<Operation<?>, InvocationChain>();
+//
+// Operation<?> operation1 = new Operation<Type>("testMethod", null, null, null);
+// InvocationChainImpl inChain = new InvocationChainImpl(operation1);
+// inChainsMap.put(operation1, inChain);
+//
+// AtomicComponentExtension componentExtn = new FooComponent();
+// componentExtn.setAllowsPassByReference(true);
+//
+//
+// Map<Operation<?>, InvocationChain> outChainsMap =
+// new Hashtable<Operation<?>, InvocationChain>();
+// InvocationChainImpl outChain = new InvocationChainImpl(operation1);
+// outChainsMap.put(operation1, outChain);
+//
+// expect(inboundWire.getSourceContract()).andReturn(serviceContract);
+// expect(inboundWire.getInvocationChains()).andReturn(inChainsMap);
+// expect(outboundWire.getSourceContract()).andReturn(serviceContract).times(2);
+// expect(outboundWire.getInvocationChains()).andReturn(outChainsMap).times(2);
+//
+// Interceptor inInterceptor = createMock(Interceptor.class);
+// Interceptor outInterceptor = createMock(Interceptor.class);
+// inChain.addInterceptor(0, inInterceptor);
+// outChain.addInterceptor(0, outInterceptor);
+// //outChain.addInterceptor(new SynchronousBridgingInterceptor(inChain.getHeadInterceptor()));
+//
+// EasyMock.replay(inboundWire, outboundWire);
+// processor.process(componentExtn, outboundWire, componentExtn, inboundWire);
+//
+// assertEquals(false, inChain.getHeadInterceptor() instanceof PassByValueInterceptor);
+// assertEquals(false,
+// outChain.getTailInterceptor().getNext() instanceof PassByValueInterceptor);
+// assertEquals(true, outChain.getTailInterceptor().getNext().equals(
+// inChain.getHeadInterceptor()));
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.processor = new PassByValueWirePostProcessor();
+ DataBindingRegistry dataBindingRegistry = createMock(DataBindingRegistry.class);
+ processor.setDataBindingRegistry(dataBindingRegistry);
+ }
+
+ private class FooComponent extends AtomicComponentExtension {
+
+ public FooComponent() {
+ super(URI.create("foo"), null, null, null, 0, -1, -1);
+ }
+
+ public List<Wire> getWires(String name) {
+ return null;
+ }
+
+ public void attachCallbackWire(Wire wire) {
+
+ }
+
+ public void attachWire(Wire wire) {
+
+ }
+
+ public void attachWires(List<Wire> wires) {
+
+ }
+
+ public Object createInstance() throws ObjectCreationException {
+ return null;
+ }
+
+ public InstanceWrapper<?> createInstanceWrapper() throws ObjectCreationException {
+ return null;
+ }
+
+ public Object getTargetInstance() throws TargetResolutionException {
+ return null;
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, Operation operation) {
+ return null;
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, PhysicalOperationDefinition operation)
+ throws TargetInvokerCreationException {
+ return null;
+ }
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/TransformerRegistryImplTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/TransformerRegistryImplTestCase.java
new file mode 100644
index 0000000000..6250efd897
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/TransformerRegistryImplTestCase.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.core.databinding.impl;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
+import java.util.List;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.TransformerRegistry;
+
+/**
+ *
+ */
+public class TransformerRegistryImplTestCase extends TestCase {
+ private TransformerRegistry registry;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ registry = new TransformerRegistryImpl();
+ }
+
+ public void testRegisterTransformer1() {
+ Transformer transformer = createMock(Transformer.class);
+ registry.registerTransformer("a", "b", 10, transformer);
+ Transformer t = registry.getTransformer("a", "b");
+ Assert.assertSame(t, transformer);
+ }
+
+ public void testRegisterTransformerTransformer() {
+ Transformer transformer = createMock(Transformer.class);
+ expect(transformer.getSourceDataBinding()).andReturn("a");
+ expect(transformer.getTargetDataBinding()).andReturn("b");
+ expect(transformer.getWeight()).andReturn(10);
+ replay(transformer);
+ registry.registerTransformer(transformer);
+ Transformer t = registry.getTransformer("a", "b");
+ Assert.assertSame(t, transformer);
+ }
+
+ public void testUnregisterTransformer() {
+ Transformer transformer = createMock(Transformer.class);
+ registry.registerTransformer("a", "b", 10, transformer);
+ boolean result = registry.unregisterTransformer("a", "b");
+ Assert.assertTrue(result);
+ Transformer t = registry.getTransformer("a", "b");
+ Assert.assertNull(t);
+ }
+
+ public void testGetTransformerChain() {
+ Transformer t1 = createMock(Transformer.class);
+ expect(t1.getSourceDataBinding()).andReturn("a");
+ expect(t1.getTargetDataBinding()).andReturn("b");
+ expect(t1.getWeight()).andReturn(10);
+ replay(t1);
+ Transformer t2 = createMock(Transformer.class);
+ expect(t2.getSourceDataBinding()).andReturn("b");
+ expect(t2.getTargetDataBinding()).andReturn("c");
+ expect(t2.getWeight()).andReturn(20);
+ replay(t2);
+
+ Transformer t3 = createMock(Transformer.class);
+ expect(t3.getSourceDataBinding()).andReturn("a");
+ expect(t3.getTargetDataBinding()).andReturn("c");
+ expect(t3.getWeight()).andReturn(120);
+ replay(t3);
+
+ registry.registerTransformer(t1);
+ registry.registerTransformer(t2);
+ registry.registerTransformer(t3);
+
+ List<Transformer> l1 = registry.getTransformerChain("a", "b");
+ Assert.assertTrue(l1.size() == 1 && l1.get(0) == t1);
+ List<Transformer> l2 = registry.getTransformerChain("a", "c");
+ Assert.assertTrue(l2.size() == 2 && l2.get(0) == t1 && l2.get(1) == t2);
+ List<Transformer> l3 = registry.getTransformerChain("a", "d");
+ Assert.assertNull(l3);
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformerTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformerTestCase.java
new file mode 100644
index 0000000000..842051782b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformerTestCase.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.core.databinding.javabeans;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.extension.DOMHelper;
+import org.apache.tuscany.spi.model.ElementInfo;
+import org.apache.tuscany.spi.model.TypeInfo;
+import org.apache.tuscany.spi.model.DataType;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * Testcase to test the XMLTypeMapperExtension which is the back bone for all transformations supported by the JavaBeans
+ * Databinding.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DOMNode2JavaBeanTransformerTestCase extends TestCase {
+ private DOMNode2JavaBeanTransformer dom2JavaTransformer = new DOMNode2JavaBeanTransformer();
+
+ public void testFieldSettings() throws Exception {
+ String samplePropertyXML =
+ "<property name=\"prop2\" >" + "<integerNumber>27</integerNumber>"
+ + "<floatNumber>79.34</floatNumber>"
+ + "<doubleNumber>184.52</doubleNumber>" + "<innerProperty>"
+ + "<integerNumber>54</integerNumber>" + "<floatNumber>158.68</floatNumber>"
+ + "<doubleNumber>369.04</doubleNumber>" + "</innerProperty>"
+ + "<stringArray>TestString_1</stringArray>"
+ + "<stringArray>TestString_2</stringArray>" + "<boolArray>true</boolArray>"
+ + "<boolArray>false</boolArray>" + "</property>";
+
+ DocumentBuilder builder = DOMHelper.newDocumentBuilder();
+ InputSource inputSource = new InputSource(new StringReader(samplePropertyXML));
+ Node samplePropertyNode = builder.parse(inputSource);
+ TypeInfo typeInfo = new TypeInfo(null, false, null);
+
+ TransformationContext context = EasyMock.createMock(TransformationContext.class);
+ DataType<Class> targetDataType = new DataType<Class>(null, SamplePropertyBean.class);
+ EasyMock.expect(context.getTargetDataType()).andReturn(targetDataType).anyTimes();
+
+ DataType<Class> sourceDataType = new DataType<Class>(null, null);
+ ElementInfo eleInfo = new ElementInfo(null, typeInfo);
+ sourceDataType.setMetadata(ElementInfo.class.getName(), eleInfo);
+ EasyMock.expect(context.getSourceDataType()).andReturn(sourceDataType).anyTimes();
+ EasyMock.replay(context);
+
+ Object javaObject =
+ dom2JavaTransformer.transform(((Document) samplePropertyNode).getDocumentElement(), context);
+
+ assertTrue(javaObject instanceof SamplePropertyBean);
+ SamplePropertyBean samplePropBean = (SamplePropertyBean) javaObject;
+ assertEquals(samplePropBean.getIntegerNumber(), 27);
+ assertEquals((float) 79.34, samplePropBean.getFloatNumber());
+ assertEquals(samplePropBean.getInnerProperty().getDoubleNumber(), 369.04);
+
+ assertEquals(samplePropBean.getStringArray()[0], "TestString_1");
+ assertEquals(samplePropBean.boolArray[0], true);
+
+ /** testing for object to node * */
+ javax.xml.transform.Transformer transformer =
+ TransformerFactory.newInstance().newTransformer();
+ JavaBean2DOMNodeTransformer java2DomTransformer = new JavaBean2DOMNodeTransformer();
+ Node aNode = java2DomTransformer.transform(javaObject, context);
+ StringWriter sw = new StringWriter();
+ transformer.transform(new DOMSource(aNode), new StreamResult(sw));
+ String nodeString = sw.toString();
+ //System.out.println(nodeString);
+
+ // testing the case when field and getter method do not have public access
+ assertTrue(nodeString.indexOf("<doubleNumber>184.52</doubleNumber>") == -1);
+ // test the case for fields that are of array type
+ assertTrue(nodeString.indexOf("<stringArray>TestString_1</stringArray>"
+ + "<stringArray>TestString_2</stringArray>") != -1);
+ // testing the case for non-public field with public getter method
+ assertTrue(nodeString.indexOf("<integerNumber>27</integerNumber>") != -1);
+ // test the case for public field that is a another java bean .i.e. embeded javabean
+ int startIndex = nodeString.indexOf("<innerProperty>");
+ int endIndex = nodeString.indexOf("</innerProperty>");
+ String fragment = nodeString.substring(startIndex, endIndex);
+ assertTrue(fragment.indexOf("<integerNumber>54</integerNumber>") != -1);
+
+ // System.out.println(sw.toString());
+
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ private static class SamplePropertyBean {
+ public boolean[] boolArray;
+ private float floatNumber = 50;
+ private SamplePropertyBean innerProperty;
+ private double doubleNumber = 75;
+ private int integerNumber = 25;
+ private String[] stringArray;
+
+ public SamplePropertyBean() {
+
+ }
+
+ double getDoubleNumber() {
+ return doubleNumber;
+ }
+
+ public void setDoubleNumber(double doubleNumber) {
+ this.doubleNumber = doubleNumber;
+ }
+
+ public float getFloatNumber() {
+ return floatNumber;
+ }
+
+ public void setFloatNumber(float floatNumber) {
+ this.floatNumber = floatNumber;
+ }
+
+ public int getIntegerNumber() {
+ return integerNumber;
+ }
+
+ public void setIntegerNumber(int integerNumber) {
+ this.integerNumber = integerNumber;
+ }
+
+ public SamplePropertyBean getInnerProperty() {
+ return innerProperty;
+ }
+
+ public void setInnerProperty(SamplePropertyBean prop) {
+ this.innerProperty = prop;
+ }
+
+ public String toString() {
+ return Double.toString(integerNumber + floatNumber + doubleNumber) + " & "
+ + ((innerProperty == null) ? "" : innerProperty.toString());
+ }
+
+ public String[] getStringArray() {
+ return stringArray;
+ }
+
+ public void setStringArray(String[] stringArray) {
+ this.stringArray = stringArray;
+ }
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformerTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformerTestCase.java
new file mode 100644
index 0000000000..839c7429b1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformerTestCase.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.javabeans;
+
+import java.io.StringWriter;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Node;
+
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.model.DataType;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * Testcase to test the XMLTypeMapperExtension which is the back bone for all transformations supported by the JavaBeans
+ * Databinding.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaBean2DOMNodeTransformerTestCase extends TestCase {
+ private JavaBean2DOMNodeTransformer aTransformer = new JavaBean2DOMNodeTransformer();
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testTranformation() throws Exception {
+ TransformationContext context = EasyMock.createMock(TransformationContext.class);
+ DataType<Class> dataType = new DataType<Class>(null, SamplePropertyBean.class);
+ EasyMock.expect(context.getTargetDataType()).andReturn(dataType).anyTimes();
+ EasyMock.replay(context);
+
+ javax.xml.transform.Transformer transformer =
+ TransformerFactory.newInstance().newTransformer();
+ Object data = new int[]{10, 20, 30, 40};
+ Node aNode = aTransformer.transform(data, context);
+ StringWriter sw = new StringWriter();
+ transformer.transform(new DOMSource(aNode), new StreamResult(sw));
+
+ assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><int_collection><int>10</int><int>20</int>"
+ + "<int>30</int><int>40</int></int_collection>",
+ sw.toString());
+ }
+
+ public static class SamplePropertyBean {
+ private float floatNumber = 50;
+ private SamplePropertyBean innerProperty;
+ private double doubleNumber = 75;
+ private int integerNumber = 25;
+ private String[] stringArray;
+
+ public SamplePropertyBean() {
+
+ }
+
+ double getDoubleNumber() {
+ return doubleNumber;
+ }
+
+ public void setDoubleNumber(double doubleNumber) {
+ this.doubleNumber = doubleNumber;
+ }
+
+ public float getFloatNumber() {
+ return floatNumber;
+ }
+
+ public void setFloatNumber(float floatNumber) {
+ this.floatNumber = floatNumber;
+ }
+
+ public int getIntegerNumber() {
+ return integerNumber;
+ }
+
+ public void setIntegerNumber(int integerNumber) {
+ this.integerNumber = integerNumber;
+ }
+
+ public SamplePropertyBean getInnerProperty() {
+ return innerProperty;
+ }
+
+ public void setInnerProperty(SamplePropertyBean prop) {
+ this.innerProperty = prop;
+ }
+
+ public String toString() {
+ return Double.toString(integerNumber + floatNumber + doubleNumber) + " & "
+ + ((innerProperty == null) ? "" : innerProperty.toString());
+ }
+
+ public String[] getStringArray() {
+ return stringArray;
+ }
+
+ public void setStringArray(String[] stringArray) {
+ this.stringArray = stringArray;
+ }
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/DOM2StAXTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/DOM2StAXTestCase.java
new file mode 100644
index 0000000000..942b2d67e9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/DOM2StAXTestCase.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.core.databinding.xml;
+
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.w3c.dom.Node;
+
+public class DOM2StAXTestCase extends TestCase {
+ private static final String IPO_XML =
+ "<?xml version=\"1.0\"?>" + "<ipo:purchaseOrder"
+ + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ + " xmlns:ipo=\"http://www.example.com/IPO\""
+ + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\""
+ + " orderDate=\"1999-12-01\">"
+ + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">"
+ + " <name>Helen Zoe</name>"
+ + " <street>47 Eden Street</street>"
+ + " <city>Cambridge</city>"
+ + " <postcode>CB1 1JR</postcode>"
+ + " </shipTo>"
+ + " <billTo xsi:type=\"ipo:USAddress\">"
+ + " <name>Robert Smith</name>"
+ + " <street>8 Oak Avenue</street>"
+ + " <city>Old Town</city>"
+ + " <state>PA</state>"
+ + " <zip>95819</zip>"
+ + " </billTo>"
+ + " <items>"
+ + " <item partNum=\"833-AA\">"
+ + " <productName>Lapis necklace</productName>"
+ + " <quantity>1</quantity>"
+ + " <USPrice>99.95</USPrice>"
+ + " <ipo:comment>Want this for the holidays</ipo:comment>"
+ + " <shipDate>1999-12-05</shipDate>"
+ + " </item>"
+ + " </items>"
+ + "</ipo:purchaseOrder>";
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testTransformation() {
+ String2Node t1 = new String2Node();
+ Node node = t1.transform(IPO_XML, null);
+ Node2XMLStreamReader t2 = new Node2XMLStreamReader();
+ XMLStreamReader reader = t2.transform(node, null);
+ XMLStreamReader2String t3 = new XMLStreamReader2String();
+ String xml = t3.transform(reader, null);
+ Assert.assertTrue(xml != null && xml.indexOf("<shipDate>1999-12-05</shipDate>") != -1);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/DataPipeTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/DataPipeTestCase.java
new file mode 100644
index 0000000000..d4eaf9b2a9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/DataPipeTestCase.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.core.databinding.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.databinding.impl.PipedTransformer;
+import org.apache.tuscany.spi.databinding.extension.DOMHelper;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Test case for DataPipe
+ */
+public class DataPipeTestCase extends TestCase {
+
+ public final void testStreamPipe() throws IOException {
+ byte[] bytes = new byte[] {1, 2, 3};
+ StreamDataPipe pipe = new StreamDataPipe();
+ Assert.assertSame(OutputStream.class, pipe.getSourceType());
+ Assert.assertSame(InputStream.class, pipe.getTargetType());
+ OutputStream os = pipe.getSink();
+ os.write(bytes);
+ byte[] newBytes = new byte[16];
+ int count = pipe.getResult().read(newBytes);
+ Assert.assertEquals(3, count);
+ for (int i = 0; i < bytes.length; i++) {
+ Assert.assertEquals(bytes[i], newBytes[i]);
+ }
+ }
+
+ public final void testWriter2ReaderPipe() throws IOException {
+ String str = "ABC";
+ Writer2ReaderDataPipe pipe = new Writer2ReaderDataPipe();
+ Assert.assertSame(Writer.class, pipe.getSourceType());
+ Assert.assertSame(Reader.class, pipe.getTargetType());
+ pipe.getSink().write(str);
+ char[] buf = new char[16];
+ int count = pipe.getResult().read(buf);
+ Assert.assertEquals(3, count);
+ for (int i = 0; i < str.length(); i++) {
+ Assert.assertEquals(str.charAt(i), buf[i]);
+ }
+ }
+
+ public final void testPiped() throws Exception {
+ Node2Writer node2Writer = new Node2Writer();
+ Writer2ReaderDataPipe pipe = new Writer2ReaderDataPipe();
+ PipedTransformer<Node, Writer, Reader> transformer =
+ new PipedTransformer<Node, Writer, Reader>(node2Writer, pipe);
+ Document document = DOMHelper.newDocument();
+ Element element = document.createElementNS("http://ns1", "root");
+ document.appendChild(element);
+ Reader reader = transformer.transform(document, null);
+ Assert.assertEquals(transformer.getWeight(), node2Writer.getWeight() + pipe.getWeight());
+ Assert.assertEquals(transformer.getSourceDataBinding(), node2Writer.getSourceDataBinding());
+ Assert.assertEquals(transformer.getTargetDataBinding(), pipe.getTargetDataBinding());
+ char[] buf = new char[120];
+ int count = reader.read(buf);
+ String xml = new String(buf, 0, count);
+ Assert.assertTrue(xml.contains("<root xmlns=\"http://ns1\"/>"));
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/Node2StringTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/Node2StringTestCase.java
new file mode 100755
index 0000000000..9b9aa3b893
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/Node2StringTestCase.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.core.databinding.xml;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.databinding.extension.DOMHelper;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class Node2StringTestCase extends TestCase {
+ public void testTransformation() throws Exception {
+ Document document = DOMHelper.newDocument();
+ Element element = document.createElementNS("http://ns1", "test");
+ document.appendChild(element);
+
+ new Node2String().transform(document, null);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/PushTransformationTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/PushTransformationTestCase.java
new file mode 100644
index 0000000000..a2318b2faa
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/PushTransformationTestCase.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.core.databinding.xml;
+
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.databinding.impl.PipedTransformer;
+import org.w3c.dom.Node;
+import org.xml.sax.ContentHandler;
+
+public class PushTransformationTestCase extends TestCase {
+ private static final String IPO_XML =
+ "<?xml version=\"1.0\"?>" + "<ipo:purchaseOrder"
+ + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ + " xmlns:ipo=\"http://www.example.com/IPO\""
+ + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\""
+ + " orderDate=\"1999-12-01\">"
+ + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">"
+ + " <name>Helen Zoe</name>"
+ + " <street>47 Eden Street</street>"
+ + " <city>Cambridge</city>"
+ + " <postcode>CB1 1JR</postcode>"
+ + " </shipTo>"
+ + " <billTo xsi:type=\"ipo:USAddress\">"
+ + " <name>Robert Smith</name>"
+ + " <street>8 Oak Avenue</street>"
+ + " <city>Old Town</city>"
+ + " <state>PA</state>"
+ + " <zip>95819</zip>"
+ + " </billTo>"
+ + " <items>"
+ + " <item partNum=\"833-AA\">"
+ + " <productName>Lapis necklace</productName>"
+ + " <quantity>1</quantity>"
+ + " <USPrice>99.95</USPrice>"
+ + " <ipo:comment>Want this for the holidays</ipo:comment>"
+ + " <shipDate>1999-12-05</shipDate>"
+ + " </item>"
+ + " </items>"
+ + "</ipo:purchaseOrder>";
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testTransformation() {
+ String2XMLStreamReader t1 = new String2XMLStreamReader();
+ XMLStreamReader reader = t1.transform(IPO_XML, null);
+ XMLStreamReader2SAX t2 = new XMLStreamReader2SAX();
+ PipedTransformer<XMLStreamReader, ContentHandler, Node> t3 =
+ new PipedTransformer<XMLStreamReader, ContentHandler, Node>(t2, new SAX2DOMPipe());
+ Node node = t3.transform(reader, null);
+ Assert.assertNotNull(node);
+ Node2String t4 = new Node2String();
+ String xml = t4.transform(node, null);
+ Assert.assertTrue(xml != null && xml.indexOf("<shipDate>1999-12-05</shipDate>") != -1);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/StAXHelperTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/StAXHelperTestCase.java
new file mode 100644
index 0000000000..7d18e83ac6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/StAXHelperTestCase.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.core.databinding.xml;
+
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+/**
+ * Test Case for StAXHelper
+ */
+public class StAXHelperTestCase extends TestCase {
+ private static final String XML =
+ "<a:foo xmlns:a='http://a' name='foo'><bar name='bar'>" + "<doo a:name='doo' xmlns:a='http://doo'/>"
+ + "</bar></a:foo>";
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testHelper() throws Exception {
+ XMLStreamReader reader = StAXHelper.createXMLStreamReader(XML);
+ String xml = StAXHelper.save(reader);
+ reader = StAXHelper.createXMLStreamReader(xml);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/TraxTransformerTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/TraxTransformerTestCase.java
new file mode 100644
index 0000000000..7e9494d423
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/TraxTransformerTestCase.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.core.databinding.xml;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.w3c.dom.Node;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ *
+ */
+public class TraxTransformerTestCase extends TestCase {
+ private URL url;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ url = getClass().getResource("foo.xml");
+ }
+
+ public void testTransformDOM() throws IOException {
+ InputStream is = url.openStream();
+ InputStream2Node t1 = new InputStream2Node();
+ Node node = t1.transform(is, null);
+ is.close();
+ Writer writer = new StringWriter();
+ Node2Writer t2 = new Node2Writer();
+ t2.transform(node, writer, null);
+ String str = writer.toString();
+ StringReader reader = new StringReader(str);
+ Reader2Node t3 = new Reader2Node();
+ node = t3.transform(reader, null);
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ Node2OutputStream t4 = new Node2OutputStream();
+ t4.transform(node, os, null);
+ InputSource inputSource = new InputSource(new ByteArrayInputStream(os.toByteArray()));
+ InputSource2Node t5 = new InputSource2Node();
+ node = t5.transform(inputSource, null);
+ }
+
+ public void testTransformSAX() throws IOException {
+ MyContentHandler handler = new MyContentHandler();
+ InputStream is = url.openStream();
+ InputStream2SAX t1 = new InputStream2SAX();
+ t1.transform(is, handler, null);
+ is.close();
+
+ String xml = "<foo xmlns=\"http://foo\">bar</foo>";
+
+ InputSource inputSource = new InputSource(new StringReader(xml));
+ InputSource2SAX t2 = new InputSource2SAX();
+ MyContentHandler handler2 = new MyContentHandler();
+ t2.transform(inputSource, handler2, null);
+
+ }
+
+ private static class MyContentHandler extends DefaultHandler {
+
+ @Override
+ public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
+ throws SAXException {
+ super.startElement(namespaceURI, localName, qName, atts);
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/deployer/BootstrapDeployerTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/deployer/BootstrapDeployerTestCase.java
new file mode 100644
index 0000000000..c98decc240
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/deployer/BootstrapDeployerTestCase.java
@@ -0,0 +1,181 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.deployer;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Map;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.builder.Connector;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ComponentManager;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.component.ScopeContainerMonitor;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.model.BindingDefinition;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.Include;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.PropertyValue;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.bootstrap.Bootstrapper;
+import org.apache.tuscany.core.bootstrap.DefaultBootstrapper;
+import org.apache.tuscany.core.builder.ConnectorImpl;
+import org.apache.tuscany.core.component.ComponentManagerImpl;
+import org.apache.tuscany.core.component.scope.ScopeRegistryImpl;
+import org.apache.tuscany.core.component.scope.CompositeScopeContainer;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation;
+import org.apache.tuscany.core.mock.component.BasicInterface;
+import org.apache.tuscany.core.monitor.NullMonitorFactory;
+import org.apache.tuscany.core.resolver.DefaultAutowireResolver;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+/**
+ * Verifies the default boostrap deployer
+ *
+ * @version $Rev$ $Date$
+ */
+public class BootstrapDeployerTestCase extends TestCase {
+ private DeployerImpl deployer;
+ private DeploymentContext deploymentContext;
+ private ComponentDefinition<SystemCompositeImplementation> componentDefinition;
+ private SystemCompositeImplementation implementation;
+ private URI componentId;
+
+ @SuppressWarnings("unchecked")
+ public void testBoot1Load() throws LoaderException {
+ Component parent = createNiceMock(Component.class);
+ URI uri = URI.create("sca://parent");
+ EasyMock.expect(parent.getUri()).andReturn(uri).atLeastOnce();
+ EasyMock.replay(parent);
+ URL scdl = BootstrapDeployerTestCase.class.getResource("boot1.scdl");
+ implementation.setScdlLocation(scdl);
+ deployer.load(parent, componentDefinition, deploymentContext);
+ CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> composite =
+ implementation.getComponentType();
+ assertNotNull(composite);
+ assertEquals(new QName("http://example.com", "boot1"), composite.getName());
+
+ // check parse of <service>
+ Map<String, ServiceDefinition> services = composite.getDeclaredServices();
+ assertEquals(1, services.size()); // included doesn't count
+ services = composite.getServices();
+ assertEquals(2, services.size()); // included counts
+ ServiceDefinition serviceDefinition = services.get("service");
+ assertNotNull(serviceDefinition);
+ assertEquals(componentId.resolve("#service"), serviceDefinition.getUri());
+ assertEquals(BasicInterface.class, serviceDefinition.getServiceContract().getInterfaceClass());
+ Collection<BindingDefinition> bindings = serviceDefinition.getBindings();
+ assertTrue(bindings.isEmpty());
+
+ // check parse of <component>
+ Map<String, ComponentDefinition<? extends Implementation<?>>> components = composite.getDeclaredComponents();
+ assertEquals(1, components.size()); // included doesn't count
+ components = composite.getComponents();
+ assertEquals(2, components.size()); // included counts
+ ComponentDefinition<? extends Implementation<?>> component = components.get("component");
+ assertNotNull(component);
+ PropertyValue<?> propVal = component.getPropertyValues().get("publicProperty");
+ assertEquals("propval", propVal.getValueFactory().getInstance());
+
+ // check introspection of implementation
+ ComponentType<?, ?, ?> componentType = component.getImplementation().getComponentType();
+ assertNotNull(componentType); // details checked in SystemComponentTypeLoaderTestCase
+
+ // check included component
+ Map<String, Include> includes = composite.getIncludes();
+ assertEquals(1, includes.size());
+ Include include = includes.get("boot1-include");
+ assertNotNull(include);
+ CompositeComponentType included = include.getIncluded();
+ assertNotNull(included);
+ assertEquals(1, included.getComponents().size());
+ }
+
+ public void testBoot1Deployment() throws Exception {
+ URL scdl = BootstrapDeployerTestCase.class.getResource("boot1.scdl");
+ implementation.setScdlLocation(scdl);
+ Component parent = EasyMock.createMock(Component.class);
+ replay(parent);
+ // load the boot1 file using the bootstrap deployer
+ componentDefinition.setUri(URI.create("sca://parent/simple"));
+ Collection<Component> components = deployer.deploy(parent, componentDefinition);
+ assertFalse(components.isEmpty());
+ verify(parent);
+ }
+
+ public void testBoot2Deployment() throws Exception {
+ URL scdl = BootstrapDeployerTestCase.class.getResource("boot2.scdl");
+ implementation.setScdlLocation(scdl);
+ Component parent = createNiceMock(Component.class);
+ replay(parent);
+ // load the boot2 file using the bootstrap deployer
+ componentDefinition.setUri(URI.create("newDeployer"));
+ Collection<Component> components = deployer.deploy(parent, componentDefinition);
+ assertFalse(components.isEmpty());
+ verify(parent);
+ for (Component component : components) {
+ component.start();
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ protected void setUp() throws Exception {
+ super.setUp();
+ componentId = URI.create("sca://localhost/parent");
+ XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
+ DefaultAutowireResolver resolver = new DefaultAutowireResolver();
+ ComponentManager manager = new ComponentManagerImpl(null, resolver);
+ Connector connector = new ConnectorImpl(manager);
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ JavaServiceContract<ComponentManager> contract = registry.introspect(ComponentManager.class);
+ manager.registerJavaObject(URI.create("ComponentManager"), contract, manager);
+ NullMonitorFactory monitorFactory = new NullMonitorFactory();
+
+ ScopeRegistry scopeRegistry = new ScopeRegistryImpl();
+ CompositeScopeContainer scopeContainer =
+ new CompositeScopeContainer(monitorFactory.getMonitor(ScopeContainerMonitor.class));
+ scopeContainer.start();
+ scopeRegistry.register(scopeContainer);
+
+ Bootstrapper bootstrapper =
+ new DefaultBootstrapper(monitorFactory, xmlFactory, manager, resolver, connector, scopeRegistry);
+ deployer = (DeployerImpl) bootstrapper.createDeployer();
+ deploymentContext = new RootDeploymentContext(null, null, componentId, xmlFactory, null, false);
+ implementation = new SystemCompositeImplementation();
+ implementation.setClassLoader(getClass().getClassLoader());
+ componentDefinition = new ComponentDefinition<SystemCompositeImplementation>(implementation);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/idl/java/ConversationalIntrospectionTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/idl/java/ConversationalIntrospectionTestCase.java
new file mode 100644
index 0000000000..e1cbaa2b0b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/idl/java/ConversationalIntrospectionTestCase.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.core.idl.java;
+
+import org.osoa.sca.annotations.Conversational;
+import org.osoa.sca.annotations.EndsConversation;
+
+import org.apache.tuscany.spi.idl.InvalidConversationalOperationException;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConversationalIntrospectionTestCase extends TestCase {
+ private JavaInterfaceProcessorRegistryImpl registry = new JavaInterfaceProcessorRegistryImpl();
+
+ public void testServiceContractConversationalInformationIntrospection() throws Exception {
+ JavaServiceContract<Foo> contract = registry.introspect(Foo.class);
+ assertTrue(contract.isConversational());
+ int seq = contract.getOperations().get("operation").getConversationSequence();
+ assertEquals(Operation.CONVERSATION_CONTINUE, seq);
+ seq = contract.getOperations().get("endOperation").getConversationSequence();
+ assertEquals(Operation.CONVERSATION_END, seq);
+ }
+
+ public void testBadServiceContract() throws Exception {
+ try {
+ registry.introspect(BadFoo.class);
+ fail();
+ } catch (InvalidConversationalOperationException e) {
+ //expected
+ }
+ }
+
+ public void testNonConversationalInformationIntrospection() throws Exception {
+ JavaServiceContract<NonConversationalFoo> contract = registry.introspect(NonConversationalFoo.class);
+ assertFalse(contract.isConversational());
+ int seq = contract.getOperations().get("operation").getConversationSequence();
+ assertEquals(Operation.NO_CONVERSATION, seq);
+ }
+
+ @Conversational
+ private interface Foo {
+ void operation();
+
+ @EndsConversation
+ void endOperation();
+ }
+
+ private interface BadFoo {
+ void operation();
+
+ @EndsConversation
+ void endOperation();
+ }
+
+ private interface NonConversationalFoo {
+ void operation();
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/idl/java/JavaInterfaceProcessorRegistryImplTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/idl/java/JavaInterfaceProcessorRegistryImplTestCase.java
new file mode 100644
index 0000000000..e3a7deb10a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/idl/java/JavaInterfaceProcessorRegistryImplTestCase.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.core.idl.java;
+
+import java.lang.reflect.Type;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessor;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.util.JavaIntrospectionHelper;
+import org.easymock.EasyMock;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaInterfaceProcessorRegistryImplTestCase extends TestCase {
+ private JavaInterfaceProcessorRegistryImpl impl;
+
+ public void testSimpleInterface() throws InvalidServiceContractException {
+ JavaServiceContract contract = impl.introspect(Simple.class);
+ // TODO spec to clairfy interface name
+ assertEquals(JavaIntrospectionHelper.getBaseName(Simple.class), contract.getInterfaceName());
+ assertEquals(Simple.class, contract.getInterfaceClass());
+ Map<String, Operation<Type>> operations = contract.getOperations();
+ assertEquals(1, operations.size());
+ Operation<Type> baseInt = operations.get("baseInt");
+ assertNotNull(baseInt);
+
+ DataType<Type> returnType = baseInt.getOutputType();
+ assertEquals(Integer.TYPE, returnType.getPhysical());
+ assertEquals(Integer.TYPE, returnType.getLogical());
+
+ List<DataType<Type>> parameterTypes = baseInt.getInputType().getLogical();
+ assertEquals(1, parameterTypes.size());
+ DataType<Type> arg0 = parameterTypes.get(0);
+ assertEquals(Integer.TYPE, arg0.getPhysical());
+ assertEquals(Integer.TYPE, arg0.getLogical());
+
+ List<DataType<Type>> faultTypes = baseInt.getFaultTypes();
+ assertEquals(1, faultTypes.size());
+ DataType<Type> fault0 = faultTypes.get(0);
+ assertEquals(IllegalArgumentException.class, fault0.getPhysical());
+ assertEquals(IllegalArgumentException.class, fault0.getLogical());
+ }
+
+ public void testUnregister() throws Exception {
+ JavaInterfaceProcessor processor = createMock(JavaInterfaceProcessor.class);
+ processor.visitInterface(eq(Base.class), EasyMock.same((Class)null), isA(JavaServiceContract.class));
+ expectLastCall().once();
+ replay(processor);
+ impl.registerProcessor(processor);
+ impl.introspect(Base.class);
+ impl.unregisterProcessor(processor);
+ impl.introspect(Base.class);
+ verify(processor);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ impl = new JavaInterfaceProcessorRegistryImpl();
+
+ }
+
+ private static interface Base {
+ int baseInt(int param) throws IllegalArgumentException;
+ }
+
+ private static interface Simple extends Base {
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/IntrospectionRegistryTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/IntrospectionRegistryTestCase.java
new file mode 100644
index 0000000000..622e8e479a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/IntrospectionRegistryTestCase.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.core.implementation;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessor;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.IntrospectionRegistryImpl.Monitor;
+import org.apache.tuscany.core.monitor.NullMonitorFactory;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class IntrospectionRegistryTestCase extends TestCase {
+
+ private Monitor monitor;
+
+ public void testRegister() throws Exception {
+ IntrospectionRegistryImpl registry = new IntrospectionRegistryImpl(monitor);
+ ImplementationProcessor processor = EasyMock.createNiceMock(ImplementationProcessor.class);
+ registry.registerProcessor(processor);
+ }
+
+ public void testUnegister() throws Exception {
+ IntrospectionRegistryImpl registry = new IntrospectionRegistryImpl(monitor);
+ ImplementationProcessor processor = EasyMock.createNiceMock(ImplementationProcessor.class);
+ registry.registerProcessor(processor);
+ registry.unregisterProcessor(processor);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testWalk() throws Exception {
+ IntrospectionRegistryImpl registry = new IntrospectionRegistryImpl(monitor);
+ ImplementationProcessor processor = EasyMock.createMock(ImplementationProcessor.class);
+ processor.visitClass(
+ EasyMock.eq(Bar.class),
+ EasyMock.isA(PojoComponentType.class),
+ EasyMock.isA(DeploymentContext.class));
+ processor.visitConstructor(
+ EasyMock.isA(Constructor.class),
+ EasyMock.isA(PojoComponentType.class),
+ EasyMock.isA(DeploymentContext.class));
+ processor.visitMethod(
+ EasyMock.isA(Method.class),
+ EasyMock.isA(PojoComponentType.class),
+ EasyMock.isA(DeploymentContext.class));
+ processor.visitField(
+ EasyMock.isA(Field.class),
+ EasyMock.isA(PojoComponentType.class),
+ EasyMock.isA(DeploymentContext.class));
+ processor.visitSuperClass(
+ EasyMock.isA(Class.class),
+ EasyMock.isA(PojoComponentType.class),
+ EasyMock.isA(DeploymentContext.class));
+ processor.visitEnd(
+ EasyMock.isA(Class.class),
+ EasyMock.isA(PojoComponentType.class),
+ EasyMock.isA(DeploymentContext.class));
+
+ // mock.expects(once()).method("visitClass");
+// mock.expects(once()).method("visitMethod");
+// mock.expects(once()).method("visitField");
+// mock.expects(once()).method("visitConstructor");
+// mock.expects(once()).method("visitSuperClass");
+// mock.expects(once()).method("visitEnd");
+ EasyMock.replay(processor);
+ registry.registerProcessor(processor);
+ registry.introspect(
+ Bar.class,
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(),
+ EasyMock.createNiceMock(DeploymentContext.class));
+ EasyMock.verify(processor);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ monitor = new NullMonitorFactory().getMonitor(Monitor.class);
+ }
+
+ private class Baz {
+
+ }
+
+ private class Bar extends Baz {
+
+ protected String bar;
+
+ public Bar() {
+ }
+
+ public void bar() {
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PhysicalComponentTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PhysicalComponentTestCase.java
new file mode 100644
index 0000000000..7ea0793c16
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PhysicalComponentTestCase.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.core.implementation;
+
+import junit.framework.TestCase;
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.Init;
+
+import org.apache.tuscany.core.component.InstanceFactory;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.core.component.scope.InstanceWrapperBase;
+import org.apache.tuscany.spi.component.TargetDestructionException;
+import org.apache.tuscany.spi.component.TargetInitializationException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PhysicalComponentTestCase extends TestCase {
+ public void testSomething() {
+
+ }
+
+ /**
+ * This is the class supplied by the user.
+ */
+ public static class UserImplementation {
+ @Init
+ void init() {
+ }
+
+ @Destroy
+ void destroy() {
+ }
+ }
+
+ /**
+ * This is the generated wrapper class.
+ */
+ public static class UserWrapper extends InstanceWrapperBase<UserImplementation> {
+ public UserWrapper(UserImplementation instance) {
+ super(instance);
+ }
+
+ public void start() throws TargetInitializationException {
+ instance.init();
+ super.start();
+ }
+
+ public void stop() throws TargetDestructionException {
+ super.stop();
+ instance.destroy();
+ }
+ }
+
+ /**
+ * This is the generated factory class.
+ */
+ public static class UserFactory implements InstanceFactory<UserImplementation> {
+ public InstanceWrapper<UserImplementation> newInstance() {
+ UserImplementation instance = new UserImplementation();
+ return new UserWrapper(instance);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PojoAtomicComponentTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PojoAtomicComponentTestCase.java
new file mode 100644
index 0000000000..a38ca310b4
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PojoAtomicComponentTestCase.java
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.injection.EventInvoker;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PojoAtomicComponentTestCase extends TestCase {
+ private PojoConfiguration config;
+ private URI groupId;
+
+ @SuppressWarnings({"unchecked"})
+ public void testNoCallbackWires() throws Exception {
+ AtomicComponent component = new TestAtomicComponent(config);
+ ScopeContainer container = EasyMock.createMock(ScopeContainer.class);
+ EasyMock.expect(container.getScope()).andReturn(Scope.CONVERSATION);
+ container.register(component, groupId);
+ EasyMock.replay(container);
+ config.addCallbackSite("callback", Foo.class.getMethod("setCallback", Object.class));
+ component.setScopeContainer(container);
+ component.start();
+ EasyMock.verify(container);
+ }
+
+ public void testOptimizable() throws Exception {
+ TestAtomicComponent component = new TestAtomicComponent(config);
+ assertTrue(component.isOptimizable());
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void testDestroyableButOptimizable() throws Exception {
+ EventInvoker<Object> invoker = EasyMock.createMock(EventInvoker.class);
+ invoker.invokeEvent(EasyMock.notNull());
+ EasyMock.replay(invoker);
+ config.setDestroyInvoker(invoker);
+ TestAtomicComponent component = new TestAtomicComponent(config);
+ assertTrue(component.isOptimizable());
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void testStatelessOptimizable() throws Exception {
+ TestAtomicComponent component = new TestAtomicComponent(config, Scope.STATELESS);
+ assertTrue(component.isOptimizable());
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public void testNotOptimizable() throws Exception {
+ EventInvoker<Object> invoker = EasyMock.createMock(EventInvoker.class);
+ invoker.invokeEvent(EasyMock.notNull());
+ EasyMock.replay(invoker);
+ config.setDestroyInvoker(invoker);
+ TestAtomicComponent component = new TestAtomicComponent(config, Scope.STATELESS);
+ assertFalse(component.isOptimizable());
+ }
+
+ public void testPropertyAccess() {
+ String value = "Foo!";
+ ObjectFactory objectFactory = EasyMock.createMock(ObjectFactory.class);
+ EasyMock.expect(objectFactory.getInstance()).andReturn(value);
+ EasyMock.replay(objectFactory);
+
+ TestAtomicComponent component = new TestAtomicComponent(config);
+ component.addPropertyFactory("foo", objectFactory);
+ assertSame(value, component.getProperty(String.class, "foo"));
+ }
+
+ public void testServiceLookup() {
+ URI uri = URI.create("#service");
+ FooService foo = EasyMock.createMock(FooService.class);
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.getSourceUri()).andReturn(uri).atLeastOnce();
+ EasyMock.replay(wire);
+ ObjectFactory factory = EasyMock.createMock(ObjectFactory.class);
+ EasyMock.expect(factory.getInstance()).andReturn(foo);
+ EasyMock.replay(factory);
+ TestAtomicComponent component = new TestAtomicComponent(config, Scope.COMPOSITE, factory);
+ component.attachWire(wire);
+ assertSame(foo, component.getService(FooService.class, "service"));
+ EasyMock.verify(wire);
+ EasyMock.verify(factory);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ PojoObjectFactory<Foo> factory = new PojoObjectFactory<Foo>(Foo.class.getConstructor());
+
+ config = new PojoConfiguration();
+ config.setInstanceFactory(factory);
+ config.setName(URI.create("foo"));
+ groupId = URI.create("parent");
+ config.setGroupId(groupId);
+ }
+
+ private class TestAtomicComponent extends PojoAtomicComponent {
+ private final ObjectFactory factory;
+ private final Scope scope;
+
+ public TestAtomicComponent(PojoConfiguration configuration) {
+ this(configuration, Scope.COMPOSITE, null);
+ }
+
+ public TestAtomicComponent(PojoConfiguration configuration, Scope scope) {
+ this(configuration, scope, null);
+ }
+
+ public TestAtomicComponent(PojoConfiguration configuration, Scope scope, ObjectFactory factory) {
+ super(configuration);
+ this.scope = scope;
+ this.factory = factory;
+ }
+
+ public Scope getScope() {
+ return scope;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ protected <B> ObjectFactory<B> createWireFactory(Class<B> interfaze, Wire wire) {
+ return factory;
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, Operation operation)
+ throws TargetInvokerCreationException {
+ return null;
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, PhysicalOperationDefinition operation)
+ throws TargetInvokerCreationException {
+ return null;
+ }
+ }
+
+ private static class Foo {
+ public Foo() {
+ }
+
+ public void setCallback(Object callback) {
+
+ }
+ }
+
+ public static interface FooService {
+ }
+
+}
+
+
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PojoComponentTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PojoComponentTestCase.java
new file mode 100644
index 0000000000..44a51ef362
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PojoComponentTestCase.java
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation;
+
+import java.net.URI;
+import java.util.Collections;
+import java.util.List;
+
+import junit.framework.TestCase;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
+
+import org.apache.tuscany.core.component.InstanceFactory;
+import org.apache.tuscany.core.component.InstanceFactoryProvider;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PojoComponentTestCase<T> extends TestCase {
+ private URI componentId;
+ private PojoComponent component;
+ private InstanceFactoryProvider<T> provider;
+ private InstanceFactory<T> instanceFactory;
+ private InstanceWrapper<T> wrapper;
+ private ScopeContainer scopeContainer;
+ private Wire wire;
+ private List<Wire> wires;
+
+ public void testConversationAttributes() {
+ TestComponent<T> component = new TestComponent<T>(componentId, null, null, 0, 12, 34);
+ assertEquals(0, component.getInitLevel());
+ assertEquals(false, component.isEagerInit());
+ assertEquals(12, component.getMaxIdleTime());
+ assertEquals(34, component.getMaxAge());
+ }
+
+ public void testEagerInit() {
+ TestComponent<T> component = new TestComponent<T>(componentId, null, null, 50, 12, 34);
+ assertEquals(50, component.getInitLevel());
+ assertEquals(true, component.isEagerInit());
+ assertEquals(12, component.getMaxIdleTime());
+ assertEquals(34, component.getMaxAge());
+ }
+
+ public void testLifecycleAndWrapperCreation() {
+ // test start method creates the factory
+ expect(provider.createFactory()).andReturn(instanceFactory);
+ scopeContainer.register(component, null);
+ replay(provider, instanceFactory, wrapper, scopeContainer);
+ component.start();
+ verify(provider, instanceFactory, wrapper, scopeContainer);
+
+ // test creating an wrapper calls the factory
+ // we piggyback this here has the component needs to be started for the factory to be active
+ reset(provider, instanceFactory, wrapper, scopeContainer);
+ expect(instanceFactory.newInstance()).andReturn(wrapper);
+ replay(provider, instanceFactory, wrapper, scopeContainer);
+ component.createInstanceWrapper();
+ verify(provider, instanceFactory, wrapper, scopeContainer);
+
+ // test stop method
+ reset(provider, instanceFactory, wrapper, scopeContainer);
+ scopeContainer.unregister(component);
+ replay(provider, instanceFactory, wrapper, scopeContainer);
+ component.stop();
+ verify(provider, instanceFactory, wrapper, scopeContainer);
+ }
+
+/*
+ public void testAttachSingleReferenceWire() {
+ provider.attachWire(wire);
+ replay(provider);
+ component.attachWire(wire);
+ verify(provider);
+ }
+
+ public void testAttachMultipleReferenceWire() {
+ provider.attachWires(wires);
+ replay(provider);
+ component.attachWires(wires);
+ verify(provider);
+ }
+
+ public void testAttachCallbackWire() {
+ provider.attachCallbackWire(wire);
+ replay(provider);
+ component.attachCallbackWire(wire);
+ verify(provider);
+ }
+*/
+
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+ componentId = URI.create("sca://./component");
+ provider = createNiceMock(InstanceFactoryProvider.class);
+ instanceFactory = createNiceMock(InstanceFactory.class);
+ wrapper = createNiceMock(InstanceWrapper.class);
+ scopeContainer = createNiceMock(ScopeContainer.class);
+ wire = createNiceMock(Wire.class);
+ wires = Collections.singletonList(wire);
+ component = new TestComponent<T>(componentId, provider, scopeContainer, 0, -1, -1);
+ }
+
+ public static class TestComponent<T> extends PojoComponent<T> {
+
+ public TestComponent(URI componentId,
+ InstanceFactoryProvider<T> instanceFactoryProvider,
+ ScopeContainer scopeContainer,
+ int initLevel,
+ long maxIdleTime,
+ long maxAge) {
+ super(componentId, instanceFactoryProvider, scopeContainer, null, initLevel, maxIdleTime, maxAge);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeBuilderTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeBuilderTestCase.java
new file mode 100644
index 0000000000..96808add34
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeBuilderTestCase.java
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.composite;
+
+import java.net.URI;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ScopeContainerMonitor;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.binding.local.LocalBindingBuilder;
+import org.apache.tuscany.core.binding.local.LocalBindingDefinition;
+import org.apache.tuscany.core.builder.BuilderRegistryImpl;
+import org.apache.tuscany.core.component.scope.CompositeScopeContainer;
+import org.apache.tuscany.core.deployer.RootDeploymentContext;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.java.JavaComponentBuilder;
+import org.apache.tuscany.core.implementation.java.JavaImplementation;
+import org.apache.tuscany.core.mock.component.OtherTarget;
+import org.apache.tuscany.core.mock.component.Source;
+import org.apache.tuscany.core.mock.component.SourceImpl;
+import org.apache.tuscany.core.mock.component.Target;
+import org.apache.tuscany.core.mock.component.TargetImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public class CompositeBuilderTestCase extends TestCase {
+ private static final URI TOP_COMPONENT = URI.create("Top");
+ private static final URI SOURCE_COMPONENT = URI.create("Top/Parent/SourceComponent");
+ private static final URI TARGET_COMPONENT = URI.create("Top/Parent/TargetComponent");
+ private static final URI INNER_SOURCE_COMPONENT = URI.create("Top/Parent/SourceComponent/InnerSourceComponent");
+
+ private DeploymentContext deploymentContext;
+
+ @SuppressWarnings("unchecked")
+ public void testBuild() throws Exception {
+ CompositeBuilder builder = new CompositeBuilder();
+ BuilderRegistryImpl builderRegistry = new BuilderRegistryImpl(null);
+ JavaComponentBuilder jBuilder = new JavaComponentBuilder();
+ builderRegistry.register(JavaImplementation.class, jBuilder);
+ builderRegistry.register(CompositeImplementation.class, builder);
+ builderRegistry.register(LocalBindingDefinition.class, new LocalBindingBuilder());
+ builder.setBuilderRegistry(builderRegistry);
+
+ Component component =
+ builder.build(createTopComponentDef(), deploymentContext);
+ Map<URI, Component> components = deploymentContext.getComponents();
+ Component sourceComponent = components.get(SOURCE_COMPONENT);
+ assertNotNull(sourceComponent.getService("InnerSourceService"));
+ AtomicComponent innerSourceComponent = (AtomicComponent) components.get(INNER_SOURCE_COMPONENT);
+ assertNotNull(innerSourceComponent);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ ScopeContainerMonitor monitor = EasyMock.createNiceMock(ScopeContainerMonitor.class);
+ CompositeScopeContainer container = new CompositeScopeContainer(monitor);
+ container.start();
+ deploymentContext = new RootDeploymentContext(null, null, TOP_COMPONENT, null, container, false);
+ }
+
+ private ComponentDefinition createTopComponentDef() throws Exception {
+ CompositeComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> outerType =
+ new CompositeComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ outerType.add(createSourceComponentDef());
+ outerType.add(createTargetComponentDef());
+
+ CompositeImplementation outerImpl = new CompositeImplementation();
+ outerImpl.setComponentType(outerType);
+
+ ComponentDefinition def = new ComponentDefinition<CompositeImplementation>(outerImpl);
+ def.setUri(TOP_COMPONENT);
+ return def;
+ }
+
+ private ComponentDefinition<CompositeImplementation> createSourceComponentDef() throws Exception {
+
+ CompositeComponentType<ServiceDefinition, ReferenceDefinition, JavaMappedProperty<?>> innerType =
+ new CompositeComponentType<ServiceDefinition, ReferenceDefinition, JavaMappedProperty<?>>();
+ innerType.add(createInnerSourceComponentDef());
+ ReferenceDefinition reference = new ReferenceDefinition();
+ reference.setUri(URI.create("#TargetComponentRef"));
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ JavaServiceContract targetContract = registry.introspect(Target.class);
+ reference.setServiceContract(targetContract);
+ innerType.add(reference);
+ ServiceDefinition service = new ServiceDefinition();
+ service.setUri(URI.create("#InnerSourceService"));
+ JavaServiceContract sourceContract = registry.introspect(Source.class);
+ service.setServiceContract(sourceContract);
+ service.setTarget(INNER_SOURCE_COMPONENT);
+ innerType.add(service);
+
+ CompositeImplementation innerImpl = new CompositeImplementation();
+ innerImpl.setComponentType(innerType);
+
+ ComponentDefinition<CompositeImplementation> sourceComponentDefinition =
+ new ComponentDefinition<CompositeImplementation>(SOURCE_COMPONENT, innerImpl);
+ ReferenceTarget refTarget = new ReferenceTarget();
+ refTarget.setReferenceName(URI.create("#TargetComponentRef"));
+ refTarget.addTarget(TARGET_COMPONENT);
+ sourceComponentDefinition.add(refTarget);
+
+ return sourceComponentDefinition;
+ }
+
+ private ComponentDefinition<JavaImplementation> createInnerSourceComponentDef() throws Exception {
+
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> sourceType =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ sourceType.setImplementationScope(Scope.COMPOSITE);
+ JavaMappedReference reference = new JavaMappedReference();
+ reference.setUri(URI.create("#targetReference"));
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ ServiceContract<?> targetContract = registry.introspect(Target.class);
+ targetContract.setCallbackClass(OtherTarget.class);
+ targetContract.setCallbackName("OtherTarget");
+ reference.setServiceContract(targetContract);
+ reference.setMember(SourceImpl.class.getMethod("setTarget", Target.class));
+ sourceType.add(reference);
+
+ ServiceContract<?> sourceContract = registry.introspect(Source.class);
+
+ JavaMappedService sourceServiceDefinition = new JavaMappedService();
+ sourceServiceDefinition.setUri(URI.create("#Source"));
+ sourceServiceDefinition.setServiceContract(sourceContract);
+
+ sourceType.add(sourceServiceDefinition);
+ sourceType.setConstructorDefinition(new ConstructorDefinition<SourceImpl>(SourceImpl.class.getConstructor()));
+ JavaImplementation sourceImpl = new JavaImplementation(SourceImpl.class, sourceType);
+ ComponentDefinition<JavaImplementation> innerSourceComponentDefinition =
+ new ComponentDefinition<JavaImplementation>(INNER_SOURCE_COMPONENT, sourceImpl);
+ ReferenceTarget refTarget = new ReferenceTarget();
+ refTarget.setReferenceName(URI.create("#targetReference"));
+ refTarget.addTarget(new URI("#TargetComponentRef"));
+ innerSourceComponentDefinition.add(refTarget);
+
+ return innerSourceComponentDefinition;
+ }
+
+ private ComponentDefinition<JavaImplementation> createTargetComponentDef() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> targetType =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ targetType.setImplementationScope(Scope.COMPOSITE);
+
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ ServiceContract<?> targetContract = registry.introspect(Target.class);
+ targetContract.setCallbackClass(OtherTarget.class);
+ targetContract.setCallbackName("OtherTarget");
+
+ JavaMappedService serviceDefinition = new JavaMappedService();
+ serviceDefinition.setUri(URI.create("Target"));
+ serviceDefinition.setServiceContract(targetContract);
+ serviceDefinition.setCallbackReferenceName("otherTarget");
+
+ targetType.add(serviceDefinition);
+ targetType.setConstructorDefinition(new ConstructorDefinition<TargetImpl>(TargetImpl.class.getConstructor()));
+ JavaImplementation targetImpl = new JavaImplementation(TargetImpl.class, targetType);
+ //URI uri = URI.create("TargetComponent");
+ return new ComponentDefinition<JavaImplementation>(TARGET_COMPONENT, targetImpl);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplTestCase.java
new file mode 100644
index 0000000000..a5574c7f78
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplTestCase.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.core.implementation.composite;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.event.Event;
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+import org.apache.tuscany.spi.model.Scope;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CompositeComponentImplTestCase extends TestCase {
+
+ public void testGetScope() {
+ Component composite = new CompositeComponentImpl(URI.create("parent"));
+ Assert.assertEquals(Scope.SYSTEM, composite.getScope());
+ }
+
+ public void testRegisterService() throws Exception {
+ Component composite = new CompositeComponentImpl(URI.create("parent"));
+ Service service = new ServiceImpl(URI.create("foo#service"), null);
+ composite.register(service);
+ assertNotNull(composite.getService("service"));
+ }
+
+ public void testRegisterReference() throws Exception {
+ Component composite = new CompositeComponentImpl(URI.create("parent"));
+ Reference reference = new ReferenceImpl(URI.create("foo#reference"), null);
+ composite.register(reference);
+ assertNotNull(composite.getReference("reference"));
+ }
+
+ public void testOnEvent() {
+ CompositeComponentImpl composite = new CompositeComponentImpl(URI.create("parent"));
+ Event event = new Event() {
+ public Object getSource() {
+ return null;
+ }
+ };
+ RuntimeEventListener listener = createMock(RuntimeEventListener.class);
+ listener.onEvent(eq(event));
+ expectLastCall();
+ replay(listener);
+ composite.addListener(listener);
+ composite.start();
+ composite.onEvent(event);
+ EasyMock.verify(listener);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLoaderTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLoaderTestCase.java
new file mode 100644
index 0000000000..84c5825e82
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLoaderTestCase.java
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.composite;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.ModelObject;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.deployer.RootDeploymentContext;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CompositeLoaderTestCase extends TestCase {
+ public static final QName COMPOSITE = new QName(SCA_NS, "composite");
+ private CompositeLoader loader;
+ private QName name;
+
+ public void testLoadNameAndDefaultAutowire() throws Exception {
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn(name.getLocalPart());
+ EasyMock.expect(reader.getAttributeValue(null, "targetNamespace")).andReturn(name.getNamespaceURI());
+ EasyMock.expect(reader.getAttributeValue(null, "autowire")).andReturn(null);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(COMPOSITE);
+ EasyMock.replay(reader);
+ CompositeComponentType<?, ?, ?> type = loader.load(null, reader, null);
+ assertEquals(name, type.getName());
+ assertFalse(type.isAutowire());
+ EasyMock.verify(reader);
+ }
+
+ public void testAutowire() throws Exception {
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn(name.getLocalPart());
+ EasyMock.expect(reader.getAttributeValue(null, "targetNamespace")).andReturn(name.getNamespaceURI());
+ EasyMock.expect(reader.getAttributeValue(null, "autowire")).andReturn("true");
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(COMPOSITE);
+ EasyMock.replay(reader);
+ CompositeComponentType<?, ?, ?> type = loader.load(null, reader, null);
+ assertTrue(type.isAutowire());
+ EasyMock.verify(reader);
+ }
+
+ /**
+ * Tests autowire enabled is propagated when children are loaded
+ */
+ public void testAutowireContextEnabledPropagation() throws Exception {
+ LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class);
+ registry.load(EasyMock.isA(ModelObject.class),
+ EasyMock.isA(XMLStreamReader.class),
+ EasyMock.isA(DeploymentContext.class));
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ DeploymentContext context = (DeploymentContext) EasyMock.getCurrentArguments()[2];
+ assertTrue("autowire not propagated", context.isAutowire());
+ return null;
+ }
+ });
+ EasyMock.replay(registry);
+ DeploymentContext context = new RootDeploymentContext(null, null, null, null, null, true);
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn(name.getLocalPart());
+ EasyMock.expect(reader.getAttributeValue(null, "targetNamespace")).andReturn(name.getNamespaceURI());
+ EasyMock.expect(reader.getAttributeValue(null, "autowire")).andReturn("true");
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(COMPOSITE);
+ EasyMock.replay(reader);
+ loader.load(null, reader, context);
+ assertTrue(context.isAutowire());
+ }
+
+ /**
+ * Tests autowire enabled is propagated when children are loaded and composite is set to use inherited autowire
+ * settings
+ */
+ public void testAutowireContextEnabledInheritedPropagation() throws Exception {
+ LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class);
+ registry.load(EasyMock.isA(ModelObject.class),
+ EasyMock.isA(XMLStreamReader.class),
+ EasyMock.isA(DeploymentContext.class));
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ DeploymentContext context = (DeploymentContext) EasyMock.getCurrentArguments()[2];
+ assertTrue("autowire not propagated", context.isAutowire());
+ return null;
+ }
+ });
+ EasyMock.replay(registry);
+ DeploymentContext context = new RootDeploymentContext(null, null, null, null, null, true);
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn(name.getLocalPart());
+ EasyMock.expect(reader.getAttributeValue(null, "targetNamespace")).andReturn(name.getNamespaceURI());
+ EasyMock.expect(reader.getAttributeValue(null, "autowire")).andReturn(null);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(COMPOSITE);
+ EasyMock.replay(reader);
+ loader.load(null, reader, context);
+ assertTrue(context.isAutowire());
+ }
+
+ /**
+ * Tests autowire false is propagated when children are loaded and composite inherits autowire settings
+ */
+ public void testAutowireFalseContextPropagation() throws Exception {
+ LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class);
+ registry.load(EasyMock.isA(ModelObject.class),
+ EasyMock.isA(XMLStreamReader.class),
+ EasyMock.isA(DeploymentContext.class));
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ DeploymentContext context = (DeploymentContext) EasyMock.getCurrentArguments()[2];
+ assertFalse("autowire not propagated", context.isAutowire());
+ return null;
+ }
+ });
+ EasyMock.replay(registry);
+ DeploymentContext context = new RootDeploymentContext(null, null, null, null, null, false);
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn(name.getLocalPart());
+ EasyMock.expect(reader.getAttributeValue(null, "targetNamespace")).andReturn(name.getNamespaceURI());
+ EasyMock.expect(reader.getAttributeValue(null, "autowire")).andReturn(null);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(COMPOSITE);
+ EasyMock.replay(reader);
+ loader.load(null, reader, context);
+ assertFalse(context.isAutowire());
+ }
+
+ /**
+ * Tests autowire false is propagated when children are loaded and composite autowire is set to false
+ */
+ public void testAutowireCompositeFalsePropagation() throws Exception {
+ LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class);
+ registry.load(EasyMock.isA(ModelObject.class),
+ EasyMock.isA(XMLStreamReader.class),
+ EasyMock.isA(DeploymentContext.class));
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ DeploymentContext context = (DeploymentContext) EasyMock.getCurrentArguments()[2];
+ assertFalse("autowire not propagated", context.isAutowire());
+ return null;
+ }
+ });
+ EasyMock.replay(registry);
+ DeploymentContext context = new RootDeploymentContext(null, null, null, null, null, true);
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn(name.getLocalPart());
+ EasyMock.expect(reader.getAttributeValue(null, "targetNamespace")).andReturn(name.getNamespaceURI());
+ EasyMock.expect(reader.getAttributeValue(null, "autowire")).andReturn("false");
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(COMPOSITE);
+ EasyMock.replay(reader);
+ loader.load(null, reader, context);
+ assertTrue(context.isAutowire());
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ LoaderRegistry registry = EasyMock.createNiceMock(LoaderRegistry.class);
+ EasyMock.replay(registry);
+ loader = new CompositeLoader(registry, null);
+ name = new QName("http://example.com", "composite");
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLoaderWireResolutionTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLoaderWireResolutionTestCase.java
new file mode 100644
index 0000000000..47574c02b6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLoaderWireResolutionTestCase.java
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.implementation.composite;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.loader.InvalidWireException;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.model.WireDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.java.JavaImplementation;
+
+/**
+ * This class tests the wire resolution function of the composite loader
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeLoaderWireResolutionTestCase extends TestCase {
+ private CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> componentType;
+ private CompositeLoader compositeLoader = new CompositeLoader(null, null);
+
+ public void testCompositeSvc2CompositeReferenceWire() throws Exception {
+ WireDefinition wireDefn = new WireDefinition();
+ wireDefn.setSource(new URI("compositeService1"));
+ wireDefn.setTarget(new URI("compositeReference"));
+ componentType.add(wireDefn);
+ compositeLoader.resolveWires(componentType);
+ }
+
+ public void testCompositeSvc2ComponentValid() throws Exception {
+ //undefined source and targets
+ WireDefinition wireDefn = new WireDefinition();
+ wireDefn.setSource(new URI("compositeService1"));
+ wireDefn.setTarget(new URI("Component1"));
+ componentType.add(wireDefn);
+ compositeLoader.resolveWires(componentType);
+ }
+
+ public void testCompositeSvc2ComponentQualifiedValid() throws Exception {
+ //undefined source and targets
+ WireDefinition wireDefn = new WireDefinition();
+ wireDefn.setSource(new URI("compositeService1"));
+ wireDefn.setTarget(new URI("Component2#pojoSvc3"));
+ componentType.add(wireDefn);
+ compositeLoader.resolveWires(componentType);
+ }
+
+ public void testCompositeSvc2ComponentQualifiedInvalid() throws URISyntaxException {
+ //undefined source and targets
+ WireDefinition wireDefn = new WireDefinition();
+ wireDefn.setSource(new URI("compositeService1"));
+ wireDefn.setTarget(new URI("Component2#pojoSvc5"));
+ componentType.add(wireDefn);
+ try {
+ compositeLoader.resolveWires(componentType);
+ fail();
+ } catch (InvalidWireException e) {
+ // expected
+ }
+ }
+
+ public void testCompositeSvc2ComponentUnQualifiedInvalid() throws URISyntaxException {
+ //undefined source and targets
+ WireDefinition wireDefn = new WireDefinition();
+ wireDefn.setSource(new URI("compositeService1"));
+ wireDefn.setTarget(new URI("Component2"));
+ componentType.add(wireDefn);
+ try {
+ compositeLoader.resolveWires(componentType);
+ fail();
+ } catch (InvalidWireException e) {
+ // expected
+ }
+ }
+
+ public void testComponent2CompositeReferenceValid() throws Exception {
+ //undefined source and targets
+ WireDefinition wireDefn = new WireDefinition();
+ wireDefn.setSource(new URI("Component1#pojoRef1"));
+ wireDefn.setTarget(new URI("compositeReference"));
+ componentType.add(wireDefn);
+ compositeLoader.resolveWires(componentType);
+ }
+
+ public void testComponent2CompositeReferenceQualifiedValid() throws Exception {
+ //undefined source and targets
+ WireDefinition wireDefn = new WireDefinition();
+ wireDefn.setSource(new URI("Component2#pojoRef3"));
+ wireDefn.setTarget(new URI("compositeReference"));
+ componentType.add(wireDefn);
+ compositeLoader.resolveWires(componentType);
+ }
+
+ public void testComponent2CompositeReferenceUnQualifiedInvalid() throws URISyntaxException {
+ //undefined source and targets
+ WireDefinition wireDefn = new WireDefinition();
+ wireDefn.setSource(new URI("Component2"));
+ wireDefn.setTarget(new URI("compositeReference"));
+ componentType.add(wireDefn);
+
+ try {
+ compositeLoader.resolveWires(componentType);
+ fail();
+ } catch (InvalidWireException e) {
+ // expected
+ }
+ }
+
+ public void testComponent2ComponentQualifedValid() throws Exception {
+ WireDefinition wireDefn = new WireDefinition();
+ wireDefn.setSource(new URI("Component1#pojoRef1"));
+ wireDefn.setTarget(new URI("Component2#pojoSvc3"));
+ componentType.add(wireDefn);
+ compositeLoader.resolveWires(componentType);
+ }
+
+ public void testComponent2ComponentUnQualifedInvalid() throws URISyntaxException {
+ //undefined source and targets
+ WireDefinition wireDefn = new WireDefinition();
+ wireDefn.setSource(new URI("Component1"));
+ wireDefn.setTarget(new URI("Component2"));
+ componentType.add(wireDefn);
+ try {
+ compositeLoader.resolveWires(componentType);
+ fail();
+ } catch (InvalidWireException e) {
+ // expected
+ }
+ }
+
+ public void testInvalidWireDefinitions() throws URISyntaxException {
+ //undefined source and targets
+ WireDefinition wireDefn = new WireDefinition();
+ wireDefn.setSource(new URI("undefinedSource"));
+ wireDefn.setTarget(new URI("compositeReference"));
+ componentType.add(wireDefn);
+
+ try {
+ compositeLoader.resolveWires(componentType);
+ fail();
+ } catch (InvalidWireException e) {
+ // expected
+ }
+
+ try {
+ wireDefn.setSource(new URI("compositeService1"));
+ wireDefn.setTarget(new URI("undefinedTarget"));
+ componentType.add(wireDefn);
+ compositeLoader.resolveWires(componentType);
+ fail();
+ } catch (InvalidWireException e) {
+ // expected
+ }
+ }
+
+ public void setUp() throws Exception {
+ componentType = new CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+
+ //add a service to the composite
+ ServiceDefinition serviceDefn = new ServiceDefinition(URI.create("#compositeService1"), null, true);
+ ServiceDefinition boundSvcDefn = new ServiceDefinition(URI.create("#boundSvc"), null, true, null);
+ ServiceDefinition boundSvcDefnWithTarget =
+ new ServiceDefinition(URI.create("#boundSvcWithTarget"), null, true);
+ boundSvcDefnWithTarget.setTarget(new URI("orgTarget"));
+ componentType.add(serviceDefn);
+ componentType.add(boundSvcDefn);
+ componentType.add(boundSvcDefnWithTarget);
+
+ ReferenceDefinition compositeReference = new ReferenceDefinition(URI.create("#compositeReference"), null);
+ componentType.add(compositeReference);
+
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> pojoComponentType1 =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ServiceDefinition pojoSvc1 = new ServiceDefinition(URI.create("#pojoSvc1"), null, false);
+ pojoComponentType1.add(pojoSvc1);
+ ReferenceDefinition pojoRef1 = new ReferenceDefinition(URI.create("#pojoRef1"), null);
+ pojoComponentType1.add(pojoRef1);
+ JavaImplementation pojoImpl1 = new JavaImplementation(null, pojoComponentType1);
+
+ URI uri = URI.create("Component1");
+ ComponentDefinition<JavaImplementation> component1 =
+ new ComponentDefinition<JavaImplementation>(uri, pojoImpl1);
+ componentType.add(component1);
+
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> pojoComponentType2 =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ServiceDefinition pojoSvc2 = new ServiceDefinition(URI.create("#pojoSvc2"), null, false);
+ pojoComponentType2.add(pojoSvc2);
+ ServiceDefinition pojoSvc3 = new ServiceDefinition(URI.create("#pojoSvc3"), null, false);
+ pojoComponentType2.add(pojoSvc3);
+ ReferenceDefinition pojoRef2 = new ReferenceDefinition(URI.create("#pojoRef2"), null);
+ pojoComponentType2.add(pojoRef2);
+ ReferenceDefinition pojoRef3 = new ReferenceDefinition(URI.create("#pojoRef3"), null);
+ pojoComponentType2.add(pojoRef3);
+ JavaImplementation pojoImpl2 = new JavaImplementation(null, pojoComponentType2);
+
+ URI uri2 = URI.create("Component2");
+ ComponentDefinition<JavaImplementation> component2 =
+ new ComponentDefinition<JavaImplementation>(uri2, pojoImpl2);
+ componentType.add(component2);
+ }
+
+
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/DuplicateRegistrationTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/DuplicateRegistrationTestCase.java
new file mode 100644
index 0000000000..c3394c1043
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/DuplicateRegistrationTestCase.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.core.implementation.composite;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.DuplicateNameException;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.Component;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * Verfies children with the same name cannot be registered in the same composite
+ *
+ * @version $Rev$ $Date$
+ */
+public class DuplicateRegistrationTestCase extends TestCase {
+
+ public void testDuplicateServiceRegistration() throws Exception {
+ Component parent = new CompositeComponentImpl(URI.create("parent"));
+ parent.start();
+
+ Service service1 = EasyMock.createMock(Service.class);
+ EasyMock.expect(service1.getUri()).andReturn(URI.create("#service")).atLeastOnce();
+ service1.stop();
+ EasyMock.replay(service1);
+
+ Service service2 = EasyMock.createMock(Service.class);
+ EasyMock.expect(service2.getUri()).andReturn(URI.create("#service")).atLeastOnce();
+ service2.stop();
+ EasyMock.replay(service2);
+
+ parent.register(service2);
+ try {
+ parent.register(service1);
+ fail();
+ } catch (DuplicateNameException e) {
+ // ok
+ }
+ parent.stop();
+ }
+
+ public void testDuplicateReferenceRegistration() throws Exception {
+ Component parent = new CompositeComponentImpl(URI.create("parent"));
+ parent.start();
+
+ Reference reference1 = EasyMock.createMock(Reference.class);
+ EasyMock.expect(reference1.getUri()).andReturn(URI.create("#reference")).atLeastOnce();
+ reference1.stop();
+ EasyMock.replay(reference1);
+
+ Reference reference2 = EasyMock.createMock(Reference.class);
+ EasyMock.expect(reference2.getUri()).andReturn(URI.create("#reference")).atLeastOnce();
+ reference2.stop();
+ EasyMock.replay(reference2);
+
+ parent.register(reference2);
+ try {
+ parent.register(reference1);
+ fail();
+ } catch (DuplicateNameException e) {
+ // ok
+ }
+ parent.stop();
+
+ }
+
+ public void testDuplicateServiceReferenceRegistration() throws Exception {
+ Component parent = new CompositeComponentImpl(URI.create("parent"));
+ parent.start();
+
+ Service service1 = EasyMock.createMock(Service.class);
+ EasyMock.expect(service1.getUri()).andReturn(URI.create("#child")).atLeastOnce();
+ service1.stop();
+ EasyMock.replay(service1);
+
+ Reference service2 = EasyMock.createMock(Reference.class);
+ EasyMock.expect(service2.getUri()).andReturn(URI.create("#child")).atLeastOnce();
+ service2.stop();
+ EasyMock.replay(service2);
+
+ parent.register(service2);
+ try {
+ parent.register(service1);
+ fail();
+ } catch (DuplicateNameException e) {
+ // ok
+ }
+ parent.stop();
+
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ImplementationCompositeLoaderTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ImplementationCompositeLoaderTestCase.java
new file mode 100644
index 0000000000..f0207a168a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ImplementationCompositeLoaderTestCase.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.core.implementation.composite;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import javax.xml.namespace.QName;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+
+import org.apache.tuscany.spi.deployer.CompositeClassLoader;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+import org.apache.tuscany.spi.services.artifact.Artifact;
+import org.apache.tuscany.spi.services.artifact.ArtifactRepository;
+
+import junit.framework.TestCase;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reportMatcher;
+import static org.easymock.EasyMock.verify;
+import org.easymock.IArgumentMatcher;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ImplementationCompositeLoaderTestCase extends TestCase {
+ private static final QName IMPLEMENTATION_COMPOSITE = new QName(SCA_NS, "implementation.composite");
+
+ private ClassLoader cl;
+ private ImplementationCompositeLoader loader;
+ private XMLStreamReader reader;
+ private DeploymentContext context;
+ private ArtifactRepository artifactRepository;
+
+ public void testName() throws LoaderException, XMLStreamException, MalformedURLException {
+ String name = "foo";
+ expect(reader.getName()).andReturn(IMPLEMENTATION_COMPOSITE);
+ expect(reader.getAttributeValue(null, "name")).andReturn(name);
+ expect(reader.getAttributeValue(null, "group")).andReturn(null);
+ expect(reader.getAttributeValue(null, "version")).andReturn(null);
+ expect(reader.getAttributeValue(null, "scdlLocation")).andReturn(null);
+ expect(reader.getAttributeValue(null, "jarLocation")).andReturn(null);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ replay(reader);
+
+ replay(context);
+ replay(artifactRepository);
+
+ CompositeImplementation impl = loader.load(null, reader, context);
+ verify(reader);
+ verify(context);
+ verify(artifactRepository);
+ assertEquals(name, impl.getName());
+ assertNull(impl.getScdlLocation());
+ assertNull(impl.getClassLoader());
+ }
+
+ public void testWithArtifact() throws LoaderException, XMLStreamException, MalformedURLException {
+ String name = "foo";
+ expect(reader.getName()).andReturn(IMPLEMENTATION_COMPOSITE);
+ expect(reader.getAttributeValue(null, "name")).andReturn(name);
+ expect(reader.getAttributeValue(null, "group")).andReturn("com.example");
+ expect(reader.getAttributeValue(null, "version")).andReturn("1.0");
+ expect(reader.getAttributeValue(null, "scdlLocation")).andReturn(null);
+ expect(reader.getAttributeValue(null, "jarLocation")).andReturn(null);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ replay(reader);
+
+ expect(context.getClassLoader()).andReturn(cl);
+ replay(context);
+ URL url = new URL("http://www.example.com/sca/base.jar");
+ artifactRepository.resolve(artifactMatcher(url, "com.example", name, "1.0"));
+ replay(artifactRepository);
+
+ CompositeImplementation impl = loader.load(null, reader, context);
+ verify(reader);
+ verify(context);
+ verify(artifactRepository);
+ assertEquals(name, impl.getName());
+ assertEquals(new URL("jar:http://www.example.com/sca/base.jar!/META-INF/sca/default.scdl"),
+ impl.getScdlLocation());
+ assertTrue(impl.getClassLoader() instanceof CompositeClassLoader);
+ }
+
+ public void testWithScdlLocation() throws LoaderException, XMLStreamException, MalformedURLException {
+ String name = "foo";
+ expect(reader.getName()).andReturn(IMPLEMENTATION_COMPOSITE);
+ expect(reader.getAttributeValue(null, "name")).andReturn(name);
+ expect(reader.getAttributeValue(null, "group")).andReturn(null);
+ expect(reader.getAttributeValue(null, "version")).andReturn(null);
+ expect(reader.getAttributeValue(null, "scdlLocation")).andReturn("bar.scdl");
+ expect(reader.getAttributeValue(null, "jarLocation")).andReturn(null);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ replay(reader);
+
+ expect(context.getScdlLocation()).andReturn(new URL("http://www.example.com/sca/base.scdl"));
+ expect(context.getClassLoader()).andReturn(cl);
+ replay(context);
+ replay(artifactRepository);
+
+ CompositeImplementation impl = loader.load(null, reader, context);
+ verify(reader);
+ verify(context);
+ verify(artifactRepository);
+ assertEquals(name, impl.getName());
+ assertEquals(new URL("http://www.example.com/sca/bar.scdl"), impl.getScdlLocation());
+ assertSame(cl, impl.getClassLoader());
+ }
+
+ public void testWithJarLocation() throws LoaderException, XMLStreamException, MalformedURLException {
+ String name = "foo";
+ expect(reader.getName()).andReturn(IMPLEMENTATION_COMPOSITE);
+ expect(reader.getAttributeValue(null, "name")).andReturn(name);
+ expect(reader.getAttributeValue(null, "group")).andReturn(null);
+ expect(reader.getAttributeValue(null, "version")).andReturn(null);
+ expect(reader.getAttributeValue(null, "scdlLocation")).andReturn(null);
+ expect(reader.getAttributeValue(null, "jarLocation")).andReturn("bar.jar");
+ expect(reader.next()).andReturn(END_ELEMENT);
+ replay(reader);
+
+ expect(context.getScdlLocation()).andReturn(new URL("http://www.example.com/sca/base.scdl"));
+ expect(context.getClassLoader()).andReturn(cl);
+ replay(context);
+ replay(artifactRepository);
+
+ CompositeImplementation impl = loader.load(null, reader, context);
+ verify(reader);
+ verify(context);
+ verify(artifactRepository);
+ assertEquals(name, impl.getName());
+ assertEquals(new URL("jar:http://www.example.com/sca/bar.jar!/META-INF/sca/default.scdl"),
+ impl.getScdlLocation());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ artifactRepository = createMock(ArtifactRepository.class);
+ reader = createMock(XMLStreamReader.class);
+ context = createMock(DeploymentContext.class);
+ cl = getClass().getClassLoader();
+ loader = new ImplementationCompositeLoader(null, artifactRepository);
+ }
+
+ protected static Artifact artifactMatcher(final URL url,
+ final String group,
+ final String name,
+ final String version) {
+ reportMatcher(new IArgumentMatcher() {
+
+ public boolean matches(Object object) {
+ if (!(object instanceof Artifact)) {
+ return false;
+ }
+
+ Artifact artifact = (Artifact) object;
+ boolean match = group.equals(artifact.getGroup())
+ && name.equals(artifact.getName())
+ && version.equals(artifact.getVersion())
+ && "jar".equals(artifact.getType());
+ if (match) {
+ artifact.setUrl(url);
+ }
+ return match;
+ }
+
+ public void appendTo(StringBuffer stringBuffer) {
+ stringBuffer.append(group).append(':').append(name).append(':').append(version);
+ }
+ });
+ return null;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ManagedRequestContextTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ManagedRequestContextTestCase.java
new file mode 100644
index 0000000000..12299e762b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ManagedRequestContextTestCase.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.core.implementation.composite;
+
+import org.osoa.sca.RequestContext;
+
+import org.apache.tuscany.spi.component.WorkContext;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ManagedRequestContextTestCase extends TestCase {
+
+ public void testGetServiceName() {
+ WorkContext workContext = EasyMock.createMock(WorkContext.class);
+ EasyMock.expect(workContext.getCurrentServiceName()).andReturn("foo");
+ EasyMock.replay(workContext);
+ RequestContext context = new ManagedRequestContext(workContext);
+ assertEquals("foo", context.getServiceName());
+ EasyMock.verify(workContext);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ReferenceImplTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ReferenceImplTestCase.java
new file mode 100644
index 0000000000..34d37469a7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ReferenceImplTestCase.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.core.implementation.composite;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReferenceImplTestCase extends TestCase {
+
+ public void testStart() {
+ ReferenceBinding binding = EasyMock.createMock(ReferenceBinding.class);
+ binding.start();
+ EasyMock.replay(binding);
+ Reference reference = new ReferenceImpl(URI.create("ref"), null);
+ reference.addReferenceBinding(binding);
+ reference.start();
+ EasyMock.verify(binding);
+
+ }
+
+ public void testStop() {
+ ReferenceBinding binding = EasyMock.createMock(ReferenceBinding.class);
+ binding.stop();
+ EasyMock.replay(binding);
+ Reference reference = new ReferenceImpl(URI.create("ref"), null);
+ reference.addReferenceBinding(binding);
+ reference.stop();
+ EasyMock.verify(binding);
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ServiceImplTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ServiceImplTestCase.java
new file mode 100644
index 0000000000..bb8ed020e0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ServiceImplTestCase.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.core.implementation.composite;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.ServiceBinding;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ServiceImplTestCase extends TestCase {
+
+ public void testStart() {
+ ServiceBinding binding = EasyMock.createMock(ServiceBinding.class);
+ binding.start();
+ EasyMock.replay(binding);
+ Service service = new ServiceImpl(URI.create("foo#bar"), null, null);
+ service.addServiceBinding(binding);
+ service.start();
+ EasyMock.verify(binding);
+
+ }
+
+ public void testStop() {
+ ServiceBinding binding = EasyMock.createMock(ServiceBinding.class);
+ binding.stop();
+ EasyMock.replay(binding);
+ Service service = new ServiceImpl(URI.create("foo#bar"), null, null);
+ service.addServiceBinding(binding);
+ service.stop();
+ EasyMock.verify(binding);
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentMetadataInjectionTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentMetadataInjectionTestCase.java
new file mode 100644
index 0000000000..5186119345
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentMetadataInjectionTestCase.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.core.implementation.java;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests SCA metadata such as <code>@ComponentName</code> and <code>@SCAObject</code> are handled properly
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaAtomicComponentMetadataInjectionTestCase extends TestCase {
+
+ public void testComponentNameSet() throws Exception {
+ // TODO implement
+ }
+
+ public void testCompositeContextSet() throws Exception {
+ // TODO implement
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentNegativeMetadataTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentNegativeMetadataTestCase.java
new file mode 100644
index 0000000000..dfd62c8c53
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentNegativeMetadataTestCase.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.core.implementation.java;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Performs rudimentary negative testing by using malformed metadata on a POJO
+ *
+ * @version $Rev $Date
+ */
+public class JavaAtomicComponentNegativeMetadataTestCase extends TestCase {
+
+ /**
+ * Tests that a pojo with <code>@ComponentName</code> specified on a non-String type generates an error.
+ * <p/>
+ * <strong>NB:</strong> the test assumes an error with a message containing "@ComponentName" is generated
+ */
+ public void testBadNameType() throws Exception {
+ // TODO implement
+ }
+
+ /**
+ * Tests that a pojo with <code>@Context</code> specified on a non-CompositeContext type generates an error.
+ * <p/>
+ * <strong>NB:</strong> the test assumes an error with a message containing "@Context" is generated
+ */
+ public void testContextType() throws Exception {
+ // TODO implement
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaBuilderPropertyTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaBuilderPropertyTestCase.java
new file mode 100644
index 0000000000..9083470aa5
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaBuilderPropertyTestCase.java
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.PropertyValue;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.injection.SingletonObjectFactory;
+import org.easymock.EasyMock;
+
+/**
+ * Verifies that the java component builder handles configured properties correctly
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaBuilderPropertyTestCase extends TestCase {
+ private DeploymentContext deploymentContext;
+ private Component parent;
+ private ScopeRegistry registry;
+
+ @SuppressWarnings("unchecked")
+ public void testPropertyHandling() throws Exception {
+ JavaComponentBuilder builder = new JavaComponentBuilder();
+ builder.setScopeRegistry(registry);
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, JavaMappedProperty<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, JavaMappedProperty<?>>();
+ JavaMappedProperty<String> property = new JavaMappedProperty<String>();
+ property.setName("test");
+ property.setDefaultValueFactory(new SingletonObjectFactory<String>("foo"));
+ property.setMember(JavaBuilderPropertyTestCase.Foo.class.getMethod("setTest", String.class));
+ type.add(property);
+ type.setConstructorDefinition(new ConstructorDefinition<Foo>(Foo.class.getConstructor((Class[]) null)));
+ type.setImplementationScope(Scope.STATELESS);
+ JavaImplementation impl = new JavaImplementation(Foo.class, type);
+ ComponentDefinition<JavaImplementation> definition = new ComponentDefinition<JavaImplementation>(impl);
+ definition.setUri(URI.create("component"));
+ PropertyValue propertyValue = new PropertyValue(property.getName(), property.getDefaultValueFactory());
+ definition.getPropertyValues().put(property.getName(), propertyValue);
+ AtomicComponent component = builder.build(definition, deploymentContext);
+ JavaBuilderPropertyTestCase.Foo foo = (JavaBuilderPropertyTestCase.Foo) component.createInstance();
+ assertEquals("foo", foo.getTest());
+ }
+
+ public void testIntPropertyHandling() throws Exception {
+ JavaComponentBuilder builder = new JavaComponentBuilder();
+ builder.setScopeRegistry(registry);
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, JavaMappedProperty<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, JavaMappedProperty<?>>();
+ JavaMappedProperty<Integer> property = new JavaMappedProperty<Integer>();
+ property.setName("test");
+ property.setDefaultValueFactory(new SingletonObjectFactory<Integer>(1));
+ property.setMember(JavaBuilderPropertyTestCase.FooInt.class.getMethod("setTest", Integer.TYPE));
+ type.add(property);
+ type.setConstructorDefinition(new ConstructorDefinition<FooInt>(FooInt.class.getConstructor((Class[]) null)));
+ type.setImplementationScope(Scope.STATELESS);
+ JavaImplementation impl = new JavaImplementation(Foo.class, type);
+ ComponentDefinition<JavaImplementation> definition = new ComponentDefinition<JavaImplementation>(impl);
+ definition.setUri(URI.create("component"));
+ ObjectFactory<Integer> defaultValueFactory = property.getDefaultValueFactory();
+ PropertyValue<Integer> propertyValue = new PropertyValue<Integer>(property.getName(), defaultValueFactory);
+ definition.getPropertyValues().put(property.getName(), propertyValue);
+ AtomicComponent component = builder.build(definition, deploymentContext);
+ FooInt foo = (FooInt) component.createInstance();
+ assertEquals(1, foo.getTest());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ deploymentContext = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(deploymentContext.getGroupId()).andStubReturn(URI.create("composite"));
+ EasyMock.replay(deploymentContext);
+ parent = EasyMock.createNiceMock(Component.class);
+ ScopeContainer mockContainer = EasyMock.createNiceMock(ScopeContainer.class);
+ EasyMock.replay(mockContainer);
+ registry = EasyMock.createMock(ScopeRegistry.class);
+ EasyMock.expect(registry.getScopeContainer(EasyMock.isA(Scope.class))).andReturn(mockContainer);
+ EasyMock.replay(registry);
+ }
+
+ private static class Foo {
+ private String test;
+
+ public Foo() {
+ }
+
+ public String getTest() {
+ return test;
+ }
+
+ public void setTest(String test) {
+ this.test = test;
+ }
+ }
+
+ private static class FooInt {
+ private int test;
+
+ public FooInt() {
+ }
+
+ public int getTest() {
+ return test;
+ }
+
+ public void setTest(int test) {
+ this.test = test;
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderConversationIDTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderConversationIDTestCase.java
new file mode 100644
index 0000000000..644fb35e3e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderConversationIDTestCase.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.core.implementation.java;
+
+import java.lang.reflect.Field;
+import java.net.URI;
+
+import org.osoa.sca.annotations.ConversationID;
+
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev: 473859 $ $Date: 2006-11-11 22:31:55 -0500 (Sat, 11 Nov 2006) $
+ */
+public class JavaComponentBuilderConversationIDTestCase extends TestCase {
+
+ @SuppressWarnings("unchecked")
+ public void testResourceInjection() throws Exception {
+ DeploymentContext ctx = EasyMock.createNiceMock(DeploymentContext.class);
+ EasyMock.expect(ctx.getGroupId()).andStubReturn(URI.create("composite"));
+ EasyMock.replay(ctx);
+ ScopeContainer container = EasyMock.createNiceMock(ScopeContainer.class);
+ ScopeRegistry registry = EasyMock.createMock(ScopeRegistry.class);
+ EasyMock.expect(registry.getScopeContainer(Scope.STATELESS)).andReturn(container);
+ EasyMock.replay(registry);
+ JavaComponentBuilder builder = new JavaComponentBuilder();
+ builder.setScopeRegistry(registry);
+ WorkContext workContext = new WorkContextImpl();
+ workContext.setIdentifier(Scope.CONVERSATION, "convID");
+ builder.setWorkContext(workContext);
+
+ ConstructorDefinition<Foo> ctorDef = new ConstructorDefinition<Foo>(Foo.class.getConstructor());
+ PojoComponentType type = new PojoComponentType();
+ Field field = Foo.class.getDeclaredField("conversationID");
+ type.setConversationIDMember(field);
+ type.setImplementationScope(Scope.STATELESS);
+ type.setConstructorDefinition(ctorDef);
+
+ JavaImplementation impl = new JavaImplementation(Foo.class, type);
+ URI uri = URI.create("foo");
+ ComponentDefinition<JavaImplementation> definition = new ComponentDefinition<JavaImplementation>(uri, impl);
+ JavaAtomicComponent component = (JavaAtomicComponent) builder.build(definition, ctx);
+ Foo foo = (Foo) component.createInstance();
+ assertEquals("convID", foo.conversationID);
+ }
+
+ private static class Foo {
+
+ @ConversationID
+ protected String conversationID;
+
+ public Foo() {
+ }
+
+ }
+}
+
+
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderMetadataTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderMetadataTestCase.java
new file mode 100644
index 0000000000..ca4aab9d3a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderMetadataTestCase.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.core.implementation.java;
+
+import java.lang.reflect.Constructor;
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.composite.CompositeComponentImpl;
+import org.apache.tuscany.core.mock.component.Source;
+import org.apache.tuscany.core.mock.component.SourceImpl;
+import org.apache.tuscany.core.mock.component.Target;
+import org.easymock.EasyMock;
+
+/**
+ * Verifies component type metadata is properly applied to the component
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class JavaComponentBuilderMetadataTestCase extends TestCase {
+ private DeploymentContext deploymentContext;
+ private Constructor<SourceImpl> constructor;
+ private Component parent;
+ private PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type;
+ private ComponentDefinition<JavaImplementation> definition;
+ private ScopeContainer scopeContainer;
+
+ public void testInitLevel() throws Exception {
+ type.setInitLevel(1);
+ JavaComponentBuilder builder = new JavaComponentBuilder();
+ JavaAtomicComponent component = (JavaAtomicComponent) builder.build(definition, deploymentContext);
+ assertEquals(1, component.getInitLevel());
+ }
+
+ public void testMaxAge() throws Exception {
+ type.setMaxAge(100);
+ JavaComponentBuilder builder = new JavaComponentBuilder();
+ JavaAtomicComponent component = (JavaAtomicComponent) builder.build(definition, deploymentContext);
+ assertEquals(100, component.getMaxAge());
+ }
+
+ public void testMaxIdleTime() throws Exception {
+ type.setMaxIdleTime(100);
+ JavaComponentBuilder builder = new JavaComponentBuilder();
+ JavaAtomicComponent component = (JavaAtomicComponent) builder.build(definition, deploymentContext);
+ assertEquals(100, component.getMaxIdleTime());
+ }
+
+ public void testNoMaxAgeNoMaxIdleTime() throws Exception {
+ JavaComponentBuilder builder = new JavaComponentBuilder();
+ JavaAtomicComponent component = (JavaAtomicComponent) builder.build(definition, deploymentContext);
+ assertEquals(-1, component.getMaxAge());
+ assertEquals(-1, component.getMaxIdleTime());
+ }
+
+ public void testScope() throws Exception {
+ JavaComponentBuilder builder = new JavaComponentBuilder();
+ JavaAtomicComponent component = (JavaAtomicComponent) builder.build(definition, deploymentContext);
+ component.setScopeContainer(scopeContainer);
+ assertEquals(Scope.COMPOSITE, component.getScope());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ parent = new CompositeComponentImpl(URI.create("parent"));
+ constructor = SourceImpl.class.getConstructor((Class[]) null);
+ createDeploymentContext();
+ createComponentDefinitionAndType();
+ }
+
+
+ private void createDeploymentContext() {
+ scopeContainer = EasyMock.createMock(ScopeContainer.class);
+ scopeContainer.start();
+ scopeContainer.stop();
+ scopeContainer.register(EasyMock.isA(AtomicComponent.class), EasyMock.isA(URI.class));
+ EasyMock.expectLastCall().atLeastOnce();
+ EasyMock.expect(scopeContainer.getScope()).andReturn(Scope.COMPOSITE).atLeastOnce();
+ EasyMock.replay(scopeContainer);
+ deploymentContext = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(deploymentContext.getGroupId()).andStubReturn(URI.create("composite"));
+ EasyMock.replay(deploymentContext);
+ }
+
+ private void createComponentDefinitionAndType() throws Exception {
+ type = new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ type.setImplementationScope(Scope.COMPOSITE);
+ JavaMappedReference reference = new JavaMappedReference();
+ reference.setUri(URI.create("#target"));
+ reference.setMember(SourceImpl.class.getMethod("setTarget", Target.class));
+ type.add(reference);
+ ServiceContract<?> contract = new JavaServiceContract(Source.class);
+ JavaMappedService serviceDefinition = new JavaMappedService();
+ serviceDefinition.setUri(URI.create("component#Source"));
+ serviceDefinition.setServiceContract(contract);
+ type.add(serviceDefinition);
+ type.setConstructorDefinition(new ConstructorDefinition<SourceImpl>(constructor));
+ JavaImplementation sourceImpl = new JavaImplementation(SourceImpl.class, type);
+ definition = new ComponentDefinition<JavaImplementation>(sourceImpl);
+ definition.setUri(URI.create("component"));
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderResourceTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderResourceTestCase.java
new file mode 100644
index 0000000000..684e0420dd
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderResourceTestCase.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.core.implementation.java;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.host.ResourceHost;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.Resource;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaComponentBuilderResourceTestCase extends TestCase {
+
+ @SuppressWarnings("unchecked")
+ public void testResourceInjection() throws Exception {
+ DeploymentContext ctx = EasyMock.createNiceMock(DeploymentContext.class);
+ EasyMock.expect(ctx.getGroupId()).andStubReturn(URI.create("composite"));
+ EasyMock.replay(ctx);
+ ScopeContainer container = EasyMock.createNiceMock(ScopeContainer.class);
+ ScopeRegistry registry = EasyMock.createMock(ScopeRegistry.class);
+ EasyMock.expect(registry.getScopeContainer(Scope.STATELESS)).andReturn(container);
+ EasyMock.replay(registry);
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(EasyMock.eq(String.class))).andReturn("result");
+ EasyMock.replay(host);
+ JavaComponentBuilder builder = new JavaComponentBuilder();
+ builder.setHost(host);
+ builder.setScopeRegistry(registry);
+ ConstructorDefinition<Foo> ctorDef = new ConstructorDefinition<Foo>(Foo.class.getConstructor());
+ PojoComponentType type = new PojoComponentType();
+ Resource resource = new Resource("resource", String.class, Foo.class.getDeclaredField("resource"));
+ type.add(resource);
+ type.setImplementationScope(Scope.STATELESS);
+ type.setConstructorDefinition(ctorDef);
+ JavaImplementation impl = new JavaImplementation(Foo.class, type);
+ URI uri = URI.create("foo");
+ ComponentDefinition<JavaImplementation> definition = new ComponentDefinition<JavaImplementation>(uri, impl);
+ Wire resourceWire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(resourceWire.getTargetInstance()).andReturn("result");
+ EasyMock.replay(resourceWire);
+
+ JavaAtomicComponent component = (JavaAtomicComponent) builder.build(definition, ctx);
+ Foo foo = (Foo) component.createInstance();
+ assertEquals("result", foo.resource);
+ }
+
+ private static class Foo {
+
+ protected String resource;
+
+ public Foo() {
+ }
+
+ }
+}
+
+
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentTypeLoaderTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentTypeLoaderTestCase.java
new file mode 100644
index 0000000000..92e8946d6f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentTypeLoaderTestCase.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.core.implementation.java;
+
+import java.net.URL;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.IntrospectionRegistry;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaComponentTypeLoaderTestCase extends TestCase {
+
+ @SuppressWarnings("unchecked")
+ public void testPojoComponentTypeCreatedForIntrospection() throws Exception {
+ IntrospectionRegistry registry = EasyMock.createMock(IntrospectionRegistry.class);
+ registry.introspect(
+ (Class) EasyMock.isNull(),
+ EasyMock.isA(PojoComponentType.class),
+ (DeploymentContext) EasyMock.isNull());
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return EasyMock.getCurrentArguments()[2];
+ }
+ });
+ EasyMock.replay(registry);
+ JavaComponentTypeLoader loader = new JavaComponentTypeLoader(null, registry);
+ loader.loadByIntrospection(new JavaImplementation(), null);
+ EasyMock.verify(registry);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testPojoComponentTypeCreatedForSideFileLoadAndReturned() throws Exception {
+ LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class);
+ registry.load(
+ EasyMock.isA(PojoComponentType.class),
+ (URL) EasyMock.isNull(),
+ EasyMock.eq(PojoComponentType.class),
+ (DeploymentContext) EasyMock.isNull());
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ return EasyMock.getCurrentArguments()[0];
+ }
+ });
+ EasyMock.replay(registry);
+ JavaComponentTypeLoader loader = new JavaComponentTypeLoader(registry, null);
+ assertEquals(PojoComponentType.class, loader.loadFromSidefile(null, null).getClass());
+ EasyMock.verify(registry);
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaInvokerInterceptorBasicTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaInvokerInterceptorBasicTestCase.java
new file mode 100644
index 0000000000..e84e8e4d7c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaInvokerInterceptorBasicTestCase.java
@@ -0,0 +1,247 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+import org.easymock.IMocksControl;
+import org.easymock.classextension.EasyMock;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.wire.Message;
+
+public class JavaInvokerInterceptorBasicTestCase<CONTEXT> extends TestCase {
+ private TestBean bean;
+ private CONTEXT contextId;
+ private Method echoMethod;
+ private Method arrayMethod;
+ private Method nullParamMethod;
+ private Method primitiveMethod;
+ private Method checkedMethod;
+ private Method runtimeMethod;
+
+ private IMocksControl control;
+ private WorkContext workContext;
+ private ScopeContainer<CONTEXT> scopeContainer;
+ private InstanceWrapper<TestBean> wrapper;
+ private AtomicComponent<TestBean> component;
+ private Message message;
+
+ public void testObjectInvoke() throws Throwable {
+ JavaInvokerInterceptor<TestBean, CONTEXT> invoker =
+ new JavaInvokerInterceptor<TestBean, CONTEXT>(echoMethod, component, scopeContainer);
+ String value = "foo";
+ mockCall(new Object[]{value});
+ message.setBody(value);
+ control.replay();
+ Message ret = invoker.invoke(message);
+ assertSame(ret, message);
+ control.verify();
+ }
+
+ public void testPrimitiveInvoke() throws Throwable {
+ JavaInvokerInterceptor<TestBean, CONTEXT> invoker =
+ new JavaInvokerInterceptor<TestBean, CONTEXT>(primitiveMethod, component, scopeContainer);
+ Integer value = 1;
+ mockCall(new Object[]{value});
+ message.setBody(value);
+ control.replay();
+ Message ret = invoker.invoke(message);
+ assertSame(ret, message);
+ control.verify();
+ }
+
+ public void testArrayInvoke() throws Throwable {
+ JavaInvokerInterceptor<TestBean, CONTEXT> invoker =
+ new JavaInvokerInterceptor<TestBean, CONTEXT>(arrayMethod, component, scopeContainer);
+ String[] value = new String[]{"foo", "bar"};
+ mockCall(new Object[]{value});
+ message.setBody(value);
+ control.replay();
+ Message ret = invoker.invoke(message);
+ assertSame(ret, message);
+ control.verify();
+ }
+
+ public void testEmptyInvoke() throws Throwable {
+ JavaInvokerInterceptor<TestBean, CONTEXT> invoker =
+ new JavaInvokerInterceptor<TestBean, CONTEXT>(nullParamMethod, component, scopeContainer);
+ mockCall(new Object[]{});
+ message.setBody("foo");
+ control.replay();
+ Message ret = invoker.invoke(message);
+ assertSame(ret, message);
+ control.verify();
+ }
+
+ public void testNullInvoke() throws Throwable {
+ JavaInvokerInterceptor<TestBean, CONTEXT> invoker =
+ new JavaInvokerInterceptor<TestBean, CONTEXT>(nullParamMethod, component, scopeContainer);
+ mockCall(null);
+ message.setBody("foo");
+ control.replay();
+ Message ret = invoker.invoke(message);
+ assertSame(ret, message);
+ control.verify();
+ }
+
+ public void testInvokeCheckedException() throws Throwable {
+ JavaInvokerInterceptor<TestBean, CONTEXT> invoker =
+ new JavaInvokerInterceptor<TestBean, CONTEXT>(checkedMethod, component, scopeContainer);
+ mockCall(null);
+ message.setBodyWithFault(EasyMock.isA(TestException.class));
+ control.replay();
+ Message ret = invoker.invoke(message);
+ assertSame(ret, message);
+ control.verify();
+ }
+
+ public void testInvokeRuntimeException() throws Throwable {
+ JavaInvokerInterceptor<TestBean, CONTEXT> invoker =
+ new JavaInvokerInterceptor<TestBean, CONTEXT>(runtimeMethod, component, scopeContainer);
+ mockCall(null);
+ message.setBodyWithFault(EasyMock.isA(TestRuntimeException.class));
+ control.replay();
+ Message ret = invoker.invoke(message);
+ assertSame(ret, message);
+ control.verify();
+ }
+
+ public void testSequenceStart() throws Throwable {
+ JavaInvokerInterceptor<TestBean, CONTEXT> invoker =
+ new JavaInvokerInterceptor<TestBean, CONTEXT>(nullParamMethod, component, scopeContainer);
+ mockCall(null, JavaInvokerInterceptor.START);
+ message.setBody("foo");
+ control.replay();
+ Message ret = invoker.invoke(message);
+ assertSame(ret, message);
+ control.verify();
+ }
+
+ public void testSequenceContinue() throws Throwable {
+ JavaInvokerInterceptor<TestBean, CONTEXT> invoker =
+ new JavaInvokerInterceptor<TestBean, CONTEXT>(nullParamMethod, component, scopeContainer);
+ mockCall(null, JavaInvokerInterceptor.CONTINUE);
+ message.setBody("foo");
+ control.replay();
+ Message ret = invoker.invoke(message);
+ assertSame(ret, message);
+ control.verify();
+ }
+
+ public void testSequenceEnd() throws Throwable {
+ JavaInvokerInterceptor<TestBean, CONTEXT> invoker =
+ new JavaInvokerInterceptor<TestBean, CONTEXT>(nullParamMethod, component, scopeContainer);
+ mockCall(null, JavaInvokerInterceptor.END);
+ message.setBody("foo");
+ control.replay();
+ Message ret = invoker.invoke(message);
+ assertSame(ret, message);
+ control.verify();
+ }
+
+ private void mockCall(Object value) throws Exception {
+ mockCall(value, JavaInvokerInterceptor.NONE);
+ }
+
+ private void mockCall(Object value, short sequence) throws Exception {
+ EasyMock.expect(message.getBody()).andReturn(value);
+ EasyMock.expect(message.getConversationSequence()).andReturn(sequence);
+ EasyMock.expect(message.getWorkContext()).andReturn(workContext);
+ EasyMock.expect(scopeContainer.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.expect(workContext.getIdentifier(Scope.COMPOSITE)).andReturn(contextId);
+ if (sequence == JavaInvokerInterceptor.START || sequence == JavaInvokerInterceptor.NONE) {
+ EasyMock.expect(scopeContainer.getWrapper(component, contextId)).andReturn(wrapper);
+ } else if (sequence == JavaInvokerInterceptor.CONTINUE || sequence == JavaInvokerInterceptor.END) {
+ EasyMock.expect(scopeContainer.getAssociatedWrapper(component, contextId)).andReturn(wrapper);
+ } else {
+ fail();
+ }
+ EasyMock.expect(wrapper.getInstance()).andReturn(bean);
+ scopeContainer.returnWrapper(component, wrapper, contextId);
+ if (sequence == JavaInvokerInterceptor.END) {
+ scopeContainer.remove(component);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void setUp() throws Exception {
+ bean = new TestBean();
+ contextId = (CONTEXT) new Object();
+ echoMethod = TestBean.class.getDeclaredMethod("echo", String.class);
+ arrayMethod = TestBean.class.getDeclaredMethod("arrayEcho", String[].class);
+ nullParamMethod = TestBean.class.getDeclaredMethod("nullParam");
+ primitiveMethod = TestBean.class.getDeclaredMethod("primitiveEcho", Integer.TYPE);
+ checkedMethod = TestBean.class.getDeclaredMethod("checkedException");
+ runtimeMethod = TestBean.class.getDeclaredMethod("runtimeException");
+ assertNotNull(echoMethod);
+ assertNotNull(checkedMethod);
+ assertNotNull(runtimeMethod);
+
+ control = EasyMock.createStrictControl();
+ workContext = control.createMock(WorkContext.class);
+ component = control.createMock(AtomicComponent.class);
+ scopeContainer = control.createMock(ScopeContainer.class);
+ wrapper = control.createMock(InstanceWrapper.class);
+ message = control.createMock(Message.class);
+ }
+
+ private class TestBean {
+
+ public String echo(String msg) throws Exception {
+ assertEquals("foo", msg);
+ return msg;
+ }
+
+ public String[] arrayEcho(String[] msg) throws Exception {
+ assertNotNull(msg);
+ assertEquals(2, msg.length);
+ assertEquals("foo", msg[0]);
+ assertEquals("bar", msg[1]);
+ return msg;
+ }
+
+ public String nullParam() throws Exception {
+ return "foo";
+ }
+
+ public int primitiveEcho(int i) throws Exception {
+ return i;
+ }
+
+ public void checkedException() throws TestException {
+ throw new TestException();
+ }
+
+ public void runtimeException() throws TestRuntimeException {
+ throw new TestRuntimeException();
+ }
+ }
+
+ public static class TestException extends Exception {
+ }
+
+ public static class TestRuntimeException extends RuntimeException {
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaReferenceWireTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaReferenceWireTestCase.java
new file mode 100644
index 0000000000..4f2cea1741
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaReferenceWireTestCase.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.core.implementation.java;
+
+import java.lang.reflect.Constructor;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetException;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.ProxyService;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+
+/**
+ * Validates wiring from a Java atomic context
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class JavaReferenceWireTestCase extends TestCase {
+
+ @SuppressWarnings({"unchecked"})
+ public void testReferenceSet() throws Exception {
+ ScopeContainer scope = createMock();
+ scope.start();
+ final Target target = new TargetImpl();
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.addReferenceSite("target", SourceImpl.class.getMethod("setTarget", Target.class));
+ Constructor<SourceImpl> ctr = SourceImpl.class.getConstructor();
+ configuration.setInstanceFactory(new PojoObjectFactory<SourceImpl>(ctr));
+ Wire wire = EasyMock.createMock(Wire.class);
+ wire.getInvocationChains();
+ EasyMock.expectLastCall().andReturn(new HashMap<Operation<?>, InvocationChain>()).atLeastOnce();
+ URI uri = URI.create("#target");
+ EasyMock.expect(wire.getSourceUri()).andReturn(uri).atLeastOnce();
+ EasyMock.expect(wire.isOptimizable()).andReturn(false);
+ EasyMock.replay(wire);
+ ProxyService service = EasyMock.createMock(ProxyService.class);
+ EasyMock.expect(service.createProxy(EasyMock.eq(Target.class), EasyMock.eq(wire), EasyMock.isA(Map.class)))
+ .andAnswer(new IAnswer<Target>() {
+ public Target answer() throws Throwable {
+ Wire wire = (Wire) EasyMock.getCurrentArguments()[1];
+ wire.getInvocationChains();
+ return target;
+ }
+
+ }).atLeastOnce();
+ EasyMock.replay(service);
+ configuration.setProxyService(service);
+ configuration.setName(new URI("source"));
+ configuration.setGroupId(URI.create("composite"));
+ JavaAtomicComponent component = new JavaAtomicComponent(configuration);
+ component.setScopeContainer(scope);
+ component.attachWire(wire);
+ component.start();
+ Source source = (Source) component.getTargetInstance();
+ assertSame(target, source.getTarget());
+ scope.stop();
+ EasyMock.verify(wire);
+ EasyMock.verify(scope);
+ EasyMock.verify(service);
+ }
+
+ private ScopeContainer createMock() throws TargetException {
+ ScopeContainer scope = EasyMock.createMock(ScopeContainer.class);
+ scope.start();
+ scope.stop();
+ scope.register(EasyMock.isA(AtomicComponent.class), EasyMock.eq(URI.create("composite")));
+ EasyMock.expectLastCall().atLeastOnce();
+ EasyMock.expect(scope.getScope()).andReturn(Scope.COMPOSITE).atLeastOnce();
+ scope.getWrapper(EasyMock.isA(AtomicComponent.class), EasyMock.eq(URI.create("composite")));
+ EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+ private Map<AtomicComponent, InstanceWrapper> cache = new HashMap<AtomicComponent, InstanceWrapper>();
+
+ public Object answer() throws Throwable {
+ AtomicComponent component = (AtomicComponent) EasyMock.getCurrentArguments()[0];
+ InstanceWrapper instance = cache.get(component);
+ if (instance == null) {
+ instance = component.createInstanceWrapper();
+ cache.put(component, instance);
+ }
+ return instance;
+ }
+ }).anyTimes();
+ EasyMock.replay(scope);
+ return scope;
+ }
+
+ private interface Source {
+ Target getTarget();
+ }
+
+ private static class SourceImpl implements Source {
+ private Target target;
+
+ public SourceImpl() {
+ }
+
+ public Target getTarget() {
+ return target;
+ }
+
+ public void setTarget(Target target) {
+ this.target = target;
+ }
+ }
+
+ private interface Target {
+
+ String getString();
+
+ void setString(String val);
+ }
+
+ private static class TargetImpl implements Target {
+ private String string;
+
+ public TargetImpl() {
+ }
+
+ public String getString() {
+ return string;
+ }
+
+ public void setString(String string) {
+ this.string = string;
+ }
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerBasicInvocationTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerBasicInvocationTestCase.java
new file mode 100644
index 0000000000..114d8f6970
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerBasicInvocationTestCase.java
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
+import static org.apache.tuscany.spi.wire.TargetInvoker.NONE;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.classextension.EasyMock;
+
+public class JavaTargetInvokerBasicInvocationTestCase extends TestCase {
+ private Method echoMethod;
+ private Method arrayMethod;
+ private Method nullParamMethod;
+ private Method primitiveMethod;
+ private Method checkedMethod;
+ private Method runtimeMethod;
+ private Wire wire;
+ private WorkContext context;
+ private ScopeContainer scopeContainer;
+ private InstanceWrapper wrapper;
+ private TestBean bean;
+ private JavaAtomicComponent component;
+
+ public JavaTargetInvokerBasicInvocationTestCase(String arg0) {
+ super(arg0);
+ }
+
+ public void setUp() throws Exception {
+ echoMethod = TestBean.class.getDeclaredMethod("echo", String.class);
+ arrayMethod = TestBean.class.getDeclaredMethod("arrayEcho", String[].class);
+ nullParamMethod = TestBean.class.getDeclaredMethod("nullParam", (Class[]) null);
+ primitiveMethod = TestBean.class.getDeclaredMethod("primitiveEcho", Integer.TYPE);
+ checkedMethod = TestBean.class.getDeclaredMethod("checkedException", (Class[]) null);
+ runtimeMethod = TestBean.class.getDeclaredMethod("runtimeException", (Class[]) null);
+ assertNotNull(echoMethod);
+ assertNotNull(checkedMethod);
+ assertNotNull(runtimeMethod);
+
+ wire = EasyMock.createNiceMock(Wire.class);
+ context = EasyMock.createNiceMock(WorkContext.class);
+ component = EasyMock.createMock(JavaAtomicComponent.class);
+ scopeContainer = EasyMock.createNiceMock(ScopeContainer.class);
+ wrapper = EasyMock.createNiceMock(InstanceWrapper.class);
+ bean = new TestBean();
+ EasyMock.replay(component);
+ EasyMock.expect(scopeContainer.getScope()).andReturn(Scope.COMPOSITE);
+ EasyMock.expect(scopeContainer.getWrapper(component, null)).andReturn(wrapper);
+ EasyMock.replay(scopeContainer);
+ EasyMock.expect(wrapper.getInstance()).andReturn(bean);
+ EasyMock.replay(wrapper);
+ }
+
+
+ protected void tearDown() throws Exception {
+ EasyMock.verify(component);
+ EasyMock.verify(scopeContainer);
+ EasyMock.verify(wrapper);
+ super.tearDown();
+ }
+
+ public void testObjectInvoke() throws Throwable {
+ JavaTargetInvoker invoker = new JavaTargetInvoker(echoMethod, component, scopeContainer);
+ Object ret = invoker.invokeTarget("foo", NONE, context);
+ assertEquals("foo", ret);
+ }
+
+ public void testArrayInvoke() throws Throwable {
+ JavaTargetInvoker invoker = new JavaTargetInvoker(arrayMethod, component, scopeContainer);
+ String[] args = new String[]{"foo", "bar"};
+ Object ret = invoker.invokeTarget(new Object[]{args}, NONE, context);
+ String[] retA = (String[]) ret;
+ assertNotNull(retA);
+ assertEquals(2, retA.length);
+ assertEquals("foo", retA[0]);
+ assertEquals("bar", retA[1]);
+ }
+
+ public void testNullInvoke() throws Throwable {
+ JavaTargetInvoker invoker = new JavaTargetInvoker(nullParamMethod, component, scopeContainer);
+ Object ret = invoker.invokeTarget(null, NONE, context);
+ String retS = (String) ret;
+ assertEquals("foo", retS);
+ }
+
+ public void testPrimitiveInvoke() throws Throwable {
+ JavaTargetInvoker invoker = new JavaTargetInvoker(primitiveMethod, component, scopeContainer);
+ Object ret = invoker.invokeTarget(new Integer[]{1}, NONE, context);
+ Integer retI = (Integer) ret;
+ assertEquals(1, retI.intValue());
+ }
+
+ public void testInvokeCheckedException() throws Throwable {
+ JavaTargetInvoker invoker = new JavaTargetInvoker(checkedMethod, component, scopeContainer);
+ try {
+ invoker.invokeTarget(null, NONE, context);
+ fail(TestException.class.getName() + " should have been thrown");
+ } catch (InvocationTargetException e) {
+ assertTrue(e.getCause() instanceof TestException);
+ }
+ }
+
+ public void testInvokeRuntimeException() throws Throwable {
+ JavaTargetInvoker invoker = new JavaTargetInvoker(runtimeMethod, component, scopeContainer);
+ try {
+ invoker.invokeTarget(null, NONE, context);
+ fail(TestException.class.getName() + " should have been thrown");
+ } catch (InvocationTargetException e) {
+ assertTrue(e.getCause() instanceof TestRuntimeException);
+ }
+ }
+
+ private class TestBean {
+
+ public String echo(String msg) throws Exception {
+ assertEquals("foo", msg);
+ return msg;
+ }
+
+ public String[] arrayEcho(String[] msg) throws Exception {
+ assertNotNull(msg);
+ assertEquals(2, msg.length);
+ assertEquals("foo", msg[0]);
+ assertEquals("bar", msg[1]);
+ return msg;
+ }
+
+ public String nullParam() throws Exception {
+ return "foo";
+ }
+
+ public int primitiveEcho(int i) throws Exception {
+ return i;
+ }
+
+ public void checkedException() throws TestException {
+ throw new TestException();
+ }
+
+ public void runtimeException() throws TestRuntimeException {
+ throw new TestRuntimeException();
+ }
+ }
+
+ public class TestException extends Exception {
+ }
+
+ public class TestRuntimeException extends RuntimeException {
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerSequenceTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerSequenceTestCase.java
new file mode 100644
index 0000000000..4e288cf9db
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerSequenceTestCase.java
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java;
+
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.WorkContext;
+
+import junit.framework.TestCase;
+import org.easymock.classextension.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaTargetInvokerSequenceTestCase extends TestCase {
+ private Method method;
+ private Foo foo;
+ private JavaAtomicComponent component;
+ private ScopeContainer scopeContainer;
+ private InstanceWrapper wrapper;
+ private WorkContext workContext;
+ private Object contextId;
+ private JavaTargetInvoker invoker;
+ private Message msg;
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ method = Foo.class.getMethod("invoke");
+ foo = EasyMock.createMock(Foo.class);
+ foo.invoke();
+ EasyMock.replay(foo);
+
+ contextId = new Object();
+ workContext = EasyMock.createMock(WorkContext.class);
+ EasyMock.expect(workContext.getIdentifier(Scope.CONVERSATION)).andStubReturn(contextId);
+ EasyMock.replay(workContext);
+
+ msg = new MessageImpl();
+ msg.setWorkContext(workContext);
+
+ component = EasyMock.createMock(JavaAtomicComponent.class);
+ scopeContainer = EasyMock.createMock(ScopeContainer.class);
+ wrapper = EasyMock.createMock(InstanceWrapper.class);
+ EasyMock.expect(wrapper.getInstance()).andReturn(foo);
+ EasyMock.replay(wrapper);
+
+ EasyMock.expect(scopeContainer.getScope()).andStubReturn(Scope.CONVERSATION);
+ EasyMock.replay(scopeContainer);
+ invoker = new JavaTargetInvoker(method, component, scopeContainer);
+ EasyMock.reset(scopeContainer);
+ EasyMock.expect(scopeContainer.getScope()).andStubReturn(Scope.CONVERSATION);
+ }
+
+ /**
+ * Verifies an invocation marked as non-conversational has an existing or new instance returned
+ */
+ public void testNoSequence() throws Exception {
+ EasyMock.expect(scopeContainer.getWrapper(component, contextId)).andReturn(wrapper);
+ scopeContainer.returnWrapper(component, wrapper, contextId);
+ EasyMock.replay(component);
+ EasyMock.replay(scopeContainer);
+ msg.setConversationSequence(TargetInvoker.NONE);
+ invoker.invoke(msg);
+ EasyMock.verify(foo);
+ EasyMock.verify(component);
+ EasyMock.verify(scopeContainer);
+ EasyMock.verify(wrapper);
+ }
+
+ /**
+ * Verifies that an invocation marked as starting a conversation has a new instance returned
+ */
+ public void testStartSequence() throws Exception {
+ EasyMock.replay(component);
+ EasyMock.expect(scopeContainer.getWrapper(component, contextId)).andReturn(wrapper);
+ scopeContainer.returnWrapper(component, wrapper, contextId);
+ EasyMock.replay(scopeContainer);
+ msg.setConversationSequence(TargetInvoker.START);
+ invoker.invoke(msg);
+ EasyMock.verify(foo);
+ EasyMock.verify(component);
+ EasyMock.verify(scopeContainer);
+ EasyMock.verify(wrapper);
+ }
+
+ /**
+ * Verifies that an invocation marked as continuing a conversation has an associated instance returned
+ */
+ public void testContinueSequence() throws Exception {
+ EasyMock.replay(component);
+ EasyMock.expect(scopeContainer.getAssociatedWrapper(component, contextId)).andReturn(wrapper);
+ scopeContainer.returnWrapper(component, wrapper, contextId);
+ EasyMock.replay(scopeContainer);
+ msg.setConversationSequence(TargetInvoker.CONTINUE);
+ invoker.invoke(msg);
+ EasyMock.verify(foo);
+ EasyMock.verify(component);
+ EasyMock.verify(scopeContainer);
+ EasyMock.verify(wrapper);
+ }
+
+ /**
+ * Verifies that an invocation marked as ending a conversation has an associated instance returned and it is removed
+ * following the dispatch to the instance
+ */
+ public void testEndSequence() throws Exception {
+ EasyMock.replay(component);
+ EasyMock.expect(scopeContainer.getAssociatedWrapper(component, contextId)).andReturn(wrapper);
+ scopeContainer.returnWrapper(component, wrapper, contextId);
+ scopeContainer.remove(component);
+ EasyMock.replay(scopeContainer);
+ msg.setConversationSequence(TargetInvoker.END);
+ invoker.invoke(msg);
+ EasyMock.verify(foo);
+ EasyMock.verify(component);
+ EasyMock.verify(scopeContainer);
+ EasyMock.verify(wrapper);
+ }
+
+
+ private interface Foo {
+ void invoke();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerStatelessDestroyTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerStatelessDestroyTestCase.java
new file mode 100644
index 0000000000..b0def53117
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerStatelessDestroyTestCase.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.core.implementation.java;
+
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.WorkContext;
+
+import junit.framework.TestCase;
+import org.easymock.classextension.EasyMock;
+
+public class JavaTargetInvokerStatelessDestroyTestCase extends TestCase {
+ private JavaAtomicComponent component;
+ private ScopeContainer scopeContainer;
+ private InstanceWrapper wrapper;
+ private Method echoMethod;
+ private WorkContext workContext;
+
+ public void testDestroy() throws Exception {
+ EasyMock.expect(scopeContainer.getWrapper(component, null)).andReturn(wrapper);
+ EasyMock.expect(wrapper.getInstance()).andReturn(new Echo());
+ scopeContainer.returnWrapper(component, wrapper, null);
+ EasyMock.replay(component);
+ EasyMock.replay(scopeContainer);
+ EasyMock.replay(wrapper);
+ JavaTargetInvoker invoker = new JavaTargetInvoker(echoMethod, component, scopeContainer);
+ invoker.setCacheable(false);
+ assertEquals("foo", invoker.invokeTarget("foo", JavaTargetInvoker.NONE, workContext));
+ EasyMock.verify(component);
+ EasyMock.verify(scopeContainer);
+ EasyMock.verify(wrapper);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ echoMethod = Echo.class.getDeclaredMethod("echo", String.class);
+ component = EasyMock.createMock(JavaAtomicComponent.class);
+ scopeContainer = EasyMock.createNiceMock(ScopeContainer.class);
+ EasyMock.expect(scopeContainer.getScope()).andStubReturn(Scope.STATELESS);
+ wrapper = EasyMock.createNiceMock(InstanceWrapper.class);
+ workContext = EasyMock.createMock(WorkContext.class);
+ EasyMock.expect(workContext.getIdentifier(Scope.STATELESS)).andStubReturn(null);
+ EasyMock.replay(workContext);
+ }
+
+ public static class Echo {
+ public String echo(String message) throws Exception {
+ return message;
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/MultiplicityTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/MultiplicityTestCase.java
new file mode 100644
index 0000000000..ba478c9634
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/MultiplicityTestCase.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.core.implementation.java;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Tests wires that are configured with a multiplicity
+ *
+ * @version $Rev$ $Date$
+ */
+public class MultiplicityTestCase extends TestCase {
+
+ public void testMultiplicity() throws Exception {
+ // TODO implement
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/ResourceInjectionTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/ResourceInjectionTestCase.java
new file mode 100644
index 0000000000..749b2e50fc
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/ResourceInjectionTestCase.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.core.implementation.java;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.host.ResourceHost;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.injection.ResourceObjectFactory;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ResourceInjectionTestCase extends TestCase {
+
+ public void testResourceMemberInjection() throws Exception {
+ ScopeContainer containter = EasyMock.createNiceMock(ScopeContainer.class);
+ Constructor<Foo> ctor = Foo.class.getConstructor();
+ Field field = Foo.class.getDeclaredField("resource");
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setName(new URI("component"));
+ configuration.setGroupId(URI.create("composite"));
+ configuration.setInstanceFactory(new PojoObjectFactory<Foo>(ctor));
+ configuration.addResourceSite("bar", field);
+ JavaAtomicComponent component = new JavaAtomicComponent(configuration);
+ component.setScopeContainer(containter);
+
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.getTargetInstance()).andReturn("result");
+ EasyMock.replay(wire);
+
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(EasyMock.eq(String.class))).andReturn("result");
+ EasyMock.replay(host);
+
+ ResourceObjectFactory<String> factory = new ResourceObjectFactory<String>(String.class, false, host);
+ component.addResourceFactory("bar", factory);
+
+ Foo foo = (Foo) component.createInstance();
+ assertEquals("result", foo.resource);
+ }
+
+
+ public void testResourceConstructorInjection() throws Exception {
+ ScopeContainer containter = EasyMock.createNiceMock(ScopeContainer.class);
+ Constructor<FooConstructor> ctor = FooConstructor.class.getConstructor(String.class);
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setName(new URI("component"));
+ configuration.setGroupId(URI.create("composite"));
+ configuration.setInstanceFactory(new PojoObjectFactory<FooConstructor>(ctor));
+ List<String> ctorNames = new ArrayList<String>();
+ ctorNames.add("bar");
+ configuration.setConstructorParamNames(ctorNames);
+ JavaAtomicComponent component = new JavaAtomicComponent(configuration);
+ component.setScopeContainer(containter);
+
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.getTargetInstance()).andReturn("result");
+ EasyMock.replay(wire);
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(EasyMock.eq(String.class))).andReturn("result");
+ EasyMock.replay(host);
+
+ ResourceObjectFactory<String> factory = new ResourceObjectFactory<String>(String.class, false, host);
+ component.addResourceFactory("bar", factory);
+
+ FooConstructor foo = (FooConstructor) component.createInstance();
+ assertEquals("result", foo.resource);
+ }
+
+ public static class Foo {
+ protected String resource;
+
+ public Foo() {
+ }
+
+ }
+
+ public static class FooConstructor {
+ protected String resource;
+
+ public FooConstructor(String resource) {
+ this.resource = resource;
+ }
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/CallbackInvocationTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/CallbackInvocationTestCase.java
new file mode 100644
index 0000000000..c80bbb0264
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/CallbackInvocationTestCase.java
@@ -0,0 +1,363 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.java.integration;
+
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.osoa.sca.NoRegisteredCallbackException;
+import org.osoa.sca.annotations.Callback;
+
+import org.apache.tuscany.spi.builder.Connector;
+import org.apache.tuscany.spi.component.ComponentManager;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.services.work.WorkScheduler;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.builder.ConnectorImpl;
+import org.apache.tuscany.core.component.ComponentManagerImpl;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.component.scope.CompositeScopeContainer;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.java.JavaAtomicComponent;
+import org.apache.tuscany.core.implementation.java.JavaComponentBuilder;
+import org.apache.tuscany.core.implementation.java.JavaImplementation;
+import org.apache.tuscany.core.implementation.PojoWorkContextTunnel;
+import org.apache.tuscany.core.wire.jdk.JDKProxyService;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.getCurrentArguments;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import org.easymock.IAnswer;
+
+/**
+ * Verifies callback integration scenarios with Java components.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CallbackInvocationTestCase extends TestCase {
+ private ScopeContainer container;
+ private DeploymentContext context;
+ private JavaComponentBuilder builder;
+ private WorkScheduler scheduler;
+ private WorkContext workContext;
+ private ComponentManager componentManager;
+ private Connector connector;
+ private URI groupId;
+
+ /**
+ * Verifies callbacks between two Java component implementations: wire creation, connection, injection of callback
+ * proxy, and invocation
+ */
+ public void testComponentToComponentCallback() throws Exception {
+ ComponentDefinition<JavaImplementation> targetDefinition = createTarget();
+ JavaAtomicComponent targetComponent = (JavaAtomicComponent) builder.build(targetDefinition, context);
+ targetComponent.setScopeContainer(container);
+ container.register(targetComponent, groupId);
+ componentManager.register(targetComponent);
+ ComponentDefinition<JavaImplementation> sourceDefinition = createSource(URI.create("fooClient"));
+ JavaAtomicComponent clientComponent = (JavaAtomicComponent) builder.build(sourceDefinition, context);
+ clientComponent.setScopeContainer(container);
+ container.register(clientComponent, groupId);
+ componentManager.register(clientComponent);
+ connector.connect(sourceDefinition);
+ targetComponent.start();
+ clientComponent.start();
+ FooClient client = (FooClient) clientComponent.getTargetInstance();
+ PojoWorkContextTunnel.setThreadWorkContext(workContext);
+ try {
+ client.invoke();
+ assertTrue(client.invoked);
+ client.invokeMultiCallback();
+ assertTrue(client.count == 2);
+ } finally {
+ PojoWorkContextTunnel.setThreadWorkContext(null);
+ }
+ }
+
+ /**
+ * Verifies exception is thrown when callback is not implemented
+ */
+ public void testCallbackNotRegistered() throws Exception {
+ // JFM temporarily commenting out as implementation needs to be spec compliant
+ }
+
+ /**
+ * Verifies a callback in response to an invocation from two different client components is routed back to the
+ * appropriate client.
+ */
+ public void testTwoSourceComponentToComponentCallback() throws Exception {
+ ComponentDefinition<JavaImplementation> targetDefinition = createTarget();
+ JavaAtomicComponent targetComponent =
+ (JavaAtomicComponent) builder.build(targetDefinition, context);
+ targetComponent.setScopeContainer(container);
+ container.register(targetComponent, groupId);
+ componentManager.register(targetComponent);
+
+ ComponentDefinition<JavaImplementation> sourceDefinition1 = createSource(URI.create("client1"));
+ ComponentDefinition<JavaImplementation> sourceDefinition2 = createSource(URI.create("client2"));
+ JavaAtomicComponent clientComponent1 = (JavaAtomicComponent) builder.build(sourceDefinition1, context);
+ clientComponent1.setScopeContainer(container);
+ container.register(clientComponent1, groupId);
+ componentManager.register(clientComponent1);
+ JavaAtomicComponent clientComponent2 = (JavaAtomicComponent) builder.build(sourceDefinition2, context);
+ clientComponent2.setScopeContainer(container);
+ container.register(clientComponent2, groupId);
+ componentManager.register(clientComponent2);
+
+ connector.connect(sourceDefinition1);
+ connector.connect(sourceDefinition2);
+ targetComponent.start();
+
+ PojoWorkContextTunnel.setThreadWorkContext(workContext);
+ try {
+ FooClient client1 = (FooClient) clientComponent1.getTargetInstance();
+ client1.invoke();
+ assertTrue(client1.invoked);
+ FooClient client2 = (FooClient) clientComponent2.getTargetInstance();
+ client2.invoke();
+ assertTrue(client2.invoked);
+ } finally {
+ PojoWorkContextTunnel.setThreadWorkContext(null);
+ }
+ }
+
+
+ private ComponentDefinition<JavaImplementation> createTarget() throws NoSuchMethodException,
+ InvalidServiceContractException {
+ ConstructorDefinition<FooImpl> ctorDef = new ConstructorDefinition<FooImpl>(FooImpl.class.getConstructor());
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ type.setConstructorDefinition(ctorDef);
+ type.setImplementationScope(Scope.COMPOSITE);
+ Method method = FooImpl.class.getMethod("setCallback", FooCallback.class);
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ ServiceContract<?> contract = registry.introspect(Foo.class);
+ contract.setCallbackClass(FooCallback.class);
+ contract.setCallbackName("callback");
+ JavaMappedService mappedService = new JavaMappedService(URI.create("Foo"), contract, false, "callback", method);
+ type.getServices().put("Foo", mappedService);
+
+ JavaImplementation impl = new JavaImplementation(FooImpl.class, type);
+ impl.setComponentType(type);
+ impl.setImplementationClass(FooImpl.class);
+ return new ComponentDefinition<JavaImplementation>(URI.create("foo"), impl);
+ }
+
+ private ComponentDefinition<JavaImplementation> createSource(URI name)
+ throws NoSuchMethodException, URISyntaxException, InvalidServiceContractException {
+ ConstructorDefinition<FooClient> ctorDef =
+ new ConstructorDefinition<FooClient>(FooClient.class.getConstructor());
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ type.setConstructorDefinition(ctorDef);
+ type.setImplementationScope(Scope.COMPOSITE);
+ Method method = FooClient.class.getMethod("setFoo", Foo.class);
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ ServiceContract<?> contract = registry.introspect(Foo.class);
+ contract.setCallbackClass(FooCallback.class);
+ contract.setCallbackName("callback");
+ JavaMappedReference mappedReference = new JavaMappedReference(URI.create(name + "#" + "foo"), contract, method);
+ type.getReferences().put("foo", mappedReference);
+ ReferenceTarget refTarget = new ReferenceTarget();
+ refTarget.setReferenceName(URI.create(name + "#" + "foo"));
+ refTarget.getTargets().add(new URI("foo"));
+ JavaImplementation impl = new JavaImplementation(FooClient.class, type);
+ impl.setComponentType(type);
+ impl.setImplementationClass(FooClient.class);
+ ComponentDefinition<JavaImplementation> def = new ComponentDefinition<JavaImplementation>(name, impl);
+ def.getReferenceTargets().put("foo", refTarget);
+ return def;
+ }
+
+ private ComponentDefinition<JavaImplementation> createPlainSource(URI name)
+ throws NoSuchMethodException, URISyntaxException, InvalidServiceContractException {
+ ConstructorDefinition<FooPlainClient> ctorDef =
+ new ConstructorDefinition<FooPlainClient>(FooPlainClient.class.getConstructor());
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ type.setConstructorDefinition(ctorDef);
+ type.setImplementationScope(Scope.COMPOSITE);
+ Method method = FooPlainClient.class.getMethod("setFoo", Foo.class);
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ ServiceContract<?> contract = registry.introspect(Foo.class);
+ contract.setCallbackClass(FooCallback.class);
+ contract.setCallbackName("callback");
+ JavaMappedReference mappedReference = new JavaMappedReference(URI.create(name + "#" + "foo"), contract, method);
+ type.getReferences().put("foo", mappedReference);
+ ReferenceTarget refTarget = new ReferenceTarget();
+ refTarget.setReferenceName(URI.create(name + "#" + "foo"));
+ refTarget.getTargets().add(new URI("foo"));
+ JavaImplementation impl = new JavaImplementation(FooPlainClient.class, type);
+ ComponentDefinition<JavaImplementation> def = new ComponentDefinition<JavaImplementation>(name, impl);
+ def.getReferenceTargets().put("foo", refTarget);
+ return def;
+ }
+
+ @Callback(FooCallback.class)
+ public static interface Foo {
+ void call();
+
+ void callMultiCallback();
+
+ void callFromPlain();
+ }
+
+ public static class FooImpl implements Foo {
+ private FooCallback callback;
+
+ public FooImpl() {
+ }
+
+ @Callback
+ public void setCallback(FooCallback callback) {
+ this.callback = callback;
+ }
+
+ public void call() {
+ callback.callback();
+ }
+
+ public void callMultiCallback() {
+ callback.multiCallback();
+ callback.multiCallback();
+ }
+
+ public void callFromPlain() {
+ try {
+ callback.callback();
+ fail();
+ } catch (NoRegisteredCallbackException e) {
+ // expected
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public static class FooClient implements FooCallback {
+
+ private Foo foo;
+ private boolean invoked;
+ private int count;
+
+ public FooClient() {
+ }
+
+ public void setFoo(Foo foo) {
+ this.foo = foo;
+ }
+
+ public void callback() {
+ if (invoked) {
+ fail();
+ }
+ invoked = true;
+ }
+
+ public void multiCallback() {
+ count++;
+ }
+
+ public void invoke() {
+ foo.call();
+ }
+
+ public void invokeMultiCallback() {
+ foo.callMultiCallback();
+ }
+ }
+
+ public interface FooCallback {
+ void callback();
+
+ void multiCallback();
+ }
+
+ public static class FooPlainClient /* implements FooCallback */ { // do NOT implement the callback
+
+ private Foo foo;
+
+ public FooPlainClient() {
+ }
+
+ public void setFoo(Foo foo) {
+ this.foo = foo;
+ }
+
+ public void invoke() {
+ foo.callFromPlain();
+ }
+
+ public void callback() {
+
+ }
+
+ public void multiCallback() {
+
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ groupId = URI.create("composite");
+ componentManager = new ComponentManagerImpl();
+ connector = new ConnectorImpl(null, null, null, componentManager, scheduler, workContext);
+ container = new CompositeScopeContainer(null);
+ container.start();
+ container.startContext(groupId, groupId);
+ context = createMock(DeploymentContext.class);
+ expect(context.getCompositeScope()).andStubReturn(container);
+ expect(context.getGroupId()).andStubReturn(groupId);
+ replay(context);
+
+ scheduler = createMock(WorkScheduler.class);
+ scheduler.scheduleWork(isA(Runnable.class));
+ expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ Runnable runnable = (Runnable) getCurrentArguments()[0];
+ runnable.run();
+ return null;
+ }
+ });
+ replay(scheduler);
+
+ builder = new JavaComponentBuilder();
+ workContext = new WorkContextImpl();
+ workContext.setIdentifier(Scope.COMPOSITE, groupId);
+ builder.setWorkContext(workContext);
+ builder.setProxyService(new JDKProxyService(workContext));
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/WireToScopedJavaTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/WireToScopedJavaTestCase.java
new file mode 100644
index 0000000000..402604a343
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/WireToScopedJavaTestCase.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.core.implementation.java.integration;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.ProxyService;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.component.scope.CompositeScopeContainer;
+import org.apache.tuscany.core.component.scope.StatelessScopeContainer;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.PojoWorkContextTunnel;
+import org.apache.tuscany.core.implementation.java.JavaAtomicComponent;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.mock.component.Target;
+import org.apache.tuscany.core.mock.component.TargetImpl;
+import org.apache.tuscany.core.wire.InvocationChainImpl;
+import org.apache.tuscany.core.wire.WireImpl;
+import org.apache.tuscany.core.wire.jdk.JDKProxyService;
+
+/**
+ * Validates wiring from a wire to Java atomic component by scope
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class WireToScopedJavaTestCase extends TestCase {
+ private WorkContext workContext = new WorkContextImpl();
+ private ProxyService proxyService = new JDKProxyService(workContext);
+
+ public void testToStatelessScope() throws Exception {
+ StatelessScopeContainer scope = new StatelessScopeContainer(null);
+ scope.start();
+ final Wire wire = getWire(scope);
+ Target service = proxyService.createProxy(Target.class, wire);
+ assertNotNull(service);
+ PojoWorkContextTunnel.setThreadWorkContext(workContext);
+ try {
+ service.setString("foo");
+ assertEquals(null, service.getString());
+ } finally {
+ PojoWorkContextTunnel.setThreadWorkContext(null);
+ }
+ scope.stop();
+ }
+
+/*
+ public void testToRequestScope() throws Exception {
+ final RequestScopeContainer scope = new RequestScopeContainer(workContext, null);
+ scope.start();
+ scope.createGroup(URI.create("composite"));
+
+ scope.onEvent(new RequestStart(this));
+
+ final Wire wire = getWire(scope);
+ Target service = proxyService.createProxy(Target.class, wire);
+ assertNotNull(service);
+ service.setString("foo");
+
+ // another request
+ Executor executor = Executors.newSingleThreadExecutor();
+ FutureTask<Void> future = new FutureTask<Void>(new Runnable() {
+ public void run() {
+ scope.onEvent(new RequestStart(this));
+ Target service2 = proxyService.createProxy(Target.class, wire);
+ Target target2 = proxyService.createProxy(Target.class, wire);
+ assertEquals(null, service2.getString());
+ service2.setString("bar");
+ assertEquals("bar", service2.getString());
+ assertEquals("bar", target2.getString());
+ scope.onEvent(new RequestEnd(this));
+ }
+ }, null);
+ executor.execute(future);
+ future.get();
+
+ assertEquals("foo", service.getString());
+ scope.onEvent(new RequestEnd(this));
+ scope.stop();
+ }
+*/
+
+/*
+ public void testToSessionScope() throws Exception {
+ HttpSessionScopeContainer scope = new HttpSessionScopeContainer(workContext, null);
+ scope.createGroup(URI.create("composite"));
+ scope.start();
+ Object session1 = new Object();
+ workContext.setIdentifier(Scope.SESSION, session1);
+ scope.onEvent(new HttpSessionStart(this, session1));
+
+ final Wire wire = getWire(scope);
+ Target service = proxyService.createProxy(Target.class, wire);
+ Target target = proxyService.createProxy(Target.class, wire);
+ assertNotNull(service);
+ service.setString("foo");
+ assertEquals("foo", service.getString());
+ assertEquals("foo", target.getString());
+
+ workContext.clearIdentifier(Scope.SESSION);
+
+ //second session
+ Object session2 = new Object();
+ workContext.setIdentifier(Scope.SESSION, session2);
+ scope.onEvent(new HttpSessionStart(this, session2));
+
+ Target service2 = proxyService.createProxy(Target.class, wire);
+ assertNotNull(service2);
+ assertNull(service2.getString());
+ Target target2 = proxyService.createProxy(Target.class, wire);
+ service2.setString("bar");
+ assertEquals("bar", service2.getString());
+ assertEquals("bar", target2.getString());
+
+ scope.onEvent(new HttpSessionEnd(this, session2));
+ workContext.clearIdentifier(Scope.SESSION);
+
+ workContext.setIdentifier(Scope.SESSION, session1);
+ assertEquals("foo", service.getString());
+
+ scope.onEvent(new HttpSessionEnd(this, session1));
+
+ scope.stop();
+ }
+*/
+
+ public void testToCompositeScope() throws Exception {
+ URI groupId = URI.create("composite");
+ Object contextId = new Object();
+ CompositeScopeContainer scope = new CompositeScopeContainer(null);
+ scope.start();
+ scope.startContext(contextId, groupId);
+ workContext.setIdentifier(Scope.COMPOSITE, contextId);
+ final Wire wire = getWire(scope);
+ Target service = proxyService.createProxy(Target.class, wire);
+ Target target = proxyService.createProxy(Target.class, wire);
+ PojoWorkContextTunnel.setThreadWorkContext(workContext);
+ try {
+ assertNotNull(service);
+ service.setString("foo");
+ assertEquals("foo", service.getString());
+ assertEquals("foo", target.getString());
+ } finally {
+ PojoWorkContextTunnel.setThreadWorkContext(null);
+ }
+ scope.stop();
+ }
+
+ private Wire getWire(ScopeContainer scope) throws Exception {
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setImplementationClass(TargetImpl.class);
+ configuration.setInstanceFactory(new PojoObjectFactory<TargetImpl>(TargetImpl.class.getConstructor()));
+ configuration.setWorkContext(workContext);
+ configuration.setName(new URI("source"));
+ configuration.setName(new URI("target"));
+ configuration.setGroupId(URI.create("composite"));
+
+ JavaAtomicComponent target = new JavaAtomicComponent(configuration);
+ target.setScopeContainer(scope);
+
+ Wire wire = createWire("target#Target", Target.class, target);
+
+ target.start();
+ return wire;
+ }
+
+ private static <T> Wire createWire(String targetName, Class<T> interfaze, JavaAtomicComponent target)
+ throws InvalidServiceContractException, TargetInvokerCreationException {
+ Wire wire = new WireImpl();
+ JavaServiceContract contract = new JavaServiceContract(interfaze);
+ contract.setConversational(false);
+ wire.setSourceContract(contract);
+ createChains(interfaze, wire);
+ wire.setTargetUri(URI.create(targetName));
+ wire.setSourceUri(URI.create("component#ref"));
+ for (InvocationChain chain : wire.getInvocationChains().values()) {
+ chain.setTargetInvoker(target.createTargetInvoker("target", chain.getOperation()));
+ }
+ return wire;
+ }
+
+ private static void createChains(Class<?> interfaze, Wire wire)
+ throws InvalidServiceContractException {
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ ServiceContract<?> contract = registry.introspect(interfaze);
+ for (Operation operation : contract.getOperations().values()) {
+ InvocationChain chain = new InvocationChainImpl(operation);
+ wire.addInvocationChain(operation, chain);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessorTestCase.java
new file mode 100644
index 0000000000..08e5b2315c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessorTestCase.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.core.implementation.processor;
+
+import org.osoa.sca.annotations.AllowsPassByReference;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev: 452761 $ $Date: 2006-10-04 12:03:20 +0530 (Wed, 04 Oct 2006) $
+ */
+public class AllowsPassByReferenceProcessorTestCase extends TestCase {
+
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type;
+ AllowsPassByReferenceProcessor processor;
+
+ public void testClassAnnotation() throws Exception {
+// processor.visitClass(Foo.class, type, null);
+// assertEquals(true, type.isAllowsPassByReference());
+//
+// processor.visitClass(Bar.class, type, null);
+// assertEquals(false, type.isAllowsPassByReference());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ type = new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor = new AllowsPassByReferenceProcessor();
+ }
+
+ @AllowsPassByReference
+ private class Foo {
+ }
+
+ //no annotation
+ private class Bar {
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorExtensibilityTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorExtensibilityTestCase.java
new file mode 100644
index 0000000000..f82d0f6f21
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorExtensibilityTestCase.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.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+
+import org.osoa.sca.annotations.Property;
+
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * Verifies the constructor processor works when parameters are marked with custom extension annotations
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConstructorProcessorExtensibilityTestCase extends TestCase {
+ private ConstructorProcessor processor =
+ new ConstructorProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl()));
+
+ public void testProcessFirst() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor1 = Foo.class.getConstructor(String.class, String.class);
+ processor.visitConstructor(ctor1, type, null);
+ assertEquals("foo", type.getConstructorDefinition().getInjectionNames().get(0));
+ }
+
+ /**
+ * Verifies the constructor processor can be called after another processor has evaluated the constructor and found
+ * an annotation
+ *
+ * @throws Exception
+ */
+ public void testProcessLast() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor1 = Foo.class.getConstructor(String.class, String.class);
+ ConstructorDefinition<Foo> definition = new ConstructorDefinition<Foo>(ctor1);
+ definition.getInjectionNames().add("");
+ definition.getInjectionNames().add("mybar");
+ type.setConstructorDefinition(definition);
+ processor.visitConstructor(ctor1, type, null);
+ assertEquals("foo", type.getConstructorDefinition().getInjectionNames().get(0));
+ }
+
+
+ private @interface Bar {
+
+ }
+
+ private static class Foo {
+ @org.osoa.sca.annotations.Constructor
+ public Foo(@Property(name = "foo") String foo, @Bar String bar) {
+
+ }
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java
new file mode 100644
index 0000000000..c6add2cae2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.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.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.Multiplicity;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorProcessorTestCase extends TestCase {
+ private ConstructorProcessor processor =
+ new ConstructorProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl()));
+
+ public void testDuplicateConstructor() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ try {
+ processor.visitClass(BadFoo.class, type, null);
+ fail();
+ } catch (DuplicateConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testConstructorAnnotation() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor1 = Foo.class.getConstructor(String.class);
+ processor.visitConstructor(ctor1, type, null);
+ assertEquals("foo", type.getConstructorDefinition().getInjectionNames().get(0));
+ }
+
+ public void testNoAnnotation() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<NoAnnotation> ctor1 = NoAnnotation.class.getConstructor();
+ processor.visitConstructor(ctor1, type, null);
+ assertNull(type.getConstructorDefinition());
+ }
+
+ public void testBadAnnotation() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<BadAnnotation> ctor1 = BadAnnotation.class.getConstructor(String.class, Foo.class);
+ try {
+ processor.visitConstructor(ctor1, type, null);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testMixedParameters() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Mixed> ctor1 = Mixed.class.getConstructor(String.class, String.class, String.class);
+ processor.visitConstructor(ctor1, type, null);
+ assertEquals("_ref0", type.getConstructorDefinition().getInjectionNames().get(0));
+ assertEquals("foo", type.getConstructorDefinition().getInjectionNames().get(1));
+ assertEquals("bar", type.getConstructorDefinition().getInjectionNames().get(2));
+ }
+
+ private static class BadFoo {
+
+ @org.osoa.sca.annotations.Constructor("foo")
+ public BadFoo(String foo) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor({"foo", "bar"})
+ public BadFoo(String foo, String bar) {
+
+ }
+ }
+
+ private static class Foo {
+ @org.osoa.sca.annotations.Constructor("foo")
+ public Foo(String foo) {
+
+ }
+ }
+
+ private static class NoAnnotation {
+ public NoAnnotation() {
+ }
+ }
+
+ private static class BadAnnotation {
+ @org.osoa.sca.annotations.Constructor("foo")
+ public BadAnnotation(String foo, Foo ref) {
+ }
+ }
+
+
+ public static final class Mixed {
+ @org.osoa.sca.annotations.Constructor
+ public Mixed(@Reference String param1,
+ @Property(name = "foo")String param2,
+ @Reference(name = "bar")String param3) {
+ }
+ }
+
+ public static final class Multiple {
+ @org.osoa.sca.annotations.Constructor
+ public Multiple(@Reference Collection<String> param1,
+ @Property(name = "foo")String[] param2,
+ @Reference(name = "bar", required = true)List<String> param3,
+ @Property(name = "abc")Set<String> param4,
+ @Reference(name = "xyz")String[] param5) {
+ }
+ }
+
+ public void testMultiplicity() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Multiple> ctor1 =
+ Multiple.class.getConstructor(Collection.class, String[].class, List.class, Set.class, String[].class);
+ processor.visitConstructor(ctor1, type, null);
+ JavaMappedReference ref0 = type.getReferences().get("_ref0");
+ assertNotNull(ref0);
+ assertEquals(Multiplicity.ZERO_N, ref0.getMultiplicity());
+ JavaMappedReference ref1 = type.getReferences().get("bar");
+ assertNotNull(ref1);
+ assertEquals(Multiplicity.ONE_N, ref1.getMultiplicity());
+ JavaMappedReference ref2 = type.getReferences().get("xyz");
+ assertNotNull(ref2);
+ assertEquals(Multiplicity.ZERO_N, ref2.getMultiplicity());
+ JavaMappedProperty prop1 = type.getProperties().get("foo");
+ assertNotNull(prop1);
+ assertTrue(prop1.isMany());
+ JavaMappedProperty prop2 = type.getProperties().get("abc");
+ assertNotNull(prop2);
+ assertTrue(prop2.isMany());
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java
new file mode 100644
index 0000000000..c3f1eec6c0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.implementation.processor;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import org.osoa.sca.annotations.Property;
+
+import org.apache.tuscany.spi.implementation.java.DuplicatePropertyException;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorPropertyTestCase extends TestCase {
+
+ ConstructorProcessor processor =
+ new ConstructorProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl()));
+
+ public void testProperty() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
+ processor.visitConstructor(ctor, type, null);
+ JavaMappedProperty<?> property = type.getProperties().get("myProp");
+ assertTrue(property.isRequired());
+ assertEquals("myProp", property.getName());
+ }
+
+ public void testTwoPropertiesSameType() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+ processor.visitConstructor(ctor, type, null);
+ assertNotNull(type.getProperties().get("myProp1"));
+ assertNotNull(type.getProperties().get("myProp2"));
+ }
+
+ public void testDuplicateProperty() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class, String.class);
+ try {
+ processor.visitConstructor(ctor, type, null);
+ fail();
+ } catch (DuplicatePropertyException e) {
+ // expected
+ }
+ }
+
+ public void testNoName() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class);
+ try {
+ processor.visitConstructor(ctor, type, null);
+ fail();
+ } catch (InvalidPropertyException e) {
+ // expected
+ }
+ }
+
+ public void testNamesOnConstructor() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor = Foo.class.getConstructor(Integer.class);
+ processor.visitConstructor(ctor, type, null);
+ assertNotNull(type.getProperties().get("myProp"));
+ }
+
+ public void testInvalidNumberOfNames() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(Integer.class, Integer.class);
+ try {
+ processor.visitConstructor(ctor, type, null);
+ fail();
+ } catch (InvalidPropertyException e) {
+ // expected
+ }
+ }
+
+ public void testNoMatchingNames() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(List.class, List.class);
+ try {
+ processor.visitConstructor(ctor, type, null);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+// public void testMultiplicityRequired() throws Exception {
+ // TODO multiplicity
+// }
+
+ private static class Foo {
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Property(name = "myProp", required = true)String prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myProp")
+ public Foo(@Property Integer prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Property(name = "myProp1")String prop1, @Property(name = "myProp2")String prop2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Property List prop) {
+
+ }
+ }
+
+ private static class BadFoo {
+
+ @org.osoa.sca.annotations.Constructor()
+ public BadFoo(@Property(name = "myProp")String prop1, @Property(name = "myProp")String prop2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor()
+ public BadFoo(@Property String prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myProp")
+ public BadFoo(@Property Integer prop, @Property Integer prop2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor({"myRef", "myRef2"})
+ public BadFoo(@Property List ref, @Property(name = "myOtherRef")List ref2) {
+
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java
new file mode 100644
index 0000000000..067a23a096
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.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.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorReferenceTestCase extends TestCase {
+ private ConstructorProcessor processor;
+
+ public void testReference() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
+ processor.visitConstructor(ctor, type, null);
+ JavaMappedReference reference = type.getReferences().get("myRef");
+ assertTrue(reference.isRequired());
+ assertEquals("#myRef", reference.getUri().toString());
+ }
+
+ public void testTwoReferencesSameType() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+ processor.visitConstructor(ctor, type, null);
+ assertNotNull(type.getReferences().get("myRef1"));
+ assertNotNull(type.getReferences().get("myRef2"));
+ }
+
+ public void testDuplicateProperty() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class, String.class);
+ try {
+ processor.visitConstructor(ctor, type, null);
+ fail();
+ } catch (DuplicateReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testNoName() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<NoNameFoo> ctor = NoNameFoo.class.getConstructor(String.class);
+ processor.visitConstructor(ctor, type, null);
+ assertNotNull(type.getReferences().get("_ref0"));
+ }
+
+ public void testNamesOnConstructor() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor = Foo.class.getConstructor(Integer.class);
+ processor.visitConstructor(ctor, type, null);
+ assertNotNull(type.getReferences().get("myRef"));
+ }
+
+ public void testInvalidNumberOfNames() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(Integer.class, Integer.class);
+ try {
+ processor.visitConstructor(ctor, type, null);
+ fail();
+ } catch (InvalidReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testNoMatchingNames() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(List.class, List.class);
+ try {
+ processor.visitConstructor(ctor, type, null);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ processor =
+ new ConstructorProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl()));
+ }
+
+// public void testMultiplicityRequired() throws Exception {
+ // TODO multiplicity
+// }
+
+ private static class Foo {
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Reference(name = "myRef", required = true)String prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Reference(name = "myRef1")String prop1, @Reference(name = "myRef2")String prop2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myRef")
+ public Foo(@Reference Integer prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor()
+ public Foo(@Reference List prop) {
+
+ }
+ }
+
+ private static class NoNameFoo {
+
+ @org.osoa.sca.annotations.Constructor
+ public NoNameFoo(@Reference String prop) {
+
+ }
+ }
+
+ private static class BadFoo {
+
+ @org.osoa.sca.annotations.Constructor
+ public BadFoo(@Reference(name = "myRef")String prop1, @Reference(name = "myRef")String prop2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor
+ public BadFoo(@Reference String prop) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myRef")
+ public BadFoo(@Reference Integer ref, @Reference Integer ref2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor({"myRef", "myRef2"})
+ public BadFoo(@Reference List ref, @Reference(name = "myOtherRef")List ref2) {
+
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java
new file mode 100644
index 0000000000..6272b5216e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.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.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import org.apache.tuscany.api.annotation.Resource;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorResourceTestCase extends TestCase {
+
+ ConstructorProcessor processor =
+ new ConstructorProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl()));
+
+ public void testResource() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
+ processor.visitConstructor(ctor, type, null);
+ org.apache.tuscany.spi.implementation.java.Resource resource = type.getResources().get("myResource");
+ assertFalse(resource.isOptional());
+ }
+
+ public void testTwoResourcesSameType() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+ processor.visitConstructor(ctor, type, null);
+ assertNotNull(type.getResources().get("myResource1"));
+ assertNotNull(type.getResources().get("myResource2"));
+ }
+
+ public void testDuplicateResource() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class, String.class);
+ try {
+ processor.visitConstructor(ctor, type, null);
+ fail();
+ } catch (DuplicateResourceException e) {
+ // expected
+ }
+ }
+
+ public void testNoName() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<ConstructorResourceTestCase.BadFoo> ctor =
+ ConstructorResourceTestCase.BadFoo.class.getConstructor(String.class);
+ try {
+ processor.visitConstructor(ctor, type, null);
+ fail();
+ } catch (InvalidResourceException e) {
+ // expected
+ }
+ }
+
+ public void testNamesOnConstructor() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor = Foo.class.getConstructor(Integer.class);
+ processor.visitConstructor(ctor, type, null);
+ assertNotNull(type.getResources().get("myResource"));
+ }
+
+ public void testInvalidNumberOfNames() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<ConstructorResourceTestCase.BadFoo> ctor =
+ ConstructorResourceTestCase.BadFoo.class.getConstructor(Integer.class, Integer.class);
+ try {
+ processor.visitConstructor(ctor, type, null);
+ fail();
+ } catch (InvalidResourceException e) {
+ // expected
+ }
+ }
+
+ public void testNoMatchingNames() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<ConstructorResourceTestCase.BadFoo> ctor =
+ ConstructorResourceTestCase.BadFoo.class.getConstructor(List.class, List.class);
+ try {
+ processor.visitConstructor(ctor, type, null);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+ private static class Foo {
+
+ @org.osoa.sca.annotations.Constructor
+ public Foo(@Resource(name = "myResource") String resource) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myResource")
+ public Foo(@Resource Integer resource) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor
+ public Foo(@Resource(name = "myResource1") String res1, @Resource(name = "myResource2") String res2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor
+ public Foo(@Resource List res) {
+
+ }
+ }
+
+ private static class BadFoo {
+
+ @org.osoa.sca.annotations.Constructor
+ public BadFoo(@Resource(name = "myResource") String res1, @Resource(name = "myResource") String res2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor
+ public BadFoo(@Resource String res) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor("myProp")
+ public BadFoo(@Resource Integer res, @Resource Integer res2) {
+
+ }
+
+ @org.osoa.sca.annotations.Constructor({"myRes", "myRes2"})
+ public BadFoo(@Resource List res, @Resource(name = "myOtherRes") List res2) {
+
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java
new file mode 100644
index 0000000000..c0bf24e5fd
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.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.core.implementation.processor;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.RequestContext;
+import org.osoa.sca.annotations.Context;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ContextProcessorTestCase extends TestCase {
+ private ContextProcessor processor;
+ private Component composite;
+
+ // FIXME: resurrect to test ComponentContext injection
+/*
+ public void testCompositeContextMethod() throws Exception {
+ Method method = Foo.class.getMethod("setContext", ComponentContext.class);
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitMethod(composite, method, type, null);
+ assertNotNull(type.getResources().get("context"));
+ }
+*/
+
+ // FIXME: resurrect to test ComponentContext injection
+/*
+ public void testCompositeContextField() throws Exception {
+ Field field = Foo.class.getDeclaredField("context");
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitField(composite, field, type, null);
+ assertNotNull(type.getResources().get("context"));
+ }
+*/
+
+ public void testRequestContextMethod() throws Exception {
+ Method method = Foo.class.getMethod("setRequestContext", RequestContext.class);
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitMethod(method, type, null);
+ assertNotNull(type.getResources().get("requestContext"));
+ }
+
+ public void testRequestContextField() throws Exception {
+ Field field = Foo.class.getDeclaredField("requestContext");
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitField(field, type, null);
+ assertNotNull(type.getResources().get("requestContext"));
+ }
+
+ public void testInvalidParamType() throws Exception {
+ Method method = Foo.class.getMethod("setContext", String.class);
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ try {
+ processor.visitMethod(method, type, null);
+ fail();
+ } catch (UnknownContextTypeException e) {
+ // expected
+ }
+ }
+
+ public void testInvalidParamTypeField() throws Exception {
+ Field field = Foo.class.getDeclaredField("badContext");
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ try {
+ processor.visitField(field, type, null);
+ fail();
+ } catch (UnknownContextTypeException e) {
+ // expected
+ }
+ }
+
+
+ public void testInvalidParamNum() throws Exception {
+ Method method = Foo.class.getMethod("setContext", ComponentContext.class, String.class);
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ try {
+ processor.visitMethod(method, type, null);
+ fail();
+ } catch (IllegalContextException e) {
+ // expected
+ }
+ }
+
+ public void testInvalidNoParams() throws Exception {
+ Method method = Foo.class.getMethod("setContext");
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ try {
+ processor.visitMethod(method, type, null);
+ fail();
+ } catch (IllegalContextException e) {
+ // expected
+ }
+ }
+
+ public void testNoContext() throws Exception {
+ Method method = Foo.class.getMethod("noContext", ComponentContext.class);
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitMethod(method, type, null);
+ assertEquals(0, type.getResources().size());
+ }
+
+ public void testNoContextField() throws Exception {
+ Field field = Foo.class.getDeclaredField("noContext");
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitField(field, type, null);
+ assertEquals(0, type.getResources().size());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ processor = new ContextProcessor();
+ processor.setWorkContext(EasyMock.createNiceMock(WorkContext.class));
+ composite = EasyMock.createNiceMock(Component.class);
+ }
+
+ private class Foo {
+ @Context
+ protected ComponentContext context;
+
+ @Context
+ protected Object badContext;
+
+ protected ComponentContext noContext;
+
+ @Context
+ protected RequestContext requestContext;
+
+ @Context
+ public void setContext(ComponentContext context) {
+
+ }
+
+ @Context
+ public void setContext(String context) {
+
+ }
+
+ @Context
+ public void setContext(ComponentContext context, String string) {
+
+ }
+
+ @Context
+ public void setContext() {
+
+ }
+
+ public void noContext(ComponentContext context) {
+
+ }
+
+ @Context
+ public void setRequestContext(RequestContext requestContext) {
+ this.requestContext = requestContext;
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConversationProcessorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConversationProcessorTestCase.java
new file mode 100644
index 0000000000..45149a1327
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConversationProcessorTestCase.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.osoa.sca.annotations.ConversationAttributes;
+import org.osoa.sca.annotations.ConversationID;
+import org.osoa.sca.annotations.Scope;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConversationProcessorTestCase extends TestCase {
+ private ConversationProcessor processor = new ConversationProcessor();
+
+ public void testMaxIdleTime() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(FooMaxIdle.class, type, null);
+ assertEquals(10000L, type.getMaxIdleTime());
+ assertEquals(-1, type.getMaxAge());
+ }
+
+ public void testMaxAge() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(FooMaxAge.class, type, null);
+ assertEquals(10000L, type.getMaxAge());
+ assertEquals(-1, type.getMaxIdleTime());
+ }
+
+ public void testBadFooBoth() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ try {
+ processor.visitClass(BadFooBoth.class, type, null);
+ fail();
+ } catch (InvalidConversationalImplementation e) {
+ // expected
+ }
+ }
+
+ public void testImplicitScope() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(ImplicitFooScope.class, type, null);
+ assertEquals(org.apache.tuscany.spi.model.Scope.CONVERSATION, type.getImplementationScope());
+ }
+
+ public void testBadFooScope() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ try {
+ processor.visitClass(BadFooScope.class, type, null);
+ fail();
+ } catch (InvalidConversationalImplementation e) {
+ // expected
+ }
+ }
+
+ public void testJustConversation() throws Exception {
+ // TODO do we want these semantics
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(FooJustConversation.class, type, null);
+ assertEquals(org.apache.tuscany.spi.model.Scope.CONVERSATION, type.getImplementationScope());
+ assertEquals(-1, type.getMaxAge());
+ assertEquals(-1, type.getMaxIdleTime());
+ }
+
+ public void testSetConversationIDField() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Field field = FooWithConversationIDField.class.getDeclaredField("conversationID");
+ processor.visitField(field, type, null);
+ assertNotNull(type.getConversationIDMember());
+ assertEquals(field, type.getConversationIDMember());
+ }
+
+ public void testSetConversationIDMethod() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Method method = FooWithConversationIDMethod.class.getDeclaredMethods()[0];
+ processor.visitMethod(method, type, null);
+ assertNotNull(type.getConversationIDMember());
+ assertEquals(method, type.getConversationIDMember());
+ }
+
+ @Scope("CONVERSATION")
+ @ConversationAttributes(maxIdleTime = "10 seconds")
+ private class FooMaxIdle {
+ }
+
+ @Scope("CONVERSATION")
+ @ConversationAttributes(maxAge = "10 seconds")
+ private class FooMaxAge {
+ }
+
+ @Scope("CONVERSATION")
+ @ConversationAttributes(maxAge = "10 seconds", maxIdleTime = "10 seconds")
+ private class BadFooBoth {
+ }
+
+ @ConversationAttributes(maxAge = "10 seconds")
+ private class ImplicitFooScope {
+ }
+
+ @Scope("STATELESS")
+ @ConversationAttributes(maxAge = "10 seconds")
+ private class BadFooScope {
+ }
+
+ @ConversationAttributes
+ private class FooJustConversation {
+ }
+
+ private class FooWithConversationIDField {
+ @ConversationID
+ private String conversationID;
+ }
+
+ private class FooWithConversationIDMethod {
+ @ConversationID
+ void setConversationID(String conversationID) {
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConvertTimeMillisTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConvertTimeMillisTestCase.java
new file mode 100644
index 0000000000..556416a797
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConvertTimeMillisTestCase.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.core.implementation.processor;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConvertTimeMillisTestCase extends TestCase {
+ private MockProcessor registy;
+
+ public void testConvertSeconds() throws Exception {
+ assertEquals(10000L, registy.convertTimeMillis("10 seconds"));
+ assertEquals(10000L, registy.convertTimeMillis("10 SECONDS"));
+ try {
+ registy.convertTimeMillis("10seconds");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ public void testConvertMinutes() throws Exception {
+ assertEquals(600000L, registy.convertTimeMillis("10 minutes"));
+ assertEquals(600000L, registy.convertTimeMillis("10 MINUTES"));
+ try {
+ registy.convertTimeMillis("10minutes");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ public void testConvertHours() throws Exception {
+ assertEquals(36000000L, registy.convertTimeMillis("10 hours"));
+ assertEquals(36000000L, registy.convertTimeMillis("10 HOURS"));
+ try {
+ registy.convertTimeMillis("10hours");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ public void testConvertDays() throws Exception {
+ assertEquals(864000000L, registy.convertTimeMillis("10 days"));
+ assertEquals(864000000L, registy.convertTimeMillis("10 DAYS"));
+ try {
+ registy.convertTimeMillis("10days");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ public void testConvertYears() throws Exception {
+ assertEquals(315569260000L, registy.convertTimeMillis("10 years"));
+ assertEquals(315569260000L, registy.convertTimeMillis("10 YEARS"));
+ try {
+ registy.convertTimeMillis("10years");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ public void testConvertDefault() throws Exception {
+ assertEquals(10000L, registy.convertTimeMillis("10 "));
+ assertEquals(10000L, registy.convertTimeMillis("10"));
+ }
+
+ public void testInvalid() throws Exception {
+ try {
+ registy.convertTimeMillis("foo");
+ fail();
+ } catch (NumberFormatException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ registy = new MockProcessor();
+ }
+
+ private class MockProcessor extends ConversationProcessor {
+
+ @Override
+ protected long convertTimeMillis(String expr) throws NumberFormatException {
+ return super.convertTimeMillis(expr);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/DestroyProcessorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/DestroyProcessorTestCase.java
new file mode 100644
index 0000000000..c4a4861d50
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/DestroyProcessorTestCase.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.core.implementation.processor;
+
+import java.lang.reflect.Method;
+
+import org.osoa.sca.annotations.Destroy;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DestroyProcessorTestCase extends TestCase {
+
+ public void testDestroy() throws Exception {
+ DestroyProcessor processor = new DestroyProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Method method = Foo.class.getMethod("destroy");
+ processor.visitMethod(method, type, null);
+ assertNotNull(type.getDestroyMethod());
+ }
+
+ public void testBadDestroy() throws Exception {
+ DestroyProcessor processor = new DestroyProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Method method = Bar.class.getMethod("badDestroy", String.class);
+ try {
+ processor.visitMethod(method, type, null);
+ fail();
+ } catch (IllegalDestructorException e) {
+ // expected
+ }
+ }
+
+ public void testTwoDestroy() throws Exception {
+ DestroyProcessor processor = new DestroyProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Method method = Bar.class.getMethod("destroy");
+ Method method2 = Bar.class.getMethod("destroy2");
+ processor.visitMethod(method, type, null);
+ try {
+ processor.visitMethod(method2, type, null);
+ fail();
+ } catch (DuplicateDestructorException e) {
+ // expected
+ }
+ }
+
+
+ private class Foo {
+
+ @Destroy
+ public void destroy() {
+ }
+ }
+
+
+ private class Bar {
+
+ @Destroy
+ public void destroy() {
+ }
+
+ @Destroy
+ public void destroy2() {
+ }
+
+ @Destroy
+ public void badDestroy(String foo) {
+ }
+
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessorTestCase.java
new file mode 100644
index 0000000000..292f44c3bd
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessorTestCase.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.core.implementation.processor;
+
+import org.osoa.sca.annotations.EagerInit;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class EagerInitProcessorTestCase extends TestCase {
+
+ public void testNoLevel() throws ProcessingException {
+ EagerInitProcessor processor = new EagerInitProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(Level.class, type, null);
+ assertEquals(50, type.getInitLevel());
+ }
+
+ public void testSubclass() throws ProcessingException {
+ EagerInitProcessor processor = new EagerInitProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(SubClass.class, type, null);
+ assertEquals(50, type.getInitLevel());
+ }
+
+ @EagerInit
+ private class Level {
+ }
+
+ private class SubClass extends Level {
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicAndPropertyTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicAndPropertyTestCase.java
new file mode 100644
index 0000000000..7827e47872
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicAndPropertyTestCase.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.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+
+import org.osoa.sca.annotations.Property;
+
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class HeuristicAndPropertyTestCase extends TestCase {
+
+ private PropertyProcessor propertyProcessor;
+ private HeuristicPojoProcessor heuristicProcessor;
+
+ /**
+ * Verifies the property and heuristic processors don't collide
+ */
+ @SuppressWarnings("unchecked")
+ public void testPropertyProcessorWithHeuristicProcessor() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor ctor = Foo.class.getConstructor(String.class);
+ type.setConstructorDefinition(new ConstructorDefinition(ctor));
+ propertyProcessor.visitConstructor(ctor, type, null);
+ heuristicProcessor.visitEnd(Foo.class, type, null);
+ assertEquals(1, type.getProperties().size());
+ assertNotNull(type.getProperties().get("foo"));
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ ImplementationProcessorServiceImpl service =
+ new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl());
+ propertyProcessor = new PropertyProcessor(service);
+ heuristicProcessor = new HeuristicPojoProcessor(service);
+ }
+
+ public static class Foo {
+ public Foo(@Property(name = "foo") String prop) {
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java
new file mode 100644
index 0000000000..45fe6be68f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java
@@ -0,0 +1,297 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.net.URI;
+
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Remotable;
+
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class HeuristicConstructorTestCase extends TestCase {
+
+ private HeuristicPojoProcessor processor =
+ new HeuristicPojoProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl()));
+
+ /**
+ * Verifies a single constructor is chosen with a parameter as the type
+ */
+ public void testSingleConstructorWithParam() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ JavaMappedProperty<String> prop = new JavaMappedProperty<String>();
+ prop.setName("foo");
+ prop.setJavaType(String.class);
+ type.getProperties().put("foo", prop);
+ processor.visitEnd(Foo1.class, type, null);
+ assertNotNull(type.getConstructorDefinition().getConstructor());
+ assertEquals("foo", type.getConstructorDefinition().getInjectionNames().get(0));
+ }
+
+ /**
+ * Verifies a single constructor is chosen with a reference as the type
+ */
+ public void testSingleConstructorWithRef() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ JavaMappedReference ref = new JavaMappedReference();
+ ref.setUri(URI.create("#foo"));
+ ServiceContract contract = new JavaServiceContract(String.class);
+ ref.setServiceContract(contract);
+ type.getReferences().put("foo", ref);
+ processor.visitEnd(Foo1.class, type, null);
+ assertNotNull(type.getConstructorDefinition().getConstructor());
+ assertEquals("foo", type.getConstructorDefinition().getInjectionNames().get(0));
+ }
+
+ /**
+ * Verifies a single constructor is chosen with a property and a reference as the type
+ */
+ public void testSingleConstructorWithPropRef() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+
+ JavaMappedProperty<String> prop = new JavaMappedProperty<String>();
+ prop.setName("foo");
+ prop.setJavaType(String.class);
+ type.getProperties().put("foo", prop);
+
+ JavaMappedReference ref = new JavaMappedReference();
+ ref.setUri(URI.create("#ref"));
+ ServiceContract contract = new JavaServiceContract(Foo1.class);
+ ref.setServiceContract(contract);
+ type.getReferences().put("ref", ref);
+ processor.visitEnd(Foo2.class, type, null);
+ assertNotNull(type.getConstructorDefinition().getConstructor());
+ assertEquals(2, type.getConstructorDefinition().getInjectionNames().size());
+ }
+
+
+ public void testSingleConstructorResolvableParam() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitEnd(Foo5.class, type, null);
+ assertEquals(String.class, type.getProperties().get("string").getJavaType());
+ }
+
+ public void testSingleConstructorResolvableRef() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitEnd(Foo6.class, type, null);
+ assertEquals(Ref.class,
+ type.getReferences().get("heuristicconstructortestcase$ref").getServiceContract().getInterfaceClass());
+ }
+
+ public void testSingleConstructorAmbiguousRef() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ JavaMappedReference ref = new JavaMappedReference();
+ ref.setUri(URI.create("#ref"));
+ ServiceContract contract = new JavaServiceContract(Foo1.class);
+ ref.setServiceContract(contract);
+ type.getReferences().put("ref", ref);
+ JavaMappedReference ref2 = new JavaMappedReference();
+ ref2.setUri(URI.create("#ref2"));
+ ref2.setServiceContract(contract);
+ type.getReferences().put("ref2", ref2);
+ try {
+ processor.visitEnd(Foo4.class, type, null);
+ fail();
+ } catch (AmbiguousConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testConstructorPropertyAnnotatedParamsOnly() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitEnd(Foo7.class, type, null);
+ assertNotNull(type.getProperties().get("myProp"));
+ }
+
+ public void testConstructorReferenceAnnotatedParamsOnly() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitEnd(Foo8.class, type, null);
+ assertNotNull(type.getReferences().get("myRef"));
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testDefaultConstructor() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitEnd(Foo3.class, type, null);
+ assertNotNull(type.getConstructorDefinition().getConstructor());
+ }
+
+ public void testSameTypesButAnnotated() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitEnd(Foo12.class, type, null);
+ assertEquals(2, type.getProperties().size());
+ assertNotNull(type.getProperties().get("prop1"));
+ assertNotNull(type.getProperties().get("prop2"));
+ }
+
+ /**
+ * Verifies processing executes with additional extension annotations
+ */
+ public void testRandomAnnotation() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitEnd(Foo11.class, type, null);
+ assertEquals(1, type.getProperties().size());
+ assertNotNull(type.getProperties().get("prop1"));
+ }
+
+ public void testPrivateConstructor() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ try {
+ processor.visitEnd(Foo14.class, type, null);
+ fail();
+ } catch (NoConstructorException e) {
+ // expected
+ }
+ }
+
+
+ public void testMultipleConstructors() throws Exception {
+ // throw new UnsupportedOperationException("Finish heuristic multiple constructors - Foo10");
+ }
+
+
+ public static class Foo1 {
+ public Foo1(String val) {
+ }
+ }
+
+ public static class Foo2 {
+ public Foo2(String val, Foo1 ref) {
+ }
+ }
+
+ public static class Foo3 {
+ }
+
+ public static class Foo4 {
+ public Foo4(Foo1 ref) {
+ }
+ }
+
+ public static class Prop {
+
+ }
+
+ @Remotable
+ public static interface Ref {
+
+ }
+
+ public static class Foo5 {
+ public Foo5(String val) {
+ }
+ }
+
+ public static class Foo6 {
+ public Foo6(Ref ref) {
+ }
+ }
+
+ public static class Foo7 {
+ public Foo7(@Property(name = "myProp")String prop) {
+ }
+ }
+
+
+ public static class Foo8 {
+ public Foo8(@Reference(name = "myRef")String ref) {
+ }
+ }
+
+ public static class Foo9 {
+ public Foo9(@Reference(name = "myRef")String ref) {
+ }
+ }
+
+ public static class Foo10 {
+
+ public Foo10() {
+ }
+
+ public Foo10(String prop) {
+ }
+
+ public Foo10(@Property(name = "prop1")String prop1, @Property(name = "prop2")String prop2) {
+
+ }
+ }
+
+ public static class Foo11 {
+
+ public Foo11(@Property(name = "prop1")String prop, @Baz String baz) {
+ }
+ }
+
+ public static class Foo12 {
+
+ public Foo12(@Property(name = "prop1")String prop, @Property(name = "prop2")String baz) {
+ }
+ }
+
+ public @interface Baz {
+
+ }
+
+ public static class Foo13 {
+ public Foo13(@Reference String foo) {
+ }
+ }
+
+ public static final class Foo14 {
+ private Foo14() {
+ }
+ }
+
+ public static final class Foo15 {
+ public Foo15(@Reference String param1, @Reference String param2) {
+ }
+ }
+
+ public static final class Foo16 {
+ public Foo16(@Reference String param1,
+ @Property(name = "foo")String param2,
+ @Reference(name = "bar")String param3) {
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java
new file mode 100644
index 0000000000..9863960c1e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java
@@ -0,0 +1,396 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+import java.net.URI;
+import java.util.Collection;
+import java.util.List;
+
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Remotable;
+import org.osoa.sca.annotations.Service;
+
+import org.apache.tuscany.spi.databinding.extension.SimpleTypeMapperExtension;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * Verfies component type information is properly introspected from an unadorned POJO according to the SCA Java Client
+ * and Implementation Model Specification
+ *
+ * @version $Rev$ $Date$
+ */
+public class HeuristicPojoProcessorTestCase extends TestCase {
+
+ private HeuristicPojoProcessor processor =
+ new HeuristicPojoProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl()));
+
+ /**
+ * Verifies a single service interface is computed when only one interface is implemented
+ */
+ public void testSingleInterface() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<SingleInterfaceImpl> ctor = SingleInterfaceImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<SingleInterfaceImpl>(ctor));
+ processor.visitEnd(SingleInterfaceImpl.class, type, null);
+ assertEquals(1, type.getServices().size());
+ assertEquals(PropertyInterface.class,
+ type.getServices().get(PropertyInterface.class.getSimpleName())
+ .getServiceContract().getInterfaceClass());
+ assertTrue(type.getProperties().isEmpty());
+ assertTrue(type.getReferences().isEmpty());
+ }
+
+ /**
+ * Verifies property and reference setters are computed
+ */
+ public void testPropertyReference() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<SingleInterfaceWithPropertyReferenceImpl> ctor =
+ SingleInterfaceWithPropertyReferenceImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<SingleInterfaceWithPropertyReferenceImpl>(ctor));
+ processor.visitEnd(SingleInterfaceWithPropertyReferenceImpl.class, type, null);
+ assertEquals(1, type.getServices().size());
+ assertEquals(Interface1.class,
+ type.getServices().get(Interface1.class.getSimpleName())
+ .getServiceContract().getInterfaceClass());
+ assertEquals(1, type.getProperties().size());
+ assertEquals(ComplexProperty.class, type.getProperties().get("property").getJavaType());
+ assertEquals(1, type.getReferences().size());
+ assertEquals(Ref.class, type.getReferences().get("reference").getServiceContract().getInterfaceClass());
+ }
+
+ /**
+ * Verifies that a property setter is not introspected if an analogous operation is in the service interface
+ */
+ public void testPropertySetterInInterface() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<SingleInterfaceImpl> ctor = SingleInterfaceImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<SingleInterfaceImpl>(ctor));
+ processor.visitEnd(SingleInterfaceImpl.class, type, null);
+ assertEquals(0, type.getProperties().size());
+ }
+
+ /**
+ * Verifies that a reference setter is not introspected if an analogous operation is in the service interface
+ */
+ public void testReferenceSetterInInterface() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<RefInterfaceImpl> ctor = RefInterfaceImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<RefInterfaceImpl>(ctor));
+ processor.visitEnd(RefInterfaceImpl.class, type, null);
+ assertEquals(0, type.getReferences().size());
+ }
+
+ /**
+ * Verifies collection generic types or array types are introspected as references according to spec rules
+ */
+ public void testReferenceCollectionType() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<ReferenceCollectionImpl> ctor = ReferenceCollectionImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<ReferenceCollectionImpl>(ctor));
+ processor.visitEnd(ReferenceCollectionImpl.class, type, null);
+ assertEquals(0, type.getProperties().size());
+ assertEquals(4, type.getReferences().size());
+ }
+
+ /**
+ * Verifies collection generic types or array types are introspected as properties according to spec rules
+ */
+ public void testPropertyCollectionType() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<PropertyCollectionImpl> ctor = PropertyCollectionImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<PropertyCollectionImpl>(ctor));
+ processor.visitEnd(PropertyCollectionImpl.class, type, null);
+ assertEquals(0, type.getReferences().size());
+ assertEquals(4, type.getProperties().size());
+ }
+
+ /**
+ * Verifies references are calculated when the type marked with is @Remotable
+ */
+ public void testRemotableRef() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<RemotableRefImpl> ctor = RemotableRefImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<RemotableRefImpl>(ctor));
+ processor.visitEnd(RemotableRefImpl.class, type, null);
+ assertEquals(2, type.getReferences().size());
+ assertEquals(0, type.getProperties().size());
+ }
+
+ public void testParentInterface() throws ProcessingException, NoSuchMethodException {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Child> ctor = Child.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<Child>(ctor));
+ processor.visitEnd(Child.class, type, null);
+ assertTrue(type.getServices().containsKey(Interface1.class.getSimpleName()));
+ }
+
+ /**
+ * Verifies a service inteface is calculated when only props and refs are given
+ */
+ public void testExcludedPropertyAndReference() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ JavaMappedReference ref = new JavaMappedReference();
+ ref.setUri(URI.create("#reference"));
+ type.add(ref);
+ JavaMappedReference ref2 = new JavaMappedReference();
+ ref2.setUri(URI.create("#reference2"));
+ type.add(ref2);
+ JavaMappedProperty<?> prop1 = new JavaMappedProperty();
+ prop1.setName("string1");
+ type.add(prop1);
+ JavaMappedProperty<?> prop2 = new JavaMappedProperty();
+ prop2.setName("string2");
+ type.add(prop2);
+ processor.visitEnd(MockService.class, type, null);
+ assertEquals(1, type.getServices().size());
+ }
+
+ public void testProtectedRemotableRefField() throws ProcessingException, NoSuchMethodException {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<ProtectedRemotableRefFieldImpl> ctor = ProtectedRemotableRefFieldImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<ProtectedRemotableRefFieldImpl>(ctor));
+ processor.visitEnd(ProtectedRemotableRefFieldImpl.class, type, null);
+ assertNotNull(type.getReferences().get("otherRef"));
+ }
+
+ public void testProtectedRemotableRefMethod() throws ProcessingException, NoSuchMethodException {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<ProtectedRemotableRefMethodImpl> ctor = ProtectedRemotableRefMethodImpl.class.getConstructor();
+ type.setConstructorDefinition(new ConstructorDefinition<ProtectedRemotableRefMethodImpl>(ctor));
+ processor.visitEnd(ProtectedRemotableRefMethodImpl.class, type, null);
+ assertNotNull(type.getReferences().get("otherRef"));
+ }
+
+ public void testSetDataTypes() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<PropertyIntTypeOnConstructor> ctor = PropertyIntTypeOnConstructor.class.getConstructor(int.class);
+ type.setConstructorDefinition(new ConstructorDefinition<PropertyIntTypeOnConstructor>(ctor));
+ processor.visitEnd(ProtectedRemotableRefMethodImpl.class, type, null);
+ org.apache.tuscany.spi.model.Property<?> foo = type.getProperties().get("foo");
+ assertEquals(int.class, foo.getJavaType());
+ assertEquals(SimpleTypeMapperExtension.XSD_INT, foo.getXmlType());
+ }
+
+ private static class PropertyIntTypeOnConstructor {
+ private int foo;
+
+ public PropertyIntTypeOnConstructor(@Property(name = "foo")int foo) {
+ this.foo = foo;
+ }
+
+ public int getFoo() {
+ return foo;
+ }
+ }
+
+ private interface PropertyInterface {
+ void setString1(String val);
+ }
+
+ private interface Interface1 {
+ }
+
+ private static class Parent implements Interface1 {
+
+ }
+
+ private static class Child extends Parent {
+ public Child() {
+ }
+
+ }
+
+ private static class SingleInterfaceImpl implements PropertyInterface {
+ public SingleInterfaceImpl() {
+ }
+
+ public void setString1(String val) {
+ }
+
+ }
+
+ private interface HeuristicServiceInterface {
+ void fooOperation(String ref);
+
+ void setInvalid1(); // No parameter
+
+ void setInvalid2(String str, int i); // More than one parameter
+
+ String setInvalid3(String str); // return should be void
+ }
+
+ public static class MockService implements PropertyInterface, RefInterface, HeuristicServiceInterface {
+
+ @Property
+ public void setString1(String val) {
+ }
+
+ @Property
+ public void setString2(String val) {
+ }
+
+ @Reference
+ public void setReference(Ref ref) {
+ }
+
+ @Reference
+ public void setReference2(Ref ref) {
+ }
+
+ public void fooOperation(String ref) {
+
+ }
+
+ public void setInvalid1() {
+ }
+
+ public void setInvalid2(String str, int i) {
+ }
+
+ public String setInvalid3(String str) {
+ return null;
+ }
+
+ }
+
+ @Service
+ private interface Ref {
+ }
+
+ private class ComplexProperty {
+ }
+
+ private interface RefInterface {
+ void setReference(Ref ref);
+ }
+
+ private static class RefInterfaceImpl implements RefInterface {
+ public RefInterfaceImpl() {
+ }
+
+ public void setReference(Ref ref) {
+ }
+ }
+
+ private static class SingleInterfaceWithPropertyReferenceImpl implements Interface1 {
+ public SingleInterfaceWithPropertyReferenceImpl() {
+ }
+
+ public void setReference(Ref ref) {
+ }
+
+ public void setProperty(ComplexProperty prop) {
+ }
+ }
+
+ private static class ReferenceCollectionImpl implements Interface1 {
+ public ReferenceCollectionImpl() {
+ }
+
+ public void setCollectionReference(Collection<Ref> ref) {
+ }
+
+ public void setNonGenericCollectionReference(Collection ref) {
+ }
+
+ public void setListReference(List<Ref> ref) {
+ }
+
+ public void setArrayReference(Ref[] ref) {
+ }
+ }
+
+ private static class PropertyCollectionImpl implements Interface1 {
+ public PropertyCollectionImpl() {
+ }
+
+ public void setCollectionProperty(Collection<ComplexProperty> prop) {
+ }
+
+ public void setCollectionProperty2(Collection<String> prop) {
+ }
+
+ public void setArrayProperty(ComplexProperty[] prop) {
+ }
+
+ public void setArrayProperty2(String[] prop) {
+ }
+ }
+
+ @Remotable
+ private interface RemotableRef {
+ }
+
+ private static class RemotableRefImpl implements Interface1 {
+ protected RemotableRef otherRef;
+
+ public RemotableRefImpl() {
+ }
+
+ public void setRef(RemotableRef ref) {
+
+ }
+ }
+
+ private static class ProtectedRemotableRefFieldImpl implements Interface1 {
+ protected RemotableRef otherRef;
+
+ public ProtectedRemotableRefFieldImpl() {
+ }
+
+ public ProtectedRemotableRefFieldImpl(RemotableRef otherRef) {
+ this.otherRef = otherRef;
+ }
+
+ }
+
+ private static class ProtectedRemotableRefMethodImpl implements Interface1 {
+ public ProtectedRemotableRefMethodImpl() {
+ }
+
+ protected void setOtherRef(RemotableRef otherRef) {
+ }
+
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java
new file mode 100644
index 0000000000..ed2fea8c41
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.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.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * Verifies constructors that have extensible annotation types, i.e. that have parameters marked by annotations which
+ * are themselves processed by some other implementation processor
+ *
+ * @version $Rev$ $Date$
+ */
+public class HeutisticExtensibleConstructorTestCase extends TestCase {
+
+ private HeuristicPojoProcessor processor =
+ new HeuristicPojoProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl()));
+
+ /**
+ * Verifies heuristic processing can be called priot to an extension annotation processors being called.
+ */
+ public void testBarAnnotationProcessedFirst() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+ ConstructorDefinition<Foo> definition = new ConstructorDefinition<Foo>(ctor);
+ type.setConstructorDefinition(definition);
+ JavaMappedProperty property = new JavaMappedProperty();
+ property.setName("myBar");
+ definition.getInjectionNames().add("myBar");
+ type.getProperties().put("myBar", property);
+ processor.visitEnd(Foo.class, type, null);
+ assertEquals(2, type.getProperties().size());
+ }
+
+ /**
+ * Verifies heuristic processing can be called before an extension annotation processors is called.
+ * <p/>
+ * For example, given:
+ * <pre> Foo(@Bar String prop, @org.osoa.sca.annotations.Property(name = "foo") String prop2)</pre>
+ * <p/>
+ * Heuristic evaluation of @Property can occur prior to another implementation processor evaluating @Bar
+ *
+ * @throws Exception
+ */
+ public void testBarAnnotationProcessedLast() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitEnd(Foo.class, type, null);
+
+ // now simulate process the bar impl
+ ConstructorDefinition<?> definition = type.getConstructorDefinition();
+ List<String> injectionNames = definition.getInjectionNames();
+ injectionNames.remove(0);
+ injectionNames.add(0, "mybar");
+ type.getProperties().put("mybar", new JavaMappedProperty<String>());
+
+ assertEquals(2, type.getProperties().size());
+ assertEquals("foo", definition.getInjectionNames().get(1));
+ }
+
+ /**
+ * Verifies heuristic processing can be called before an extension annotation processors is called with the
+ * extension parameter in a middle position. Specifically, verifies that the heuristic processor updates injection
+ * names and preserves their ordering.
+ */
+ public void testBarAnnotationProcessedFirstInMiddle() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Foo2> ctor = Foo2.class.getConstructor(String.class, String.class, String.class);
+ ConstructorDefinition<Foo2> definition = new ConstructorDefinition<Foo2>(ctor);
+ type.setConstructorDefinition(definition);
+ // insert placeholder for first param, which would be done by a processor
+ definition.getInjectionNames().add("");
+ JavaMappedProperty property = new JavaMappedProperty();
+ property.setName("myBar");
+ definition.getInjectionNames().add("myBar");
+ type.getProperties().put("myBar", property);
+ processor.visitEnd(Foo2.class, type, null);
+ assertEquals("baz", definition.getInjectionNames().get(0));
+ assertEquals(2, type.getProperties().size());
+ assertEquals(1, type.getReferences().size());
+ }
+
+ public @interface Bar {
+
+ }
+
+ public static class Foo {
+ public Foo(@Bar String prop, @org.osoa.sca.annotations.Property(name = "foo") String prop2) {
+ }
+ }
+
+ public static class Foo2 {
+ public Foo2(@org.osoa.sca.annotations.Reference(name = "baz") String prop1,
+ @Bar String prop2,
+ @org.osoa.sca.annotations.Property(name = "foo") String prop3) {
+ }
+ }
+
+
+}
+
+
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceTestCase.java
new file mode 100644
index 0000000000..9f340ccd11
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceTestCase.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.core.implementation.processor;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.Conversational;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Remotable;
+
+import org.apache.tuscany.spi.databinding.extension.SimpleTypeMapperExtension;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ImplementationProcessorServiceTestCase extends TestCase {
+
+ private ImplementationProcessorService implService =
+ new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl());
+
+ public void testCreateConversationalService() throws Exception {
+ JavaMappedService service = implService.createService(Foo.class);
+ assertTrue(Foo.class.equals(service.getServiceContract().getInterfaceClass()));
+ assertTrue(service.isRemotable());
+ assertTrue(service.getServiceContract().isConversational());
+ ServiceContract serviceContract = service.getServiceContract();
+ assertTrue(Bar.class.equals(serviceContract.getCallbackClass()));
+ assertTrue("ImplementationProcessorServiceTestCase$Bar".equals(serviceContract.getCallbackName()));
+ }
+
+ public void testCreateDefaultService() throws Exception {
+ JavaMappedService service = implService.createService(Baz.class);
+ assertTrue(Baz.class.equals(service.getServiceContract().getInterfaceClass()));
+ assertTrue(!service.isRemotable());
+ assertFalse(service.getServiceContract().isConversational());
+ }
+
+ public void testProcessParamProperty() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<PropertyClass> ctor = PropertyClass.class.getConstructor(int.class);
+ Annotation[] paramAnnotations = ctor.getParameterAnnotations()[0];
+ List<String> injectionNames = new ArrayList<String>();
+ String[] names = new String[]{"foo"};
+ implService.processParam(int.class,
+ ctor.getGenericParameterTypes()[0],
+ paramAnnotations,
+ names,
+ 0,
+ type,
+ injectionNames);
+ org.apache.tuscany.spi.model.Property<?> property = type.getProperties().get("foo");
+ assertEquals(int.class, property.getJavaType());
+ assertEquals(SimpleTypeMapperExtension.XSD_INT, property.getXmlType());
+ }
+
+
+ @Conversational
+ @Callback(Bar.class)
+ @Remotable
+ public interface Foo {
+
+ }
+
+ public interface Bar {
+
+ }
+
+ public interface Baz {
+
+ }
+
+ public static class PropertyClass {
+ private int foo;
+
+ public PropertyClass(@Property(name = "foo")int foo) {
+ this.foo = foo;
+ }
+
+ public int getFoo() {
+ return foo;
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceUniqueTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceUniqueTestCase.java
new file mode 100644
index 0000000000..da45ed2d46
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceUniqueTestCase.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ImplementationProcessorServiceUniqueTestCase extends TestCase {
+
+ private ImplementationProcessorService service =
+ new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl());
+
+ public void testUniquess1() throws Exception {
+ Class[] classes = new Class[2];
+ classes[0] = String.class;
+ classes[1] = Integer.class;
+ assertTrue(service.areUnique(classes));
+ }
+
+ public void testUniquess2() throws Exception {
+ Class[] classes = new Class[2];
+ classes[0] = String.class;
+ classes[1] = String.class;
+ assertFalse(service.areUnique(classes));
+ }
+
+ public void testUniquess3() throws Exception {
+ Class[] classes = new Class[1];
+ classes[0] = String.class;
+ assertTrue(service.areUnique(classes));
+ }
+
+ public void testUniquess4() throws Exception {
+ Class[] classes = new Class[3];
+ classes[0] = String.class;
+ classes[1] = Integer.class;
+ classes[2] = String.class;
+ assertFalse(service.areUnique(classes));
+ }
+
+ public void testUniquess5() throws Exception {
+ Class[] classes = new Class[0];
+ assertTrue(service.areUnique(classes));
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/InitProcessorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/InitProcessorTestCase.java
new file mode 100644
index 0000000000..ee3a0d83d1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/InitProcessorTestCase.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.core.implementation.processor;
+
+import java.lang.reflect.Method;
+
+import org.osoa.sca.annotations.Init;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InitProcessorTestCase extends TestCase {
+
+ public void testInit() throws Exception {
+ InitProcessor processor = new InitProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Method method = InitProcessorTestCase.Foo.class.getMethod("init");
+ processor.visitMethod(method, type, null);
+ assertNotNull(type.getInitMethod());
+ assertEquals(0, type.getInitLevel());
+ }
+
+ public void testBadInit() throws Exception {
+ InitProcessor processor = new InitProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Method method = InitProcessorTestCase.Bar.class.getMethod("badInit", String.class);
+ try {
+ processor.visitMethod(method, type, null);
+ fail();
+ } catch (IllegalInitException e) {
+ // expected
+ }
+ }
+
+ public void testTwoInit() throws Exception {
+ InitProcessor processor = new InitProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Method method = InitProcessorTestCase.Bar.class.getMethod("init");
+ Method method2 = InitProcessorTestCase.Bar.class.getMethod("init2");
+ processor.visitMethod(method, type, null);
+ try {
+ processor.visitMethod(method2, type, null);
+ fail();
+ } catch (DuplicateInitException e) {
+ // expected
+ }
+ }
+
+
+ private class Foo {
+ @Init
+ public void init() {
+ }
+ }
+
+
+ private class Bar {
+ @Init
+ public void init() {
+ }
+
+ @Init
+ public void init2() {
+ }
+
+ @Init
+ public void badInit(String foo) {
+ }
+
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/MonitorProcessorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/MonitorProcessorTestCase.java
new file mode 100644
index 0000000000..c3683399ca
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/MonitorProcessorTestCase.java
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.IllegalPropertyException;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.api.annotation.Monitor;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.injection.SingletonObjectFactory;
+import org.apache.tuscany.host.MonitorFactory;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MonitorProcessorTestCase extends TestCase {
+
+ private MonitorProcessor processor;
+ private MonitorFactory monitorFactory;
+
+ public void testSetter() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Method method = Foo.class.getMethod("setMonitor", Foo.class);
+ EasyMock.expect(monitorFactory.getMonitor(EasyMock.eq(Foo.class))).andReturn(null);
+ EasyMock.replay(monitorFactory);
+ processor.visitMethod(method, type, null);
+ Map<String, JavaMappedProperty<?>> properties = type.getProperties();
+ assertTrue(properties.get("monitor").getDefaultValueFactory() instanceof SingletonObjectFactory);
+ EasyMock.verify(monitorFactory);
+ }
+
+
+ public void testBadSetter() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Method method = BadMonitor.class.getMethod("setMonitor");
+ try {
+ processor.visitMethod(method, type, null);
+ fail();
+ } catch (IllegalPropertyException e) {
+ // expected
+ }
+ }
+
+ public void testField() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Field field = Foo.class.getDeclaredField("bar");
+ EasyMock.expect(monitorFactory.getMonitor(EasyMock.eq(Foo.class))).andReturn(null);
+ EasyMock.replay(monitorFactory);
+ processor.visitField(field, type, null);
+ Map<String, JavaMappedProperty<?>> properties = type.getProperties();
+ assertTrue(properties.get("bar").getDefaultValueFactory() instanceof SingletonObjectFactory);
+ EasyMock.verify(monitorFactory);
+ }
+
+ public void testConstructor() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Bar> ctor = Bar.class.getConstructor(BazMonitor.class);
+ EasyMock.expect(monitorFactory.getMonitor(EasyMock.eq(BazMonitor.class))).andReturn(null);
+ EasyMock.replay(monitorFactory);
+ processor.visitConstructor(ctor, type, null);
+ Map<String, JavaMappedProperty<?>> properties = type.getProperties();
+ assertTrue(
+ properties.get(BazMonitor.class.getName()).getDefaultValueFactory() instanceof SingletonObjectFactory);
+ EasyMock.verify(monitorFactory);
+ }
+
+ /**
+ * Verifies calling the monitor processor to evaluate a constructor can be done after a property parameter is
+ * processed
+ */
+ public void testConstructorAfterProperty() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Bar> ctor = Bar.class.getConstructor(String.class, BazMonitor.class);
+ EasyMock.expect(monitorFactory.getMonitor(EasyMock.eq(BazMonitor.class))).andReturn(null);
+ EasyMock.replay(monitorFactory);
+ ConstructorDefinition<Bar> definition = new ConstructorDefinition<Bar>(ctor);
+ JavaMappedProperty prop = new JavaMappedProperty();
+ definition.getInjectionNames().add("prop");
+ type.setConstructorDefinition(definition);
+ type.getProperties().put("prop", prop);
+ processor.visitConstructor(ctor, type, null);
+ Map<String, JavaMappedProperty<?>> properties = type.getProperties();
+ assertEquals(BazMonitor.class.getName(), definition.getInjectionNames().get(1));
+ assertEquals(2, type.getProperties().size());
+ String name = BazMonitor.class.getName();
+ assertTrue(properties.get(name).getDefaultValueFactory() instanceof SingletonObjectFactory);
+ EasyMock.verify(monitorFactory);
+ }
+
+ /**
+ * Verifies calling the monitor processor to evaluate a constructor can be done before a property parameter is
+ * processed
+ */
+ public void testConstructorBeforeProperty() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ Constructor<Bar> ctor = Bar.class.getConstructor(String.class, BazMonitor.class);
+ EasyMock.expect(monitorFactory.getMonitor(EasyMock.eq(BazMonitor.class))).andReturn(null);
+ EasyMock.replay(monitorFactory);
+ processor.visitConstructor(ctor, type, null);
+ Map<String, JavaMappedProperty<?>> properties = type.getProperties();
+ ConstructorDefinition definition = type.getConstructorDefinition();
+ assertEquals(2, definition.getInjectionNames().size());
+ assertEquals(BazMonitor.class.getName(), definition.getInjectionNames().get(1));
+ String name = BazMonitor.class.getName();
+ assertTrue(properties.get(name).getDefaultValueFactory() instanceof SingletonObjectFactory);
+ EasyMock.verify(monitorFactory);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ monitorFactory = EasyMock.createMock(MonitorFactory.class);
+ JavaInterfaceProcessorRegistryImpl registry = new JavaInterfaceProcessorRegistryImpl();
+ ImplementationProcessorServiceImpl processor = new ImplementationProcessorServiceImpl(registry);
+ this.processor = new MonitorProcessor(monitorFactory, processor);
+ }
+
+ private class Foo {
+
+ @Monitor
+ protected Foo bar;
+
+ @Monitor
+ public void setMonitor(Foo foo) {
+ }
+ }
+
+
+ private class BadMonitor {
+
+ @Monitor
+ public void setMonitor() {
+ }
+ }
+
+ private interface BazMonitor {
+
+ }
+
+ private static class Bar {
+
+ public Bar(@Monitor BazMonitor monitor) {
+ }
+
+ public Bar(String prop, @Monitor BazMonitor monitor) {
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java
new file mode 100644
index 0000000000..b91a33f6f0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java
@@ -0,0 +1,208 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.osoa.sca.annotations.Property;
+
+import org.apache.tuscany.spi.implementation.java.DuplicatePropertyException;
+import org.apache.tuscany.spi.implementation.java.IllegalPropertyException;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PropertyProcessorTestCase extends TestCase {
+
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type;
+ PropertyProcessor processor;
+
+ public void testMethodAnnotation() throws Exception {
+ processor.visitMethod(Foo.class.getMethod("setFoo", String.class), type, null);
+ assertNotNull(type.getProperties().get("foo"));
+ }
+
+ public void testMethodRequired() throws Exception {
+ processor.visitMethod(Foo.class.getMethod("setFooRequired", String.class), type, null);
+ JavaMappedProperty prop = type.getProperties().get("fooRequired");
+ assertNotNull(prop);
+ assertTrue(prop.isRequired());
+ }
+
+ public void testMethodName() throws Exception {
+ processor.visitMethod(Foo.class.getMethod("setBarMethod", String.class), type, null);
+ assertNotNull(type.getProperties().get("bar"));
+ }
+
+ public void testFieldAnnotation() throws Exception {
+ processor.visitField(Foo.class.getDeclaredField("baz"), type, null);
+ assertNotNull(type.getProperties().get("baz"));
+ }
+
+ public void testFieldRequired() throws Exception {
+ processor.visitField(Foo.class.getDeclaredField("bazRequired"), type, null);
+ JavaMappedProperty prop = type.getProperties().get("bazRequired");
+ assertNotNull(prop);
+ assertTrue(prop.isRequired());
+ }
+
+ public void testFieldName() throws Exception {
+ processor.visitField(Foo.class.getDeclaredField("bazField"), type, null);
+ assertNotNull(type.getProperties().get("theBaz"));
+ }
+
+ public void testDuplicateFields() throws Exception {
+ processor.visitField(Bar.class.getDeclaredField("dup"), type, null);
+ try {
+ processor.visitField(Bar.class.getDeclaredField("baz"), type, null);
+ fail();
+ } catch (DuplicatePropertyException e) {
+ // expected
+ }
+ }
+
+ public void testDuplicateMethods() throws Exception {
+ processor.visitMethod(Bar.class.getMethod("dupMethod", String.class), type, null);
+ try {
+ processor.visitMethod(Bar.class.getMethod("dupSomeMethod", String.class), type, null);
+ fail();
+ } catch (DuplicatePropertyException e) {
+ // expected
+ }
+ }
+
+ public void testInvalidProperty() throws Exception {
+ try {
+ processor.visitMethod(Bar.class.getMethod("badMethod"), type, null);
+ fail();
+ } catch (IllegalPropertyException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ type = new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ JavaInterfaceProcessorRegistryImpl registry = new JavaInterfaceProcessorRegistryImpl();
+ processor = new PropertyProcessor(new ImplementationProcessorServiceImpl(registry));
+ }
+
+ private class Foo {
+
+ @Property
+ protected String baz;
+ @Property(required = true)
+ protected String bazRequired;
+ @Property(name = "theBaz")
+ protected String bazField;
+
+ @Property
+ public void setFoo(String string) {
+ }
+
+ @Property(required = true)
+ public void setFooRequired(String string) {
+ }
+
+ @Property(name = "bar")
+ public void setBarMethod(String string) {
+ }
+
+ }
+
+ private class Bar {
+
+ @Property
+ protected String dup;
+
+ @Property(name = "dup")
+ protected String baz;
+
+ @Property
+ public void dupMethod(String s) {
+ }
+
+ @Property(name = "dupMethod")
+ public void dupSomeMethod(String s) {
+ }
+
+ @Property
+ public void badMethod() {
+ }
+
+ }
+
+ private class Multiple {
+ @Property
+ protected List<String> refs1;
+
+ @Property
+ protected String[] refs2;
+
+ @Property
+ public void setRefs3(String[] refs) {
+ }
+
+ @Property
+ public void setRefs4(Collection<String> refs) {
+ }
+
+ }
+
+ public void testMultiplicityCollection() throws Exception {
+ processor.visitField(Multiple.class.getDeclaredField("refs1"), type, null);
+ JavaMappedProperty prop = type.getProperties().get("refs1");
+ assertNotNull(prop);
+ assertSame(String.class, prop.getJavaType());
+ assertTrue(prop.isMany());
+ }
+
+ public void testMultiplicityArray() throws Exception {
+ processor.visitField(Multiple.class.getDeclaredField("refs2"), type, null);
+ JavaMappedProperty prop = type.getProperties().get("refs2");
+ assertNotNull(prop);
+ assertSame(String.class, prop.getJavaType());
+ assertTrue(prop.isMany());
+ }
+
+ public void testMultiplicityArrayMethod() throws Exception {
+ processor.visitMethod(Multiple.class.getMethod("setRefs3", String[].class), type, null);
+ JavaMappedProperty prop = type.getProperties().get("refs3");
+ assertNotNull(prop);
+ assertSame(String.class, prop.getJavaType());
+ assertTrue(prop.isMany());
+ }
+
+ public void testMultiplicityCollectionMethod() throws Exception {
+ processor.visitMethod(Multiple.class.getMethod("setRefs4", Collection.class), type, null);
+ JavaMappedProperty prop = type.getProperties().get("refs4");
+ assertNotNull(prop);
+ assertSame(String.class, prop.getJavaType());
+ assertTrue(prop.isMany());
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessorTestCase.java
new file mode 100644
index 0000000000..7ee40f3eb2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessorTestCase.java
@@ -0,0 +1,232 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.processor;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.Multiplicity;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReferenceProcessorTestCase extends TestCase {
+
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ ReferenceProcessor processor = new ReferenceProcessor(new JavaInterfaceProcessorRegistryImpl());
+
+ public void testMethodAnnotation() throws Exception {
+ processor.visitMethod(ReferenceProcessorTestCase.Foo.class.getMethod("setFoo", Ref.class), type, null);
+ JavaMappedReference reference = type.getReferences().get("foo");
+ assertNotNull(reference);
+ ServiceContract contract = reference.getServiceContract();
+ assertEquals(Ref.class, contract.getInterfaceClass());
+ assertEquals("ReferenceProcessorTestCase$Ref", contract.getInterfaceName());
+ }
+
+ public void testMethodRequired() throws Exception {
+ processor.visitMethod(
+ ReferenceProcessorTestCase.Foo.class.getMethod("setFooRequired", Ref.class),
+ type,
+ null);
+ JavaMappedReference prop = type.getReferences().get("fooRequired");
+ assertNotNull(prop);
+ assertTrue(prop.isRequired());
+ }
+
+ public void testMethodName() throws Exception {
+ processor.visitMethod(
+ ReferenceProcessorTestCase.Foo.class.getMethod("setBarMethod", Ref.class),
+ type,
+ null);
+ assertNotNull(type.getReferences().get("bar"));
+ }
+
+ public void testFieldAnnotation() throws Exception {
+ processor.visitField(ReferenceProcessorTestCase.Foo.class.getDeclaredField("baz"), type, null);
+ JavaMappedReference reference = type.getReferences().get("baz");
+ assertNotNull(reference);
+ ServiceContract contract = reference.getServiceContract();
+ assertEquals(Ref.class, contract.getInterfaceClass());
+ assertEquals("ReferenceProcessorTestCase$Ref", contract.getInterfaceName());
+ }
+
+ public void testFieldRequired() throws Exception {
+ processor.visitField(ReferenceProcessorTestCase.Foo.class.getDeclaredField("bazRequired"), type, null);
+ JavaMappedReference prop = type.getReferences().get("bazRequired");
+ assertNotNull(prop);
+ assertTrue(prop.isRequired());
+ }
+
+ public void testFieldName() throws Exception {
+ processor.visitField(ReferenceProcessorTestCase.Foo.class.getDeclaredField("bazField"), type, null);
+ assertNotNull(type.getReferences().get("theBaz"));
+ }
+
+ public void testDuplicateFields() throws Exception {
+ processor.visitField(ReferenceProcessorTestCase.Bar.class.getDeclaredField("dup"), type, null);
+ try {
+ processor.visitField(ReferenceProcessorTestCase.Bar.class.getDeclaredField("baz"), type, null);
+ fail();
+ } catch (DuplicateReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testDuplicateMethods() throws Exception {
+ processor.visitMethod(ReferenceProcessorTestCase.Bar.class.getMethod("dupMethod", Ref.class), type, null);
+ try {
+ processor.visitMethod(
+ ReferenceProcessorTestCase.Bar.class.getMethod("dupSomeMethod", Ref.class),
+ type,
+ null);
+ fail();
+ } catch (DuplicateReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testInvalidProperty() throws Exception {
+ try {
+ processor.visitMethod(ReferenceProcessorTestCase.Bar.class.getMethod("badMethod"), type, null);
+ fail();
+ } catch (IllegalReferenceException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ type = new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor = new ReferenceProcessor(new JavaInterfaceProcessorRegistryImpl());
+ }
+
+ private interface Ref {
+ }
+
+ private class Foo {
+
+ @Reference
+ protected Ref baz;
+ @Reference(required = true)
+ protected Ref bazRequired;
+ @Reference(name = "theBaz")
+ protected Ref bazField;
+
+ @Reference
+ public void setFoo(Ref ref) {
+ }
+
+ @Reference(required = true)
+ public void setFooRequired(Ref ref) {
+ }
+
+ @Reference(name = "bar")
+ public void setBarMethod(Ref ref) {
+ }
+
+ }
+
+ private class Bar {
+
+ @Reference
+ protected Ref dup;
+
+ @Reference(name = "dup")
+ protected Ref baz;
+
+ @Reference
+ public void dupMethod(Ref s) {
+ }
+
+ @Reference(name = "dupMethod")
+ public void dupSomeMethod(Ref s) {
+ }
+
+ @Reference
+ public void badMethod() {
+ }
+
+ }
+
+ private class Multiple {
+ @Reference(required = true)
+ protected List<Ref> refs1;
+
+ @Reference(required = false)
+ protected Ref[] refs2;
+
+ @Reference(required = true)
+ public void setRefs3(Ref[] refs) {
+ }
+
+ @Reference(required = false)
+ public void setRefs4(Collection<Ref> refs) {
+ }
+
+ }
+
+ public void testMultiplicity1ToN() throws Exception {
+ processor.visitField(Multiple.class.getDeclaredField("refs1"), type, null);
+ JavaMappedReference prop = type.getReferences().get("refs1");
+ assertNotNull(prop);
+ assertSame(Ref.class, prop.getServiceContract().getInterfaceClass());
+ assertEquals(Multiplicity.ONE_N, prop.getMultiplicity());
+ assertTrue(prop.isRequired());
+ }
+
+ public void testMultiplicityTo0ToN() throws Exception {
+ processor.visitField(Multiple.class.getDeclaredField("refs2"), type, null);
+ JavaMappedReference prop = type.getReferences().get("refs2");
+ assertNotNull(prop);
+ assertSame(Ref.class, prop.getServiceContract().getInterfaceClass());
+ assertEquals(Multiplicity.ZERO_N, prop.getMultiplicity());
+ assertFalse(prop.isRequired());
+ }
+
+ public void testMultiplicity1ToNMethod() throws Exception {
+ processor.visitMethod(Multiple.class.getMethod("setRefs3", Ref[].class), type, null);
+ JavaMappedReference prop = type.getReferences().get("refs3");
+ assertNotNull(prop);
+ assertSame(Ref.class, prop.getServiceContract().getInterfaceClass());
+ assertEquals(Multiplicity.ONE_N, prop.getMultiplicity());
+ assertTrue(prop.isRequired());
+ }
+
+ public void testMultiplicity0ToNMethod() throws Exception {
+ processor.visitMethod(Multiple.class.getMethod("setRefs4", Collection.class), type, null);
+ JavaMappedReference prop = type.getReferences().get("refs4");
+ assertNotNull(prop);
+ assertSame(Ref.class, prop.getServiceContract().getInterfaceClass());
+ assertEquals(Multiplicity.ZERO_N, prop.getMultiplicity());
+ assertFalse(prop.isRequired());
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ResourceProcessorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ResourceProcessorTestCase.java
new file mode 100644
index 0000000000..25c1a14be6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ResourceProcessorTestCase.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.core.implementation.processor;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.Resource;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ResourceProcessorTestCase extends TestCase {
+
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type;
+ ResourceProcessor processor = new ResourceProcessor();
+
+ public void testVisitField() throws Exception {
+ Field field = Foo.class.getDeclaredField("bar");
+ processor.visitField(field, type, null);
+ Resource resource = type.getResources().get("bar");
+ assertFalse(resource.isOptional());
+ assertNull(resource.getMappedName());
+ assertEquals(field.getType(), resource.getType());
+ }
+
+ public void testVisitMethod() throws Exception {
+ Method method = Foo.class.getMethod("setBar", Bar.class);
+ processor.visitMethod(method, type, null);
+ Resource resource = type.getResources().get("bar");
+ assertFalse(resource.isOptional());
+ assertNull(resource.getMappedName());
+ assertEquals(method.getParameterTypes()[0], resource.getType());
+ }
+
+ public void testVisitNamedMethod() throws Exception {
+ Method method = Foo.class.getMethod("setBar2", Bar.class);
+ processor.visitMethod(method, type, null);
+ Resource resource = type.getResources().get("someName");
+ assertFalse(resource.isOptional());
+ assertEquals("mapped", resource.getMappedName());
+ }
+
+ public void testVisitBadMethod() throws Exception {
+ Method method = Foo.class.getMethod("setBad");
+ try {
+ processor.visitMethod(method, type, null);
+ fail();
+ } catch (IllegalResourceException e) {
+ // expected
+ }
+ }
+
+ public void testDuplicateResources() throws Exception {
+ Field field = Foo.class.getDeclaredField("bar");
+ processor.visitField(field, type, null);
+ try {
+ processor.visitField(field, type, null);
+ fail();
+ } catch (DuplicateResourceException e) {
+ //expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ type = new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ }
+
+ private class Foo {
+
+ @org.apache.tuscany.api.annotation.Resource
+ protected Bar bar;
+
+ @org.apache.tuscany.api.annotation.Resource(optional = true)
+ protected Bar barNotRequired;
+
+ @org.apache.tuscany.api.annotation.Resource
+ public void setBar(Bar bar) {
+ }
+
+ @org.apache.tuscany.api.annotation.Resource(name = "someName", mappedName = "mapped")
+ public void setBar2(Bar bar) {
+ }
+
+ @org.apache.tuscany.api.annotation.Resource
+ public void setBad() {
+ }
+
+ }
+
+ private interface Bar {
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ScopeProcessorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ScopeProcessorTestCase.java
new file mode 100644
index 0000000000..f8fa73b0f5
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ScopeProcessorTestCase.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.core.implementation.processor;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+import org.apache.tuscany.spi.model.Scope;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ScopeProcessorTestCase extends TestCase {
+
+ Component parent;
+
+ public void testCompositeScope() throws ProcessingException {
+ ScopeProcessor processor = new ScopeProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+
+ processor.visitClass(Composite.class, type, null);
+ assertEquals(Scope.COMPOSITE, type.getImplementationScope());
+ }
+
+ public void testSessionScope() throws ProcessingException {
+ ScopeProcessor processor = new ScopeProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(Session.class, type, null);
+ assertEquals(Scope.SESSION, type.getImplementationScope());
+ }
+
+ public void testConversationalScope() throws ProcessingException {
+ ScopeProcessor processor = new ScopeProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(Conversation.class, type, null);
+ assertEquals(Scope.CONVERSATION, type.getImplementationScope());
+ }
+
+ public void testRequestScope() throws ProcessingException {
+ ScopeProcessor processor = new ScopeProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(Request.class, type, null);
+ assertEquals(Scope.REQUEST, type.getImplementationScope());
+ }
+
+ public void testSystemScope() throws ProcessingException {
+ ScopeProcessor processor = new ScopeProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(System.class, type, null);
+ assertEquals(Scope.SYSTEM, type.getImplementationScope());
+ }
+
+ public void testStatelessScope() throws ProcessingException {
+ ScopeProcessor processor = new ScopeProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(Stateless.class, type, null);
+ assertEquals(Scope.STATELESS, type.getImplementationScope());
+ }
+
+ public void testNoScope() throws ProcessingException {
+ ScopeProcessor processor = new ScopeProcessor();
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(None.class, type, null);
+ assertEquals(Scope.STATELESS, type.getImplementationScope());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ parent = EasyMock.createNiceMock(Component.class);
+ }
+
+ @org.osoa.sca.annotations.Scope("COMPOSITE")
+ private class Composite {
+ }
+
+ @org.osoa.sca.annotations.Scope("SESSION")
+ private class Session {
+ }
+
+ @org.osoa.sca.annotations.Scope("CONVERSATION")
+ private class Conversation {
+ }
+
+ @org.osoa.sca.annotations.Scope("REQUEST")
+ private class Request {
+ }
+
+ @org.osoa.sca.annotations.Scope("SYSTEM")
+ private class System {
+ }
+
+ @org.osoa.sca.annotations.Scope("STATELESS")
+ private class Stateless {
+ }
+
+ private class None {
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceCallbackTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceCallbackTestCase.java
new file mode 100644
index 0000000000..b198bd730b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceCallbackTestCase.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.core.implementation.processor;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.Service;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.idl.java.IllegalCallbackException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ServiceCallbackTestCase extends TestCase {
+
+ ServiceProcessor processor =
+ new ServiceProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl()));
+
+ public void testMethodCallbackInterface() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(FooImpl.class, type, null);
+ JavaMappedService service = type.getServices().get(Foo.class.getSimpleName());
+ assertNotNull(service);
+ Method method = FooImpl.class.getMethod("setCallback", FooCallback.class);
+ processor.visitMethod(method, type, null);
+ assertEquals(method, service.getCallbackMember());
+ }
+
+ public void testFieldCallbackInterface() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(FooImpl.class, type, null);
+ JavaMappedService service = type.getServices().get(Foo.class.getSimpleName());
+ assertNotNull(service);
+ Field field = FooImpl.class.getDeclaredField("callback");
+ processor.visitField(field, type, null);
+ assertEquals(field, service.getCallbackMember());
+ }
+
+ public void testMethodDoesNotMatchCallback() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(BadBarImpl.class, type, null);
+ Method method = BadBarImpl.class.getMethod("setWrongInterfaceCallback", String.class);
+ try {
+ processor.visitMethod(method, type, null);
+ fail();
+ } catch (IllegalCallbackReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testNoParamCallback() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(BadBarImpl.class, type, null);
+ Method method = BadBarImpl.class.getMethod("setNoParamCallback");
+ try {
+ processor.visitMethod(method, type, null);
+ fail();
+ } catch (IllegalCallbackReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testFieldDoesNotMatchCallback() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitClass(BadBarImpl.class, type, null);
+ Field field = BadBarImpl.class.getDeclaredField("wrongInterfaceCallback");
+ try {
+ processor.visitField(field, type, null);
+ fail();
+ } catch (IllegalCallbackReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testBadCallbackInterfaceAnnotation() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ try {
+ processor.visitClass(BadFooImpl.class, type, null);
+ fail();
+ } catch (ProcessingException e) {
+ // expected
+ assertTrue(e.getCause() instanceof IllegalCallbackException);
+ }
+ }
+
+ @Callback(FooCallback.class)
+ private interface Foo {
+
+ }
+
+ private interface FooCallback {
+
+ }
+
+ @Service(Foo.class)
+ private static class FooImpl implements Foo {
+
+ @Callback
+ protected FooCallback callback;
+
+ @Callback
+ public void setCallback(FooCallback cb) {
+
+ }
+ }
+
+ private static class BadBarImpl implements Foo {
+ @Callback
+ protected String wrongInterfaceCallback;
+
+ @Callback
+ public void setWrongInterfaceCallback(String cb) {
+
+ }
+
+ @Callback
+ public void setNoParamCallback() {
+
+ }
+
+ }
+
+ @Callback
+ private interface BadFoo {
+
+ }
+
+ @Service(BadFoo.class)
+ private static class BadFooImpl implements BadFoo {
+
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceProcessorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceProcessorTestCase.java
new file mode 100644
index 0000000000..3d3ce498c9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceProcessorTestCase.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.implementation.processor;
+
+import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.Remotable;
+import org.osoa.sca.annotations.Service;
+
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ServiceProcessorTestCase extends TestCase {
+ private ServiceProcessor processor;
+ private PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type;
+
+ public void testMultipleInterfaces() throws Exception {
+ processor.visitClass(FooMultiple.class, type, null);
+ assertEquals(2, type.getServices().size());
+ JavaMappedService service = type.getServices().get(Baz.class.getSimpleName());
+ ServiceContract contract = service.getServiceContract();
+ assertEquals(Baz.class, contract.getInterfaceClass());
+ assertEquals(Bar.class, contract.getCallbackClass());
+ assertEquals("ServiceProcessorTestCase$Bar", contract.getCallbackName());
+ assertNotNull(type.getServices().get(Bar.class.getSimpleName()));
+ }
+
+ public void testSingleInterfaces() throws Exception {
+ processor.visitClass(FooSingle.class, type, null);
+ assertEquals(1, type.getServices().size());
+ assertNotNull(type.getServices().get(Baz.class.getSimpleName()));
+ }
+
+ public void testMultipleNoService() throws Exception {
+ processor.visitClass(FooMultipleNoService.class, type, null);
+ assertEquals(0, type.getServices().size());
+ }
+
+ /**
+ * Verifies a service with a callback annotation is recognized
+ */
+ public void testMultipleWithCallbackAnnotation() throws Exception {
+ processor.visitClass(FooMultipleWithCalback.class, type, null);
+ assertEquals(1, type.getServices().size());
+ }
+
+ public void testRemotableNoService() throws Exception {
+ processor.visitClass(FooRemotableNoService.class, type, null);
+ assertEquals(1, type.getServices().size());
+ JavaMappedService service = type.getServices().get(BazRemotable.class.getSimpleName());
+ ServiceContract contract = service.getServiceContract();
+ assertEquals(BazRemotable.class, contract.getInterfaceClass());
+ }
+
+ public void testNonInterface() throws Exception {
+ try {
+ processor.visitClass(BadImpl.class, type, null);
+ fail();
+ } catch (InvalidServiceType e) {
+ //expected
+ }
+ }
+
+ public void testNoInterfaces() throws Exception {
+ try {
+ processor.visitClass(BadDefinition.class, type, null);
+ fail();
+ } catch (IllegalServiceDefinitionException e) {
+ //expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ JavaInterfaceProcessorRegistryImpl registry = new JavaInterfaceProcessorRegistryImpl();
+ processor = new ServiceProcessor(new ImplementationProcessorServiceImpl(registry));
+ type = new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ }
+
+ @Callback(Bar.class)
+ private interface Baz {
+ }
+
+ private interface Bar {
+ }
+
+ private interface Bar2 {
+ }
+
+ @Remotable
+ private interface BazRemotable {
+ }
+
+ @Service(interfaces = {Baz.class, Bar.class})
+ private class FooMultiple implements Baz, Bar {
+
+ }
+
+ @Service(Baz.class)
+ private class FooSingle implements Baz, Bar {
+
+ }
+
+ private class FooMultipleNoService implements Bar, Bar2 {
+
+ }
+
+ private class FooMultipleWithCalback implements Baz, Bar {
+
+ }
+
+ private class FooRemotableNoService implements BazRemotable, Bar {
+
+ }
+
+ @Service(FooSingle.class)
+ private class BadImpl extends FooSingle {
+
+ }
+
+
+ @Service()
+ private class BadDefinition extends FooSingle {
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/builder/SystemComponentBuilderResourceTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/builder/SystemComponentBuilderResourceTestCase.java
new file mode 100644
index 0000000000..23a131c52c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/builder/SystemComponentBuilderResourceTestCase.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.system.builder;
+
+import java.lang.reflect.Field;
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.host.ResourceHost;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.Resource;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.system.model.SystemImplementation;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SystemComponentBuilderResourceTestCase extends TestCase {
+
+ @SuppressWarnings("unchecked")
+ public void testResourceInjection() throws Exception {
+ ScopeContainer container = EasyMock.createNiceMock(ScopeContainer.class);
+ DeploymentContext ctx = EasyMock.createNiceMock(DeploymentContext.class);
+ URI groupId = URI.create("composite");
+ EasyMock.expect(ctx.getGroupId()).andStubReturn(groupId);
+ EasyMock.replay(ctx);
+ ScopeRegistry registry = EasyMock.createMock(ScopeRegistry.class);
+ EasyMock.expect(registry.getScopeContainer(Scope.STATELESS)).andReturn(container);
+ EasyMock.replay(registry);
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(EasyMock.eq(String.class))).andReturn("result");
+ EasyMock.replay(host);
+ SystemComponentBuilder builder = new SystemComponentBuilder();
+ builder.setScopeRegistry(registry);
+ builder.setHost(host);
+ ConstructorDefinition<Foo> ctorDef = new ConstructorDefinition<SystemComponentBuilderResourceTestCase.Foo>(
+ SystemComponentBuilderResourceTestCase.Foo.class.getConstructor());
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ Field member = Foo.class.getDeclaredField("resource");
+ Resource<String> resource = new Resource<String>("resource", String.class, member);
+ type.add(resource);
+ type.setImplementationScope(Scope.STATELESS);
+ type.setConstructorDefinition(ctorDef);
+ SystemImplementation impl = new SystemImplementation();
+ impl.setImplementationClass(SystemComponentBuilderResourceTestCase.Foo.class);
+ impl.setComponentType(type);
+ ComponentDefinition<SystemImplementation> definition =
+ new ComponentDefinition<SystemImplementation>(URI.create("foo"), impl);
+
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.getTargetInstance()).andReturn("result");
+ EasyMock.replay(wire);
+
+ AtomicComponent component = builder.build(definition, ctx);
+ SystemComponentBuilderResourceTestCase.Foo foo =
+ (SystemComponentBuilderResourceTestCase.Foo) component.createInstance();
+ assertEquals("result", foo.resource);
+ }
+
+ private static class Foo {
+
+ protected String resource;
+
+ public Foo() {
+ }
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/builder/SystemPhysicalComponentBuilderTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/builder/SystemPhysicalComponentBuilderTestCase.java
new file mode 100644
index 0000000000..5125b12db8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/builder/SystemPhysicalComponentBuilderTestCase.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.core.implementation.system.builder;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+import org.apache.tuscany.core.component.instancefactory.IFProviderBuilderRegistry;
+import org.apache.tuscany.core.component.InstanceFactoryProvider;
+import org.apache.tuscany.core.implementation.system.component.SystemComponent;
+import org.apache.tuscany.core.implementation.system.model.SystemPhysicalComponentDefinition;
+import org.apache.tuscany.spi.builder.physical.PhysicalComponentBuilderRegistry;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.physical.InstanceFactoryProviderDefinition;
+import org.apache.tuscany.spi.services.classloading.ClassLoaderRegistry;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SystemPhysicalComponentBuilderTestCase<T> extends TestCase {
+ private PhysicalComponentBuilderRegistry builderRegistry;
+ private ScopeRegistry scopeRegistry;
+ private IFProviderBuilderRegistry providerBuilders;
+ private InstanceFactoryProviderDefinition<T> providerDefinition;
+ private InstanceFactoryProvider<T> instanceFactoryProvider;
+ private SystemPhysicalComponentBuilder<T> builder;
+ private SystemPhysicalComponentDefinition<T> definition;
+ private URI componentId;
+ private URI groupId;
+ private ClassLoaderRegistry classLoaderRegistry;
+ private ClassLoader classLoader;
+
+ public void testBuildSimplePOJO() throws Exception {
+ SystemComponent<T> component = builder.build(definition);
+ assertEquals(componentId, component.getUri());
+ assertEquals(-1, component.getInitLevel());
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+ groupId = URI.create("sca://./composite");
+ componentId = URI.create("sca://./component");
+
+ builderRegistry = EasyMock.createMock(PhysicalComponentBuilderRegistry.class);
+ scopeRegistry = EasyMock.createMock(ScopeRegistry.class);
+
+ classLoader = getClass().getClassLoader();
+ classLoaderRegistry = EasyMock.createMock(ClassLoaderRegistry.class);
+ EasyMock.expect(classLoaderRegistry.getClassLoader(groupId)).andStubReturn(classLoader);
+ EasyMock.replay(classLoaderRegistry);
+
+ providerBuilders = EasyMock.createMock(IFProviderBuilderRegistry.class);
+ providerDefinition = new InstanceFactoryProviderDefinition();
+ instanceFactoryProvider = EasyMock.createMock(InstanceFactoryProvider.class);
+ EasyMock.expect(providerBuilders.build(providerDefinition, classLoader)).andStubReturn(instanceFactoryProvider);
+ EasyMock.replay(providerBuilders);
+
+ builder = new SystemPhysicalComponentBuilder<T>(builderRegistry,
+ null,
+ scopeRegistry,
+ providerBuilders,
+ classLoaderRegistry);
+
+ definition = new SystemPhysicalComponentDefinition<T>();
+ definition.setGroupId(groupId);
+ definition.setComponentId(componentId);
+ definition.setClassLoaderId(groupId);
+ definition.setScope(Scope.COMPOSITE);
+ definition.setInitLevel(-1);
+ definition.setInstanceFactoryProviderDefinition(providerDefinition);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentTestCase.java
new file mode 100644
index 0000000000..f475d2b3e7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentTestCase.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.implementation.system.component;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.injection.EventInvoker;
+import org.apache.tuscany.core.injection.MethodEventInvoker;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.injection.SingletonObjectFactory;
+import org.easymock.EasyMock;
+
+/**
+ * Verifies a system atomic component can be started and initialized
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class SystemAtomicComponentTestCase extends TestCase {
+
+ private EventInvoker<Object> initInvoker;
+ private EventInvoker<Object> destroyInvoker;
+ private URI groupId;
+
+ public void testDestroy() throws Exception {
+ PojoObjectFactory<Foo> factory = new PojoObjectFactory<Foo>(Foo.class.getConstructor((Class[]) null));
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setInstanceFactory(factory);
+ configuration.setDestroyInvoker(destroyInvoker);
+ configuration.setName(new URI("foo"));
+ configuration.setGroupId(groupId);
+ SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration);
+ Foo foo = (Foo) component.createInstance();
+ component.destroy(foo);
+ assertTrue(foo.destroyed);
+ }
+
+ public void testReferenceAndPropertyConstructor() throws Exception {
+ PojoObjectFactory<Bar> factory = new PojoObjectFactory<Bar>(Bar.class.getConstructor(String.class, Foo.class));
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setInstanceFactory(factory);
+ configuration.setInitInvoker(initInvoker);
+ configuration.addConstructorParamName("foo");
+ configuration.addConstructorParamType(String.class);
+ configuration.addConstructorParamName("ref");
+ configuration.addConstructorParamType(Foo.class);
+ configuration.setName(new URI("foo"));
+ configuration.setGroupId(groupId);
+ SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration);
+ component.addPropertyFactory("foo", new SingletonObjectFactory<String>("baz"));
+ Foo target = new Foo();
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.getTargetInstance()).andReturn(target);
+ URI uri = URI.create("#ref");
+ EasyMock.expect(wire.getSourceUri()).andReturn(uri).anyTimes();
+ EasyMock.replay(wire);
+ component.attachWire(wire);
+ Bar bar = (Bar) component.createInstance();
+ assertEquals("baz", bar.foo);
+ assertEquals(target, bar.ref);
+ EasyMock.verify(wire);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ initInvoker = new MethodEventInvoker<Object>(Foo.class.getMethod("init"));
+ destroyInvoker = new MethodEventInvoker<Object>(Foo.class.getMethod("destroy"));
+ groupId = URI.create("composite");
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public static class Foo {
+ private boolean initialized;
+ private boolean destroyed;
+
+ public void init() {
+ initialized = true;
+ }
+
+ public void destroy() {
+ destroyed = true;
+ }
+ }
+
+ public static class Bar {
+
+ private String foo;
+ private Foo ref;
+
+ public Bar(String foo, Foo ref) {
+ this.foo = foo;
+ this.ref = ref;
+ }
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentWireInvocationTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentWireInvocationTestCase.java
new file mode 100644
index 0000000000..f4017146fd
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentWireInvocationTestCase.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.core.implementation.system.component;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.scope.CompositeScopeContainer;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.mock.component.Source;
+import org.apache.tuscany.core.mock.component.SourceImpl;
+import org.apache.tuscany.core.mock.component.Target;
+import org.apache.tuscany.core.mock.component.TargetImpl;
+import org.easymock.EasyMock;
+
+/**
+ * Tests reference wires are injected properly into system component instances
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class SystemAtomicComponentWireInvocationTestCase extends TestCase {
+ private URI groupId;
+
+ public void testWireResolution() throws Exception {
+ groupId = URI.create("composite");
+ CompositeScopeContainer scope = new CompositeScopeContainer(null);
+ scope.start();
+ scope.startContext(groupId, groupId);
+ Target target = new TargetImpl();
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.addReferenceSite("setTarget", SourceImpl.class.getMethod("setTarget", Target.class));
+ configuration.setInstanceFactory(new PojoObjectFactory<SourceImpl>(SourceImpl.class.getConstructor()));
+ configuration.setName(new URI("source"));
+ configuration.setGroupId(groupId);
+ AtomicComponent component = new SystemAtomicComponentImpl(configuration);
+ component.setScopeContainer(scope);
+ Wire wire = EasyMock.createMock(Wire.class);
+ URI uri = URI.create("#setTarget");
+ EasyMock.expect(wire.getSourceUri()).andReturn(uri).atLeastOnce();
+ EasyMock.expect(wire.getTargetInstance()).andReturn(target);
+ EasyMock.replay(wire);
+ component.attachWire(wire);
+ component.start();
+ assertSame(((Source) component.getTargetInstance()).getTarget(), target);
+ EasyMock.verify(wire);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemComponentTypeLoaderTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemComponentTypeLoaderTestCase.java
new file mode 100644
index 0000000000..9a3272cf2e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemComponentTypeLoaderTestCase.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.core.implementation.system.loader;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.IntrospectionRegistryImpl;
+import org.apache.tuscany.core.implementation.processor.ConstructorProcessor;
+import org.apache.tuscany.core.implementation.processor.DestroyProcessor;
+import org.apache.tuscany.core.implementation.processor.HeuristicPojoProcessor;
+import org.apache.tuscany.core.implementation.processor.ImplementationProcessorServiceImpl;
+import org.apache.tuscany.core.implementation.processor.InitProcessor;
+import org.apache.tuscany.core.implementation.processor.PropertyProcessor;
+import org.apache.tuscany.core.implementation.processor.ReferenceProcessor;
+import org.apache.tuscany.core.implementation.processor.ScopeProcessor;
+import org.apache.tuscany.core.implementation.processor.ServiceProcessor;
+import org.apache.tuscany.core.implementation.system.model.SystemImplementation;
+import org.apache.tuscany.core.mock.component.BasicInterface;
+import org.apache.tuscany.core.mock.component.BasicInterfaceImpl;
+import org.apache.tuscany.core.monitor.NullMonitorFactory;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SystemComponentTypeLoaderTestCase extends TestCase {
+ private SystemComponentTypeLoader loader;
+
+ public void testIntrospectUnannotatedClass() throws ProcessingException {
+ Component parent = EasyMock.createNiceMock(Component.class);
+ SystemImplementation impl = new SystemImplementation(BasicInterfaceImpl.class);
+ PojoComponentType<?, ?, ?> componentType = loader.loadByIntrospection(impl, null);
+ ServiceDefinition service = componentType.getServices().get(BasicInterface.class.getSimpleName());
+ assertEquals(BasicInterface.class, service.getServiceContract().getInterfaceClass());
+ Property<?> property = componentType.getProperties().get("publicProperty");
+ assertEquals(String.class, property.getJavaType());
+ ReferenceDefinition referenceDefinition = componentType.getReferences().get("protectedReference");
+ assertEquals(BasicInterface.class, referenceDefinition.getServiceContract().getInterfaceClass());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ JavaInterfaceProcessorRegistryImpl interfaceProcessorRegistry = new JavaInterfaceProcessorRegistryImpl();
+ ImplementationProcessorService service =
+ new ImplementationProcessorServiceImpl(interfaceProcessorRegistry);
+ IntrospectionRegistryImpl registry = new IntrospectionRegistryImpl();
+ registry.setMonitor(new NullMonitorFactory().getMonitor(IntrospectionRegistryImpl.Monitor.class));
+ registry.registerProcessor(new ConstructorProcessor(service));
+ registry.registerProcessor(new DestroyProcessor());
+ registry.registerProcessor(new InitProcessor());
+ registry.registerProcessor(new ScopeProcessor());
+ registry.registerProcessor(new PropertyProcessor(service));
+ registry.registerProcessor(new ReferenceProcessor(interfaceProcessorRegistry));
+ registry.registerProcessor(new ServiceProcessor(service));
+ registry.registerProcessor(new HeuristicPojoProcessor(service));
+ loader = new SystemComponentTypeLoader(registry);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemImplementationLoaderTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemImplementationLoaderTestCase.java
new file mode 100644
index 0000000000..3dce59e42a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemImplementationLoaderTestCase.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.core.implementation.system.loader;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.UnrecognizedElementException;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.system.model.SystemImplementation;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SystemImplementationLoaderTestCase extends TestCase {
+
+ public static final QName SYSTEM_IMPLEMENTATION =
+ new QName("http://tuscany.apache.org/xmlns/sca/system/2.0-alpha", "implementation.system");
+
+ public void testLoad() throws Exception {
+ LoaderRegistry registry = EasyMock.createNiceMock(LoaderRegistry.class);
+ EasyMock.replay(registry);
+ DeploymentContext context = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(context.getClassLoader()).andReturn(getClass().getClassLoader());
+ EasyMock.replay(context);
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getName()).andReturn(SYSTEM_IMPLEMENTATION);
+ EasyMock.expect(reader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("class")))
+ .andReturn(getClass().getName());
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(reader);
+ SystemImplementationLoader loader = new SystemImplementationLoader(registry);
+ SystemImplementation impl = loader.load(null, reader, context);
+ assertEquals(getClass(), impl.getImplementationClass());
+ EasyMock.verify(reader);
+ EasyMock.verify(context);
+ }
+
+ public void testUnrecognizedElement() throws Exception {
+ LoaderRegistry registry = EasyMock.createNiceMock(LoaderRegistry.class);
+ EasyMock.replay(registry);
+ DeploymentContext context = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(context.getClassLoader()).andReturn(getClass().getClassLoader());
+ EasyMock.replay(context);
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getName()).andReturn(SYSTEM_IMPLEMENTATION).atLeastOnce();
+ EasyMock.expect(reader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("class")))
+ .andReturn(getClass().getName());
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.getLocation()).andReturn(new MockLocation());
+ EasyMock.replay(reader);
+ SystemImplementationLoader loader = new SystemImplementationLoader(registry);
+ try {
+ loader.load(null, reader, context);
+ fail();
+ } catch (UnrecognizedElementException e) {
+ // expected
+ }
+ }
+
+ private class MockLocation implements 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;
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory2TestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory2TestCase.java
new file mode 100644
index 0000000000..2e25131e12
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactory2TestCase.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.core.injection;
+
+import org.apache.tuscany.spi.wire.ProxyService;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CallbackWireObjectFactory2TestCase extends TestCase {
+
+ @SuppressWarnings({"unchecked"})
+ public void testCreateInstance() throws Exception {
+ ProxyService service = EasyMock.createMock(ProxyService.class);
+ Foo foo = new Foo() {
+ };
+ EasyMock.expect(service.createCallbackProxy(EasyMock.eq(Foo.class))).andReturn(foo);
+ EasyMock.replay(service);
+ CallbackWireObjectFactory2 factory = new CallbackWireObjectFactory2(Foo.class, service);
+ assertEquals(foo, factory.getInstance());
+ EasyMock.verify(service);
+ }
+
+ private interface Foo {
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactoryTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactoryTestCase.java
new file mode 100644
index 0000000000..9032d091a3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactoryTestCase.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.core.injection;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.ProxyService;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.createMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CallbackWireObjectFactoryTestCase extends TestCase {
+
+ @SuppressWarnings({"unchecked"})
+ public void testCreateInstance() throws Exception {
+ ProxyService service = createMock(ProxyService.class);
+ Foo foo = new Foo() {
+ };
+ EasyMock.expect(service.createCallbackProxy(EasyMock.eq(Foo.class), EasyMock.isA(List.class))).andReturn(foo);
+ EasyMock.replay(service);
+ List<Wire> wires = new ArrayList<Wire>();
+ CallbackWireObjectFactory factory = new CallbackWireObjectFactory(Foo.class, service, wires);
+ assertEquals(foo, factory.getInstance());
+ EasyMock.verify(service);
+ }
+
+ private interface Foo {
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/FieldInjectorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/FieldInjectorTestCase.java
new file mode 100644
index 0000000000..d31347f7e6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/FieldInjectorTestCase.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.core.injection;
+
+import java.lang.reflect.Field;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class FieldInjectorTestCase extends TestCase {
+
+ protected Field protectedField;
+
+ public void testIllegalAccess() throws Exception {
+ FieldInjector<Foo> injector = new FieldInjector<Foo>(protectedField, new SingletonObjectFactory<String>("foo"));
+ Foo foo = new Foo();
+ injector.inject(foo);
+ assertEquals("foo", foo.hidden);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ protectedField = Foo.class.getDeclaredField("hidden");
+ }
+
+ private class Foo {
+ private String hidden;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/JNDIObjectFactoryTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/JNDIObjectFactoryTestCase.java
new file mode 100644
index 0000000000..91214fd02d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/JNDIObjectFactoryTestCase.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.core.injection;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JNDIObjectFactoryTestCase extends TestCase {
+
+ public void testGetInstance() throws Exception {
+ Context ctx = EasyMock.createMock(Context.class);
+ EasyMock.expect(ctx.lookup(EasyMock.eq("foo"))).andReturn(new Foo());
+ EasyMock.replay(ctx);
+ JNDIObjectFactory<Foo> factory = new JNDIObjectFactory<Foo>(ctx, "foo");
+ assertTrue(factory.getInstance() instanceof Foo); // must do an instanceof b/c of type erasure
+ EasyMock.verify(ctx);
+ }
+
+ public void testGetInstanceError() throws Exception {
+ Context ctx = EasyMock.createMock(Context.class);
+ EasyMock.expect(ctx.lookup(EasyMock.eq("foo"))).andThrow(new NamingException());
+ EasyMock.replay(ctx);
+ JNDIObjectFactory<Foo> factory = new JNDIObjectFactory<Foo>(ctx, "foo");
+ try {
+ factory.getInstance();
+ fail();
+ } catch (ObjectCreationException e) {
+ //expected
+ }
+ EasyMock.verify(ctx);
+ }
+
+
+ private class Foo {
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/MethodEventInvokerTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/MethodEventInvokerTestCase.java
new file mode 100644
index 0000000000..3bb882da2d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/MethodEventInvokerTestCase.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.core.injection;
+
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MethodEventInvokerTestCase extends TestCase {
+ private Method privateMethod;
+ private Method exceptionMethod;
+
+ public void testIllegalAccess() throws Exception {
+ MethodEventInvoker<MethodEventInvokerTestCase.Foo> injector = new MethodEventInvoker<Foo>(privateMethod);
+ try {
+ injector.invokeEvent(new Foo());
+ fail();
+ } catch (AssertionError e) {
+ // expected
+ }
+ }
+
+ public void testException() throws Exception {
+ MethodEventInvoker<MethodEventInvokerTestCase.Foo> injector = new MethodEventInvoker<Foo>(exceptionMethod);
+ try {
+ injector.invokeEvent(new Foo());
+ fail();
+ } catch (RuntimeException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ privateMethod = MethodEventInvokerTestCase.Foo.class.getDeclaredMethod("hidden");
+ exceptionMethod = MethodEventInvokerTestCase.Foo.class.getDeclaredMethod("exception");
+
+ }
+
+ private class Foo {
+
+ public void foo() {
+ }
+
+ private void hidden() {
+ }
+
+ public void exception() {
+ throw new RuntimeException();
+ }
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/MethodInjectorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/MethodInjectorTestCase.java
new file mode 100644
index 0000000000..b21ba4ccfa
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/MethodInjectorTestCase.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.core.injection;
+
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MethodInjectorTestCase extends TestCase {
+ private Method fooMethod;
+ private Method privateMethod;
+ private Method exceptionMethod;
+
+ public void testIllegalArgument() throws Exception {
+ ObjectFactory<Object> factory = new SingletonObjectFactory<Object>(new Object());
+ MethodInjector<Foo> injector = new MethodInjector<Foo>(fooMethod, factory);
+ try {
+ injector.inject(new Foo());
+ fail();
+ } catch (ObjectCreationException e) {
+ // expected
+ }
+ }
+
+ public void testException() throws Exception {
+ ObjectFactory<Object> factory = new SingletonObjectFactory<Object>("foo");
+ MethodInjector<Foo> injector = new MethodInjector<Foo>(exceptionMethod, factory);
+ try {
+ injector.inject(new Foo());
+ fail();
+ } catch (RuntimeException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ fooMethod = Foo.class.getMethod("foo", String.class);
+ privateMethod = Foo.class.getDeclaredMethod("hidden", String.class);
+ exceptionMethod = Foo.class.getDeclaredMethod("exception", String.class);
+
+ }
+
+ private class Foo {
+
+ public void foo(String bar) {
+ }
+
+ private void hidden(String bar) {
+ }
+
+ public void exception(String bar) {
+ throw new RuntimeException();
+ }
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/PojoObjectFactoryTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/PojoObjectFactoryTestCase.java
new file mode 100644
index 0000000000..f68f34b22f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/PojoObjectFactoryTestCase.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.core.injection;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.spi.ObjectFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PojoObjectFactoryTestCase extends TestCase {
+
+ private Constructor<Foo> ctor;
+
+ public void testConstructorInjection() throws Exception {
+ List<ObjectFactory> initializers = new ArrayList<ObjectFactory>();
+ initializers.add(new SingletonObjectFactory<String>("foo"));
+ PojoObjectFactory<Foo> factory = new PojoObjectFactory<Foo>(ctor, initializers);
+ Foo foo = factory.getInstance();
+ assertEquals("foo", foo.foo);
+ }
+
+ /**
+ * Verifies null parameters can be passed to a constructor. This is valid when a reference is optional during
+ * constructor injection
+ */
+ public void testConstructorInjectionOptionalParam() throws Exception {
+ List<ObjectFactory> initializers = new ArrayList<ObjectFactory>();
+ initializers.add(null);
+ PojoObjectFactory<Foo> factory = new PojoObjectFactory<Foo>(ctor, initializers);
+ Foo foo = factory.getInstance();
+ assertNull(foo.foo);
+ }
+
+ public void testConstructorInitializerInjection() throws Exception {
+ PojoObjectFactory<Foo> factory = new PojoObjectFactory<Foo>(ctor);
+ factory.setInitializerFactory(0, new SingletonObjectFactory<String>("foo"));
+ Foo foo = factory.getInstance();
+ assertEquals("foo", foo.foo);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ ctor = Foo.class.getConstructor(String.class);
+ }
+
+ private static class Foo {
+
+ private String foo;
+
+ public Foo(String foo) {
+ this.foo = foo;
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/RequestContextObjectFactoryTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/RequestContextObjectFactoryTestCase.java
new file mode 100644
index 0000000000..a1a41bbada
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/RequestContextObjectFactoryTestCase.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.core.injection;
+
+import org.apache.tuscany.spi.component.WorkContext;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class RequestContextObjectFactoryTestCase extends TestCase {
+
+ public void testInstanceCreate() {
+ WorkContext workContext = EasyMock.createNiceMock(WorkContext.class);
+ RequestContextObjectFactory factory = new RequestContextObjectFactory(workContext);
+ assertNotNull(factory.getInstance());
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/ResourceObjectFactoryTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/ResourceObjectFactoryTestCase.java
new file mode 100644
index 0000000000..cf8bbc6818
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/ResourceObjectFactoryTestCase.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.core.injection;
+
+import org.apache.tuscany.spi.host.ResourceHost;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ResourceObjectFactoryTestCase extends TestCase {
+
+ public void testResolveFromHostByType() throws Exception {
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(EasyMock.eq(String.class))).andReturn("foo");
+ EasyMock.replay(host);
+ ResourceObjectFactory<String> factory = new ResourceObjectFactory<String>(String.class, false, host);
+ assertEquals("foo", factory.getInstance());
+ EasyMock.verify(host);
+ }
+
+ public void testResolveFromHostByName() throws Exception {
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(EasyMock.eq(String.class),
+ EasyMock.eq("sca://localhost/bar"))).andReturn("foo");
+ EasyMock.replay(host);
+ ResourceObjectFactory<String> factory =
+ new ResourceObjectFactory<String>(String.class, "sca://localhost/bar", false, host);
+ assertEquals("foo", factory.getInstance());
+ EasyMock.verify(host);
+ }
+
+
+ public void testResolveFromParentThenResolveFromHostNotFound() throws Exception {
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(EasyMock.eq(String.class))).andReturn(null);
+ EasyMock.replay(host);
+ ResourceObjectFactory<String> factory = new ResourceObjectFactory<String>(String.class, true, host);
+ assertNull(factory.getInstance());
+ EasyMock.verify(host);
+ }
+
+ public void testResolveByTypeNotFound() throws Exception {
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(EasyMock.eq(String.class))).andReturn(null);
+ EasyMock.replay(host);
+
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.getTargetInstance()).andReturn(null);
+ EasyMock.replay(wire);
+
+ ResourceObjectFactory<String> factory = new ResourceObjectFactory<String>(String.class, false, host);
+ try {
+ factory.getInstance();
+ fail();
+ } catch (ResourceNotFoundException e) {
+ //expected
+ }
+ EasyMock.verify(host);
+ }
+
+ public void testResolveByTypeNotFoundOptional() throws Exception {
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(EasyMock.eq(String.class))).andReturn(null);
+ EasyMock.replay(host);
+ ResourceObjectFactory<String> factory = new ResourceObjectFactory<String>(String.class, true, host);
+ assertNull(factory.getInstance());
+ EasyMock.verify(host);
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java
new file mode 100644
index 0000000000..876e68d5b3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/injection/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.core.injection;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SingletonObjectFactoryTestCase extends TestCase {
+
+ public void testSingleton() throws Exception {
+ Object o = new Object();
+ SingletonObjectFactory<Object> factory = new SingletonObjectFactory<Object>(o);
+ assertEquals(o, factory.getInstance());
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/AbstractConversationTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/AbstractConversationTestCase.java
new file mode 100644
index 0000000000..95f51c1183
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/AbstractConversationTestCase.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.core.integration.conversation;
+
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.services.store.StoreMonitor;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.component.scope.ConversationalScopeContainer;
+import org.apache.tuscany.core.services.store.memory.MemoryStore;
+import org.easymock.classextension.EasyMock;
+
+/**
+ * Provides helper methods for setting up a partial runtime for conversational test cases.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractConversationTestCase extends TestCase {
+ protected ScopeContainer container;
+ protected MemoryStore store;
+ protected WorkContext workContext;
+
+ protected void createRuntime() {
+ workContext = new WorkContextImpl();
+ store = new MemoryStore(EasyMock.createNiceMock(StoreMonitor.class));
+ container = new ConversationalScopeContainer(store, workContext, null);
+ }
+
+ protected void initializeRuntime() {
+ store.init();
+ container.start();
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationIdleExpireTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationIdleExpireTestCase.java
new file mode 100644
index 0000000000..92ad17b20d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationIdleExpireTestCase.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.integration.conversation;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.net.URI;
+
+import org.osoa.sca.annotations.Conversational;
+import org.osoa.sca.annotations.EndsConversation;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.TargetNotFoundException;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.java.JavaAtomicComponent;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.integration.mock.MockFactory;
+import org.apache.tuscany.core.wire.jdk.JDKInvocationHandler;
+import org.easymock.classextension.EasyMock;
+
+/**
+ * Verifies conversational resources are cleaned up if the maximum idle time is exceeded
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class ConversationIdleExpireTestCase extends AbstractConversationTestCase {
+ protected AtomicComponent target;
+ private JDKInvocationHandler handler;
+ private FooImpl targetInstance;
+ private Method operation1;
+ private Method operation2;
+ private final Object mutex = new Object();
+
+ public void testConversationExpire() throws Throwable {
+ workContext.setIdentifier(org.apache.tuscany.spi.model.Scope.CONVERSATION, "12345A");
+ // start the conversation
+ handler.invoke(operation1, null);
+ // verify the instance was persisted
+ assertEquals(targetInstance, ((InstanceWrapper)store.readRecord(target, "12345A")).getInstance());
+ synchronized (mutex) {
+ mutex.wait(100);
+ }
+ // verify the instance was expired
+ assertNull(store.readRecord(target, "12345A"));
+ // continue the conversation - should throw an error
+ try {
+ handler.invoke(operation2, null);
+ fail();
+ } catch (TargetNotFoundException e) {
+ // expected
+ }
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ createRuntime();
+ store.setReaperInterval(10);
+ initializeRuntime();
+
+ targetInstance = EasyMock.createMock(FooImpl.class);
+ targetInstance.operation1();
+ targetInstance.operation2();
+ targetInstance.end();
+ EasyMock.replay(targetInstance);
+ target = createTarget();
+
+ Wire wire = MockFactory.createWire("foo", Foo.class);
+ for (InvocationChain chain : wire.getInvocationChains().values()) {
+ chain.setTargetInvoker(target.createTargetInvoker("target", chain.getOperation()));
+ }
+ handler = new JDKInvocationHandler(Foo.class, wire, workContext);
+ operation1 = Foo.class.getMethod("operation1");
+ operation2 = Foo.class.getMethod("operation2");
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ container.stop();
+ store.destroy();
+ }
+
+ private JavaAtomicComponent createTarget() throws Exception {
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setName(new URI("target"));
+ configuration.setMaxIdleTime(50);
+ configuration.setInstanceFactory(new MockPojoFactory(FooImpl.class.getConstructor()));
+ configuration.setImplementationClass(FooImpl.class);
+ JavaAtomicComponent component = new JavaAtomicComponent(configuration);
+ component.setScopeContainer(container);
+ component.start();
+ return component;
+ }
+
+ private class MockPojoFactory extends PojoObjectFactory<FooImpl> {
+ public MockPojoFactory(Constructor<FooImpl> ctr) {
+ super(ctr);
+ }
+
+ public FooImpl getInstance() throws ObjectCreationException {
+ return targetInstance;
+ }
+ }
+
+ @Conversational
+ public static interface Foo {
+
+ void operation1();
+
+ void operation2();
+
+ @EndsConversation
+ void end();
+
+ }
+
+ public static class FooImpl implements Foo {
+
+ public void operation1() {
+ }
+
+ public void operation2() {
+ }
+
+ @EndsConversation
+ public void end() {
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationMaxAgeExpireTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationMaxAgeExpireTestCase.java
new file mode 100644
index 0000000000..10b3752873
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationMaxAgeExpireTestCase.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.core.integration.conversation;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.net.URI;
+
+import org.easymock.classextension.EasyMock;
+import org.osoa.sca.annotations.Conversational;
+import org.osoa.sca.annotations.EndsConversation;
+
+import org.apache.tuscany.core.component.InstanceFactory;
+import org.apache.tuscany.core.component.scope.ReflectiveInstanceWrapper;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.java.JavaAtomicComponent;
+import org.apache.tuscany.core.integration.mock.MockFactory;
+import org.apache.tuscany.core.wire.jdk.JDKInvocationHandler;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.TargetNotFoundException;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.ObjectCreationException;
+
+/**
+ * Verifies conversational resources are cleaned up if the maximum age is exceeded
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class ConversationMaxAgeExpireTestCase extends AbstractConversationTestCase {
+ protected AtomicComponent target;
+ private JDKInvocationHandler handler;
+ private FooImpl targetInstance;
+ private Method operation1;
+ private Method operation2;
+ private final Object mutex = new Object();
+
+ public void testConversationExpire() throws Throwable {
+/*
+ workContext.setIdentifier(org.apache.tuscany.spi.model.Scope.CONVERSATION, "12345A");
+ // start the conversation
+ handler.invoke(operation1, null);
+ // verify the instance was persisted
+ assertEquals(targetInstance, ((InstanceWrapper)store.readRecord(target, "12345A")).getInstance());
+ synchronized (mutex) {
+ mutex.wait(100);
+ }
+ // verify the instance was expired
+ assertNull(store.readRecord(target, "12345A"));
+ // continue the conversation - should throw an error
+ try {
+ handler.invoke(operation2, null);
+ fail();
+ } catch (TargetNotFoundException e) {
+ // expected
+ }
+*/
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ createRuntime();
+ store.setReaperInterval(10);
+ initializeRuntime();
+
+ targetInstance = EasyMock.createMock(FooImpl.class);
+ targetInstance.operation1();
+ targetInstance.operation2();
+ targetInstance.end();
+ EasyMock.replay(targetInstance);
+ target = createTarget();
+ // create source component mock
+ JavaAtomicComponent source = EasyMock.createMock(JavaAtomicComponent.class);
+ EasyMock.expect(source.getUri()).andReturn(URI.create("source")).atLeastOnce();
+ EasyMock.replay(source);
+
+ Wire wire = MockFactory.createWire("foo", Foo.class);
+ for (InvocationChain chain : wire.getInvocationChains().values()) {
+ chain.setTargetInvoker(target.createTargetInvoker("target", chain.getOperation()));
+ }
+ handler = new JDKInvocationHandler(Foo.class, wire, workContext);
+ operation1 = Foo.class.getMethod("operation1");
+ operation2 = Foo.class.getMethod("operation2");
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ container.stop();
+ store.destroy();
+ }
+
+ private AtomicComponent createTarget() throws Exception {
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setName(new URI("target"));
+ configuration.setMaxAge(50);
+ Constructor<FooImpl> ctor = FooImpl.class.getConstructor();
+ configuration.setInstanceFactory(new MockPojoFactory(ctor));
+ configuration.setImplementationClass(FooImpl.class);
+ JavaAtomicComponent component = new JavaAtomicComponent(configuration);
+ component.setScopeContainer(container);
+ component.start();
+ return component;
+ }
+
+ private class MockPojoFactory extends PojoObjectFactory<FooImpl> {
+ public MockPojoFactory(Constructor<FooImpl> ctr) {
+ super(ctr);
+ }
+
+ public FooImpl getInstance() throws ObjectCreationException {
+ return targetInstance;
+ }
+ }
+
+ @Conversational
+ public static interface Foo {
+
+ void operation1();
+
+ void operation2();
+
+ @EndsConversation
+ void end();
+
+ }
+
+ public static class FooImpl implements Foo {
+
+ public void operation1() {
+ }
+
+ public void operation2() {
+ }
+
+ @EndsConversation
+ public void end() {
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationStartStopEndTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationStartStopEndTestCase.java
new file mode 100644
index 0000000000..8ec98d5f0d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationStartStopEndTestCase.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.core.integration.conversation;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.net.URI;
+
+import org.osoa.sca.annotations.Conversational;
+import org.osoa.sca.annotations.EndsConversation;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import static org.apache.tuscany.spi.model.Scope.CONVERSATION;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.java.JavaAtomicComponent;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.integration.mock.MockFactory;
+import org.apache.tuscany.core.wire.jdk.JDKInvocationHandler;
+import org.easymock.classextension.EasyMock;
+
+/**
+ * Verifies start, continue and end conversation invocations are processed properly. Checks that a target instance is
+ * properly instantiated and persisted in the store. Additionally verifies that invocations are dispatched to a target
+ * instance, and that start, continue, and end operations are performed correctly. Finally, verfies that the target
+ * instance is removed from the store when the conversation ends.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class ConversationStartStopEndTestCase extends AbstractConversationTestCase {
+ protected AtomicComponent target;
+ private FooImpl targetInstance;
+ private JDKInvocationHandler handler;
+ private Method operation1;
+ private Method operation2;
+ private Method endOperation;
+
+ public void testConversationStartContinueEnd() throws Throwable {
+ workContext.setIdentifier(CONVERSATION, "12345A");
+ // start the conversation
+ handler.invoke(operation1, null);
+ // verify the instance was persisted
+ assertEquals(targetInstance, ((InstanceWrapper)store.readRecord(target, "12345A")).getInstance());
+ // continue the conversation
+ handler.invoke(operation2, null);
+ // verify the instance was persisted
+ assertEquals(targetInstance, ((InstanceWrapper)store.readRecord(target, "12345A")).getInstance());
+ // end the conversation
+ handler.invoke(endOperation, null);
+ workContext.clearIdentifier(CONVERSATION);
+ EasyMock.verify(targetInstance);
+ // verify the store has removed the instance
+ assertNull(store.readRecord(target, "12345A"));
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ createRuntime();
+ initializeRuntime();
+ targetInstance = EasyMock.createMock(FooImpl.class);
+ targetInstance.operation1();
+ targetInstance.operation2();
+ targetInstance.end();
+ EasyMock.replay(targetInstance);
+ // create target component mock
+ target = createAtomicComponent();
+ Wire wire = MockFactory.createWire("foo", Foo.class);
+ for (InvocationChain chain : wire.getInvocationChains().values()) {
+ chain.setTargetInvoker(target.createTargetInvoker("foo", chain.getOperation()));
+ }
+ handler = new JDKInvocationHandler(Foo.class, wire, workContext);
+ operation1 = Foo.class.getMethod("operation1");
+ operation2 = Foo.class.getMethod("operation2");
+ endOperation = Foo.class.getMethod("end");
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ container.stop();
+ store.destroy();
+ }
+
+ private JavaAtomicComponent createAtomicComponent() throws Exception {
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setName(new URI("target"));
+ configuration.setInstanceFactory(new MockPojoFactory(FooImpl.class.getConstructor()));
+ configuration.setImplementationClass(FooImpl.class);
+ JavaAtomicComponent component = new JavaAtomicComponent(configuration);
+ component.setScopeContainer(container);
+ component.start();
+ return component;
+ }
+
+ private class MockPojoFactory extends PojoObjectFactory<FooImpl> {
+ public MockPojoFactory(Constructor<FooImpl> ctr) {
+ super(ctr);
+ }
+
+ public FooImpl getInstance() throws ObjectCreationException {
+ return targetInstance;
+ }
+ }
+
+ @Conversational
+ public static interface Foo {
+
+ void operation1();
+
+ void operation2();
+
+ @EndsConversation
+ void end();
+
+ }
+
+ public static class FooImpl implements Foo {
+
+ public void operation1() {
+ }
+
+ public void operation2() {
+ }
+
+ @EndsConversation
+ public void end() {
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/IntrospectionRegistryIntegrationTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/IntrospectionRegistryIntegrationTestCase.java
new file mode 100644
index 0000000000..a726609073
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/IntrospectionRegistryIntegrationTestCase.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.integration.implementation;
+
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Scope;
+import org.apache.tuscany.api.annotation.Resource;
+
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import static org.apache.tuscany.spi.model.Scope.COMPOSITE;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.IntrospectionRegistryImpl;
+import org.apache.tuscany.core.implementation.processor.DestroyProcessor;
+import org.apache.tuscany.core.implementation.processor.ImplementationProcessorServiceImpl;
+import org.apache.tuscany.core.implementation.processor.InitProcessor;
+import org.apache.tuscany.core.implementation.processor.PropertyProcessor;
+import org.apache.tuscany.core.implementation.processor.ReferenceProcessor;
+import org.apache.tuscany.core.implementation.processor.ResourceProcessor;
+import org.apache.tuscany.core.implementation.processor.ScopeProcessor;
+import org.apache.tuscany.core.monitor.NullMonitorFactory;
+
+/**
+ * Sanity check of the <code>IntegrationRegistry</code> to verify operation with processors
+ *
+ * @version $Rev$ $Date$
+ */
+public class IntrospectionRegistryIntegrationTestCase extends TestCase {
+
+ private IntrospectionRegistryImpl registry;
+
+ public void testSimpleComponentTypeParsing() throws Exception {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ registry.introspect(Foo.class, type, null);
+ assertEquals(Foo.class.getMethod("init"), type.getInitMethod());
+ assertEquals(Foo.class.getMethod("destroy"), type.getDestroyMethod());
+ assertEquals(COMPOSITE, type.getImplementationScope());
+ assertEquals(Foo.class.getMethod("setBar", String.class), type.getProperties().get("bar").getMember());
+ assertEquals(Foo.class.getMethod("setTarget", Foo.class), type.getReferences().get("target").getMember());
+ assertEquals(Foo.class.getMethod("setResource", Foo.class), type.getResources().get("resource").getMember());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ registry = new IntrospectionRegistryImpl();
+ registry.setMonitor(new NullMonitorFactory().getMonitor(IntrospectionRegistryImpl.Monitor.class));
+ registry.registerProcessor(new DestroyProcessor());
+ registry.registerProcessor(new InitProcessor());
+ registry.registerProcessor(new ScopeProcessor());
+ JavaInterfaceProcessorRegistryImpl interfaceProcessorRegistry = new JavaInterfaceProcessorRegistryImpl();
+ ImplementationProcessorService service = new ImplementationProcessorServiceImpl(interfaceProcessorRegistry);
+ registry.registerProcessor(new PropertyProcessor(service));
+ registry.registerProcessor(new ReferenceProcessor(interfaceProcessorRegistry));
+ registry.registerProcessor(new ResourceProcessor());
+ }
+
+ @Scope("COMPOSITE")
+ private static class Foo {
+ protected Foo target;
+ protected String bar;
+ protected Foo resource;
+ private boolean initialized;
+ private boolean destroyed;
+
+
+ @Init
+ public void init() {
+ if (initialized) {
+ fail();
+ }
+ initialized = true;
+ }
+
+ @Destroy
+ public void destroy() {
+ if (destroyed) {
+ fail();
+ }
+ destroyed = true;
+ }
+
+ public Foo getTarget() {
+ return target;
+ }
+
+ @Reference
+ public void setTarget(Foo target) {
+ this.target = target;
+ }
+
+ public String getBar() {
+ return bar;
+ }
+
+ @Property
+ public void setBar(String bar) {
+ this.bar = bar;
+ }
+
+ @Resource
+ public void setResource(Foo resource) {
+ this.resource = resource;
+ }
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/java/PhysicalBuilderTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/java/PhysicalBuilderTestCase.java
new file mode 100644
index 0000000000..e6ed69782d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/java/PhysicalBuilderTestCase.java
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.integration.implementation.java;
+
+import java.lang.annotation.ElementType;
+import java.net.URI;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+import org.apache.tuscany.core.builder.ConnectorImpl;
+import org.apache.tuscany.core.builder.physical.DefaultPhysicalComponentBuilderRegistry;
+import org.apache.tuscany.core.builder.physical.WireAttacherRegistryImpl;
+import org.apache.tuscany.core.component.ComponentManagerImpl;
+import org.apache.tuscany.core.component.SimpleWorkContext;
+import org.apache.tuscany.core.component.instancefactory.IFProviderBuilderRegistry;
+import org.apache.tuscany.core.component.instancefactory.impl.DefaultIFProviderBuilderRegistry;
+import org.apache.tuscany.core.component.instancefactory.impl.ReflectiveIFProviderBuilder;
+import org.apache.tuscany.core.component.scope.CompositeScopeContainer;
+import org.apache.tuscany.core.deployer.federation.FederatedDeployer;
+import org.apache.tuscany.core.implementation.PojoWorkContextTunnel;
+import org.apache.tuscany.core.implementation.java.JavaPhysicalComponentBuilder;
+import org.apache.tuscany.core.model.physical.instancefactory.InjectionSiteMapping;
+import org.apache.tuscany.core.model.physical.instancefactory.InjectionSource;
+import org.apache.tuscany.core.model.physical.instancefactory.MemberSite;
+import org.apache.tuscany.core.model.physical.instancefactory.ReflectiveIFProviderDefinition;
+import org.apache.tuscany.core.model.physical.java.JavaPhysicalComponentDefinition;
+import org.apache.tuscany.core.model.physical.java.JavaPhysicalWireSourceDefinition;
+import org.apache.tuscany.core.model.physical.java.JavaPhysicalWireTargetDefinition;
+import org.apache.tuscany.spi.builder.Connector;
+import org.apache.tuscany.spi.builder.physical.WireAttacherRegistry;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ComponentManager;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.physical.InstanceFactoryProviderDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalChangeSet;
+import org.apache.tuscany.spi.model.physical.PhysicalWireDefinition;
+import org.apache.tuscany.spi.services.classloading.ClassLoaderRegistry;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PhysicalBuilderTestCase extends TestCase {
+ private URI groupId;
+ private URI sourceId;
+ private URI targetId;
+ private ClassLoaderRegistry classLoaderRegistry;
+ private JavaPhysicalComponentBuilder builder;
+ private ScopeContainer<URI> scopeContainer;
+ private ScopeRegistry scopeRegistry;
+ private InstanceFactoryProviderDefinition<TargetImpl> targetProviderDefinition;
+ private Connector connector;
+ private ComponentManager componentManager;
+ private FederatedDeployer deployer;
+ private PhysicalChangeSet pcs;
+
+ public void testWireTwoComponents() throws Exception {
+ pcs.addComponentDefinition(createSourceComponentDefinition());
+ pcs.addComponentDefinition(createTargetComponentDefinition());
+ pcs.addWireDefinition(createOptimizedWire());
+ deployer.applyChangeSet(pcs);
+
+ WorkContext workContext = new SimpleWorkContext();
+ workContext.setIdentifier(Scope.COMPOSITE, groupId);
+ PojoWorkContextTunnel.setThreadWorkContext(workContext);
+ try {
+ AtomicComponent<?> sourceComponent = (AtomicComponent<?>) componentManager.getComponent(sourceId);
+ InstanceWrapper<?> wrapper = scopeContainer.getWrapper(sourceComponent, groupId);
+ SourceImpl s = (SourceImpl) wrapper.getInstance();
+ assertSame(s.target.getClass(), TargetImpl.class);
+ } finally {
+ PojoWorkContextTunnel.setThreadWorkContext(null);
+ }
+ }
+
+ private JavaPhysicalComponentDefinition<SourceImpl> createSourceComponentDefinition() {
+ ReflectiveIFProviderDefinition sourceProviderDefinition = new ReflectiveIFProviderDefinition();
+ sourceProviderDefinition.setImplementationClass(SourceImpl.class.getName());
+ InjectionSiteMapping mapping = new InjectionSiteMapping();
+ mapping.setSource(new InjectionSource(InjectionSource.ValueSourceType.REFERENCE, "target"));
+ mapping.setSite(new MemberSite(ElementType.FIELD, "target"));
+ sourceProviderDefinition.addInjectionSite(mapping);
+
+ JavaPhysicalComponentDefinition<SourceImpl> source = new JavaPhysicalComponentDefinition<SourceImpl>();
+ source.setComponentId(sourceId);
+ source.setGroupId(groupId);
+ source.setClassLoaderId(groupId);
+ source.setScope(Scope.COMPOSITE);
+ source.setInstanceFactoryProviderDefinition(sourceProviderDefinition);
+ return source;
+ }
+
+ private JavaPhysicalComponentDefinition<TargetImpl> createTargetComponentDefinition() {
+ ReflectiveIFProviderDefinition targetProviderDefinition = new ReflectiveIFProviderDefinition();
+ targetProviderDefinition.setImplementationClass(TargetImpl.class.getName());
+
+ JavaPhysicalComponentDefinition<TargetImpl> target = new JavaPhysicalComponentDefinition<TargetImpl>();
+ target.setComponentId(targetId);
+ target.setGroupId(groupId);
+ target.setClassLoaderId(groupId);
+ target.setScope(Scope.COMPOSITE);
+ target.setInstanceFactoryProviderDefinition(targetProviderDefinition);
+ return target;
+ }
+
+ private PhysicalWireDefinition createOptimizedWire() {
+ JavaPhysicalWireSourceDefinition wireSource = new JavaPhysicalWireSourceDefinition();
+ wireSource.setUri(sourceId.resolve("#target"));
+ wireSource.setOptimizable(true);
+ JavaPhysicalWireTargetDefinition wireTarget = new JavaPhysicalWireTargetDefinition();
+ wireTarget.setUri(targetId);
+ PhysicalWireDefinition wireDefinition = new PhysicalWireDefinition();
+ wireDefinition.setSource(wireSource);
+ wireDefinition.setTarget(wireTarget);
+ return wireDefinition;
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ groupId = URI.create("sca://./composite");
+ sourceId = groupId.resolve("composite/source");
+ targetId = groupId.resolve("composite/target");
+ classLoaderRegistry = EasyMock.createMock(ClassLoaderRegistry.class);
+ ClassLoader classLoader = getClass().getClassLoader();
+ EasyMock.expect(classLoaderRegistry.getClassLoader(groupId)).andStubReturn(classLoader);
+ EasyMock.replay(classLoaderRegistry);
+
+ scopeContainer = new CompositeScopeContainer<URI>(null);
+ scopeContainer.start();
+ scopeContainer.startContext(groupId, groupId);
+
+ scopeRegistry = EasyMock.createMock(ScopeRegistry.class);
+ EasyMock.expect(scopeRegistry.getScopeContainer(Scope.COMPOSITE)).andStubReturn(scopeContainer);
+ EasyMock.replay(scopeRegistry);
+
+ IFProviderBuilderRegistry providerBuilders = new DefaultIFProviderBuilderRegistry();
+ providerBuilders.register(ReflectiveIFProviderDefinition.class, new ReflectiveIFProviderBuilder());
+
+ DefaultPhysicalComponentBuilderRegistry builderRegistry = new DefaultPhysicalComponentBuilderRegistry();
+ WireAttacherRegistry wireAttacherRegistry = new WireAttacherRegistryImpl();
+
+ builder = new JavaPhysicalComponentBuilder(builderRegistry,
+ wireAttacherRegistry,
+ scopeRegistry,
+ providerBuilders,
+ classLoaderRegistry);
+ builder.init();
+
+ componentManager = new ComponentManagerImpl();
+ connector = new ConnectorImpl(null, wireAttacherRegistry, null, componentManager, null, null);
+
+ deployer = new FederatedDeployer();
+ deployer.setBuilderRegistry(builderRegistry);
+ deployer.setComponentManager(componentManager);
+ deployer.setConnector(connector);
+
+ pcs = new PhysicalChangeSet();
+ }
+
+ public static class SourceImpl {
+ public TargetImpl target;
+ }
+
+ public static class TargetImpl {
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/system/builder/PhysicalBuilderTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/system/builder/PhysicalBuilderTestCase.java
new file mode 100644
index 0000000000..14d5324215
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/system/builder/PhysicalBuilderTestCase.java
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.integration.implementation.system.builder;
+
+import java.lang.annotation.ElementType;
+import java.net.URI;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+import org.apache.tuscany.core.builder.ConnectorImpl;
+import org.apache.tuscany.core.builder.physical.DefaultPhysicalComponentBuilderRegistry;
+import org.apache.tuscany.core.builder.physical.WireAttacherRegistryImpl;
+import org.apache.tuscany.core.component.ComponentManagerImpl;
+import org.apache.tuscany.core.component.SimpleWorkContext;
+import org.apache.tuscany.core.component.instancefactory.IFProviderBuilderRegistry;
+import org.apache.tuscany.core.component.instancefactory.impl.DefaultIFProviderBuilderRegistry;
+import org.apache.tuscany.core.component.instancefactory.impl.ReflectiveIFProviderBuilder;
+import org.apache.tuscany.core.component.scope.CompositeScopeContainer;
+import org.apache.tuscany.core.deployer.federation.FederatedDeployer;
+import org.apache.tuscany.core.implementation.PojoWorkContextTunnel;
+import org.apache.tuscany.core.implementation.system.builder.SystemPhysicalComponentBuilder;
+import org.apache.tuscany.core.implementation.system.model.SystemPhysicalComponentDefinition;
+import org.apache.tuscany.core.implementation.system.model.SystemPhysicalWireSourceDefinition;
+import org.apache.tuscany.core.implementation.system.model.SystemPhysicalWireTargetDefinition;
+import org.apache.tuscany.core.model.physical.instancefactory.InjectionSiteMapping;
+import org.apache.tuscany.core.model.physical.instancefactory.InjectionSource;
+import org.apache.tuscany.core.model.physical.instancefactory.MemberSite;
+import org.apache.tuscany.core.model.physical.instancefactory.ReflectiveIFProviderDefinition;
+import org.apache.tuscany.spi.builder.Connector;
+import org.apache.tuscany.spi.builder.physical.WireAttacherRegistry;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ComponentManager;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.physical.InstanceFactoryProviderDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalChangeSet;
+import org.apache.tuscany.spi.model.physical.PhysicalWireDefinition;
+import org.apache.tuscany.spi.services.classloading.ClassLoaderRegistry;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PhysicalBuilderTestCase extends TestCase {
+ private URI groupId;
+ private URI sourceId;
+ private URI targetId;
+ private ClassLoaderRegistry classLoaderRegistry;
+ private SystemPhysicalComponentBuilder builder;
+ private ScopeContainer<URI> scopeContainer;
+ private ScopeRegistry scopeRegistry;
+ private InstanceFactoryProviderDefinition<TargetImpl> targetProviderDefinition;
+ private Connector connector;
+ private ComponentManager componentManager;
+ private FederatedDeployer deployer;
+ private PhysicalChangeSet pcs;
+
+ public void testWireTwoComponents() throws Exception {
+ pcs.addComponentDefinition(createSourceComponentDefinition());
+ pcs.addComponentDefinition(createTargetComponentDefinition());
+ pcs.addWireDefinition(createWireDefinition());
+ deployer.applyChangeSet(pcs);
+
+ WorkContext workContext = new SimpleWorkContext();
+ workContext.setIdentifier(Scope.COMPOSITE, groupId);
+ PojoWorkContextTunnel.setThreadWorkContext(workContext);
+ try {
+ AtomicComponent<?> sourceComponent = (AtomicComponent<?>) componentManager.getComponent(sourceId);
+ InstanceWrapper<?> wrapper = scopeContainer.getWrapper(sourceComponent, groupId);
+ SourceImpl s = (SourceImpl) wrapper.getInstance();
+ assertSame(s.target.getClass(), TargetImpl.class);
+ } finally {
+ PojoWorkContextTunnel.setThreadWorkContext(null);
+ }
+ }
+
+ private SystemPhysicalComponentDefinition<SourceImpl> createSourceComponentDefinition() {
+ ReflectiveIFProviderDefinition sourceProviderDefinition = new ReflectiveIFProviderDefinition();
+ sourceProviderDefinition.setImplementationClass(SourceImpl.class.getName());
+ InjectionSiteMapping mapping = new InjectionSiteMapping();
+ mapping.setSource(new InjectionSource(InjectionSource.ValueSourceType.REFERENCE, "target"));
+ mapping.setSite(new MemberSite(ElementType.FIELD, "target"));
+ sourceProviderDefinition.addInjectionSite(mapping);
+
+ SystemPhysicalComponentDefinition<SourceImpl> source = new SystemPhysicalComponentDefinition<SourceImpl>();
+ source.setComponentId(sourceId);
+ source.setGroupId(groupId);
+ source.setClassLoaderId(groupId);
+ source.setScope(Scope.COMPOSITE);
+ source.setInstanceFactoryProviderDefinition(sourceProviderDefinition);
+ return source;
+ }
+
+ private SystemPhysicalComponentDefinition<TargetImpl> createTargetComponentDefinition() {
+ ReflectiveIFProviderDefinition targetProviderDefinition = new ReflectiveIFProviderDefinition();
+ targetProviderDefinition.setImplementationClass(TargetImpl.class.getName());
+
+ SystemPhysicalComponentDefinition<TargetImpl> target = new SystemPhysicalComponentDefinition<TargetImpl>();
+ target.setComponentId(targetId);
+ target.setGroupId(groupId);
+ target.setClassLoaderId(groupId);
+ target.setScope(Scope.COMPOSITE);
+ target.setInstanceFactoryProviderDefinition(targetProviderDefinition);
+ return target;
+ }
+
+ private PhysicalWireDefinition createWireDefinition() {
+ SystemPhysicalWireSourceDefinition wireSource = new SystemPhysicalWireSourceDefinition();
+ wireSource.setUri(sourceId.resolve("#target"));
+ SystemPhysicalWireTargetDefinition wireTarget = new SystemPhysicalWireTargetDefinition();
+ wireTarget.setUri(targetId);
+ PhysicalWireDefinition wireDefinition = new PhysicalWireDefinition();
+ wireDefinition.setSource(wireSource);
+ wireDefinition.setTarget(wireTarget);
+ return wireDefinition;
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ groupId = URI.create("sca://./composite");
+ sourceId = groupId.resolve("composite/source");
+ targetId = groupId.resolve("composite/target");
+ classLoaderRegistry = EasyMock.createMock(ClassLoaderRegistry.class);
+ ClassLoader classLoader = getClass().getClassLoader();
+ EasyMock.expect(classLoaderRegistry.getClassLoader(groupId)).andStubReturn(classLoader);
+ EasyMock.replay(classLoaderRegistry);
+
+ scopeContainer = new CompositeScopeContainer<URI>(null);
+ scopeContainer.start();
+ scopeContainer.startContext(groupId, groupId);
+
+ scopeRegistry = EasyMock.createMock(ScopeRegistry.class);
+ EasyMock.expect(scopeRegistry.getScopeContainer(Scope.COMPOSITE)).andStubReturn(scopeContainer);
+ EasyMock.replay(scopeRegistry);
+
+ IFProviderBuilderRegistry providerBuilders = new DefaultIFProviderBuilderRegistry();
+ providerBuilders.register(ReflectiveIFProviderDefinition.class, new ReflectiveIFProviderBuilder());
+
+ DefaultPhysicalComponentBuilderRegistry builderRegistry = new DefaultPhysicalComponentBuilderRegistry();
+ WireAttacherRegistry wireAttacherRegistry = new WireAttacherRegistryImpl();
+ builder = new SystemPhysicalComponentBuilder(builderRegistry,
+ wireAttacherRegistry,
+ scopeRegistry,
+ providerBuilders,
+ classLoaderRegistry);
+ builder.init();
+
+ componentManager = new ComponentManagerImpl();
+ connector = new ConnectorImpl(null, wireAttacherRegistry, null, componentManager, null, null);
+
+ deployer = new FederatedDeployer();
+ deployer.setBuilderRegistry(builderRegistry);
+ deployer.setComponentManager(componentManager);
+ deployer.setConnector(connector);
+
+ pcs = new PhysicalChangeSet();
+ }
+
+ public static class SourceImpl {
+ public TargetImpl target;
+ }
+
+ public static class TargetImpl {
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/system/builder/SystemBuilderPropertyTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/system/builder/SystemBuilderPropertyTestCase.java
new file mode 100644
index 0000000000..25e31f0196
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/system/builder/SystemBuilderPropertyTestCase.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.core.integration.implementation.system.builder;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.system.builder.SystemComponentBuilder;
+import org.apache.tuscany.core.implementation.system.model.SystemImplementation;
+import org.apache.tuscany.core.injection.SingletonObjectFactory;
+import org.easymock.EasyMock;
+
+/**
+ * Verifies that the system builder handles configured properties correctly
+ *
+ * @version $Rev$ $Date$
+ */
+public class SystemBuilderPropertyTestCase extends TestCase {
+
+ DeploymentContext deploymentContext;
+ Component parent;
+
+ @SuppressWarnings("unchecked")
+ public void testPropertyHandling() throws Exception {
+ SystemComponentBuilder builder = new SystemComponentBuilder();
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, JavaMappedProperty<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, JavaMappedProperty<?>>();
+ type.setConstructorDefinition(new ConstructorDefinition<Foo>(Foo.class.getConstructor((Class[]) null)));
+ JavaMappedProperty<String> property = new JavaMappedProperty<String>();
+ property.setName("test");
+ property.setDefaultValueFactory(new SingletonObjectFactory<String>("foo"));
+ property.setMember(Foo.class.getMethod("setTest", String.class));
+ type.add(property);
+ SystemImplementation impl = new SystemImplementation();
+ impl.setComponentType(type);
+ impl.setImplementationClass(Foo.class);
+ ComponentDefinition<SystemImplementation> definition = new ComponentDefinition<SystemImplementation>(impl);
+ definition.setUri(URI.create("component"));
+ AtomicComponent component = builder.build(definition, deploymentContext);
+ Foo foo = (Foo) component.createInstance();
+ assertEquals("foo", foo.getTest());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ deploymentContext = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(deploymentContext.getGroupId()).andStubReturn(URI.create("composite"));
+ EasyMock.replay(deploymentContext);
+ parent = EasyMock.createNiceMock(Component.class);
+ }
+
+ private static class Foo {
+ private String test;
+
+ public Foo() {
+ }
+
+ public String getTest() {
+ return test;
+ }
+
+ public void setTest(String test) {
+ this.test = test;
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/mock/MockFactory.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/mock/MockFactory.java
new file mode 100644
index 0000000000..8fd720ffd2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/mock/MockFactory.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.core.integration.mock;
+
+import java.lang.reflect.Member;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.ProxyService;
+
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.java.JavaAtomicComponent;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.wire.InvocationChainImpl;
+import org.apache.tuscany.core.wire.InvokerInterceptor;
+import org.apache.tuscany.core.wire.WireImpl;
+import org.apache.tuscany.core.wire.jdk.JDKProxyService;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public final class MockFactory {
+
+ private static final ProxyService PROXY_SERVICE = new JDKProxyService(new WorkContextImpl());
+ private static final JavaInterfaceProcessorRegistry REGISTRY = new JavaInterfaceProcessorRegistryImpl();
+
+ private MockFactory() {
+ }
+
+ /**
+ * Wires two components together where the reference interface is the same as target service
+ */
+ public static Map<String, AtomicComponent> createWiredComponents(String sourceName,
+ Class<?> sourceClass,
+ ScopeContainer sourceScope,
+ Map<String, Member> members,
+ String targetName,
+ Class<?> targetService,
+ Class<?> targetClass,
+ ScopeContainer targetScope) throws Exception {
+ return createWiredComponents(sourceName,
+ sourceClass,
+ targetService,
+ sourceScope,
+ null,
+ members,
+ targetName,
+ targetClass,
+ targetScope
+ );
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public static Map<String, AtomicComponent> createWiredComponents(String sourceName, Class<?> sourceClass,
+ Class<?> sourceReferenceClass,
+ ScopeContainer sourceScope,
+ Interceptor sourceHeadInterceptor,
+ Map<String, Member> members,
+ String targetName,
+ Class<?> targetClass,
+ ScopeContainer targetScope
+ )
+ throws Exception {
+
+ JavaAtomicComponent targetComponent =
+ createJavaComponent(targetName, targetScope, targetClass);
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setInstanceFactory(new PojoObjectFactory(sourceClass.getConstructor()));
+ configuration.setProxyService(PROXY_SERVICE);
+ for (Map.Entry<String, Member> entry : members.entrySet()) {
+ configuration.addReferenceSite(entry.getKey(), entry.getValue());
+ }
+ configuration.setWorkContext(new WorkContextImpl());
+ configuration.setName(new URI(sourceName));
+ configuration.setGroupId(URI.create("composite"));
+ JavaAtomicComponent sourceComponent = new JavaAtomicComponent(configuration);
+ sourceComponent.setScopeContainer(sourceScope);
+ Wire wire = createWire(targetName, sourceReferenceClass, sourceHeadInterceptor);
+ for (InvocationChain chain : wire.getInvocationChains().values()) {
+ chain.setTargetInvoker(targetComponent.createTargetInvoker(targetName, chain.getOperation()));
+ }
+ sourceComponent.attachWire(wire);
+ targetScope.register(targetComponent, configuration.getGroupId());
+ sourceScope.register(sourceComponent, configuration.getGroupId());
+ Map<String, AtomicComponent> components = new HashMap<String, AtomicComponent>();
+ components.put(sourceName, sourceComponent);
+ components.put(targetName, targetComponent);
+ return components;
+ }
+
+
+ /**
+ * Wires two components using a multiplicity reference
+ */
+ @SuppressWarnings("unchecked")
+ public static Map<String, AtomicComponent> createWiredMultiplicity(String sourceName, Class<?> sourceClass,
+ Class<?> sourceReferenceClass,
+ ScopeContainer sourceScope,
+ String targetName, Class<?> targetService,
+ Class<?> targetClass,
+ Map<String, Member> members,
+ ScopeContainer targetScope) throws Exception {
+ JavaAtomicComponent targetComponent =
+ createJavaComponent(targetName, targetScope, targetClass);
+ String serviceName = targetService.getName().substring(targetService.getName().lastIndexOf('.') + 1);
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setInstanceFactory(new PojoObjectFactory(sourceClass.getConstructor()));
+ configuration.setProxyService(PROXY_SERVICE);
+ for (Map.Entry<String, Member> entry : members.entrySet()) {
+ configuration.addReferenceSite(entry.getKey(), entry.getValue());
+ }
+ configuration.setWorkContext(new WorkContextImpl());
+ configuration.setName(new URI(sourceName));
+ configuration.setGroupId(URI.create("composite"));
+
+ JavaAtomicComponent sourceComponent = new JavaAtomicComponent(configuration);
+ sourceComponent.setScopeContainer(sourceScope);
+ Wire wire = createWire(targetName, sourceReferenceClass, null);
+ wire.setTargetUri(URI.create(targetName + "#" + serviceName));
+ for (InvocationChain chain : wire.getInvocationChains().values()) {
+ chain.setTargetInvoker(targetComponent.createTargetInvoker("target", chain.getOperation()));
+ }
+ List<Wire> wires = new ArrayList<Wire>();
+ wires.add(wire);
+ sourceComponent.attachWires(wires);
+ targetScope.register(targetComponent, configuration.getGroupId());
+ sourceScope.register(sourceComponent, configuration.getGroupId());
+
+ Map<String, AtomicComponent> components = new HashMap<String, AtomicComponent>();
+ components.put(sourceName, sourceComponent);
+ components.put(targetName, targetComponent);
+ return components;
+ }
+
+ public static <T> Wire createWire(String serviceName, Class<T> interfaze)
+ throws InvalidServiceContractException {
+ return createWire(serviceName, interfaze, null);
+ }
+
+ public static <T> Wire createWire(String serviceName, Class<T> interfaze, Interceptor interceptor)
+ throws InvalidServiceContractException {
+ Wire wire = new WireImpl();
+ ServiceContract<?> contract = REGISTRY.introspect(interfaze);
+ wire.setSourceContract(contract);
+ wire.setSourceUri(URI.create("#" + serviceName));
+ createChains(interfaze, interceptor, wire);
+ return wire;
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> JavaAtomicComponent createJavaComponent(String name, ScopeContainer scope, Class<T> clazz)
+ throws NoSuchMethodException, URISyntaxException {
+ PojoConfiguration configuration = new PojoConfiguration();
+ configuration.setImplementationClass(clazz);
+ configuration.setInstanceFactory(new PojoObjectFactory(clazz.getConstructor()));
+ configuration.setProxyService(PROXY_SERVICE);
+ configuration.setWorkContext(new WorkContextImpl());
+ configuration.setName(new URI(name));
+ configuration.setGroupId(URI.create("composite"));
+ JavaAtomicComponent component = new JavaAtomicComponent(configuration);
+ component.setScopeContainer(scope);
+ return component;
+ }
+
+ private static void createChains(Class<?> interfaze, Interceptor interceptor, Wire wire)
+ throws InvalidServiceContractException {
+
+ ServiceContract<?> contract = REGISTRY.introspect(interfaze);
+ for (Operation<?> method : contract.getOperations().values()) {
+ InvocationChain chain = new InvocationChainImpl(method);
+ if (interceptor != null) {
+ chain.addInterceptor(interceptor);
+ }
+ // add tail interceptor
+ chain.addInterceptor(new InvokerInterceptor());
+ wire.addInvocationChain(method, chain);
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/scope/ScopeReferenceTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/scope/ScopeReferenceTestCase.java
new file mode 100644
index 0000000000..405de5390a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/scope/ScopeReferenceTestCase.java
@@ -0,0 +1,796 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.integration.scope;
+
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.HashMap;
+import java.util.Map;
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.component.scope.CompositeScopeContainer;
+import org.apache.tuscany.core.component.scope.StatelessScopeContainer;
+import org.apache.tuscany.core.integration.mock.MockFactory;
+import org.apache.tuscany.core.mock.component.Source;
+import org.apache.tuscany.core.mock.component.SourceImpl;
+import org.apache.tuscany.core.mock.component.Target;
+import org.apache.tuscany.core.mock.component.TargetImpl;
+import org.apache.tuscany.core.util.JavaIntrospectionHelper;
+import org.apache.tuscany.core.implementation.PojoWorkContextTunnel;
+
+import org.easymock.EasyMock;
+
+/**
+ * Tests scoping is properly handled for service references
+ *
+ * @version $Rev$ $Date$
+ */
+public class ScopeReferenceTestCase extends TestCase {
+ private Map<String, Member> members;
+ private URI groupId;
+ private ScopeContainer statelessScope;
+ private ScopeContainer compositeScope;
+ private WorkContext workContext;
+
+ /**
+ * Tests a composite-to-composite scoped wire
+ */
+ public void testCompositeToComposite() throws Exception {
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source",
+ SourceImpl.class,
+ compositeScope, members,
+ "target",
+ Target.class,
+ TargetImpl.class,
+ compositeScope);
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ PojoWorkContextTunnel.setThreadWorkContext(workContext);
+ try {
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertEquals("foo", source.getTarget().getString());
+ } finally {
+ PojoWorkContextTunnel.setThreadWorkContext(null);
+ }
+ }
+
+ /**
+ * Tests a composite-to-session scoped wire is setup properly by the runtime
+ */
+/*
+ public void testCompositeToSession() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ ScopeContainer compositeScope = new CompositeScopeContainer(null);
+ compositeScope.start();
+ compositeScope.createGroup(groupId);
+ ScopeContainer sessionScope = new HttpSessionScopeContainer(ctx, null);
+ sessionScope.start();
+ sessionScope.createGroup(groupId);
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ compositeScope, members, "target", Target.class, TargetImpl.class, sessionScope);
+ compositeScope.onEvent(new ComponentStart(this, null));
+ Object session1 = new Object();
+ ctx.setIdentifier(Scope.SESSION, session1);
+ sessionScope.onEvent(new HttpSessionStart(this, session1));
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertEquals("foo", source.getTarget().getString());
+ ctx.clearIdentifier(Scope.SESSION);
+ sessionScope.onEvent(new HttpSessionEnd(this, session1));
+
+ //second session
+ Object session2 = new Object();
+ ctx.setIdentifier(Scope.SESSION, session2);
+ sessionScope.onEvent(new HttpSessionStart(this, session2));
+
+ Target target2 = (Target) targetComponent.getTargetInstance();
+ assertFalse("foo".equals(target2.getString()));
+
+ assertFalse("foo".equals(source.getTarget().getString()));
+ source.getTarget().setString("bar");
+ assertEquals("bar", target2.getString());
+ assertEquals("bar", source.getTarget().getString());
+ sessionScope.onEvent(new HttpSessionEnd(this, session2));
+
+ ctx.clearIdentifier(Scope.SESSION);
+ compositeScope.onEvent(new ComponentStop(this, null));
+ sessionScope.stop();
+ compositeScope.stop();
+ }
+*/
+
+ /**
+ * Tests a composite-to-request scoped wire
+ */
+/*
+ public void testCompositeToRequest() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ ScopeContainer compositeScope = new CompositeScopeContainer(null);
+ compositeScope.start();
+ final ScopeContainer requestScope = new RequestScopeContainer(ctx, null);
+ requestScope.start();
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ compositeScope, members, "target", Target.class, TargetImpl.class, requestScope);
+ compositeScope.onEvent(new ComponentStart(this, null));
+ requestScope.onEvent(new RequestStart(this));
+
+ AtomicComponent sourceComponent = contexts.get("source");
+ final AtomicComponent targetComponent = contexts.get("target");
+ final Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertEquals("foo", source.getTarget().getString());
+
+ // spin off another request
+ Executor executor = Executors.newSingleThreadExecutor();
+ FutureTask<Void> future = new FutureTask<Void>(new Runnable() {
+ public void run() {
+ requestScope.onEvent(new RequestStart(this));
+ Target target2 = null;
+ try {
+ target2 = (Target) targetComponent.getTargetInstance();
+ } catch (TargetException e) {
+ fail(e.getMessage());
+ }
+ assertFalse("foo".equals(target2.getString()));
+ assertFalse("foo".equals(source.getTarget().getString()));
+ source.getTarget().setString("bar");
+ assertEquals("bar", target2.getString());
+ assertEquals("bar", source.getTarget().getString());
+ requestScope.onEvent(new RequestEnd(this));
+ }
+ }, null);
+ executor.execute(future);
+ future.get();
+ assertEquals("foo", source.getTarget().getString());
+ requestScope.onEvent(new RequestEnd(this));
+ compositeScope.onEvent(new ComponentStop(this, null));
+ requestScope.stop();
+ compositeScope.stop();
+ }
+*/
+
+ /**
+ * Tests a composite-to-stateless scoped wire is setup properly by the runtime
+ */
+ public void testCompositeToStateless() throws Exception {
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ compositeScope, members, "target", Target.class, TargetImpl.class, statelessScope);
+
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ PojoWorkContextTunnel.setThreadWorkContext(workContext);
+ try {
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertFalse("foo".equals(source.getTarget().getString()));
+ Target target2 = (Target) targetComponent.getTargetInstance();
+ assertFalse("foo".equals(target2.getString()));
+ source.getTarget().setString("bar");
+ assertFalse("bar".equals(source.getTarget().getString()));
+ } finally {
+ PojoWorkContextTunnel.setThreadWorkContext(null);
+ }
+ }
+
+
+ /**
+ * Tests a session-to-session scoped wire
+ */
+/*
+ public void testSessionToSession() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ ScopeContainer sessionScope = new HttpSessionScopeContainer(ctx, null);
+ sessionScope.start();
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ sessionScope, members, "target", Target.class, TargetImpl.class, sessionScope);
+
+ Object session1 = new Object();
+ ctx.setIdentifier(Scope.SESSION, session1);
+ sessionScope.onEvent(new HttpSessionStart(this, session1));
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ source.getTarget().setString("foo");
+ source.getTarget().setString("foo");
+ assertEquals("foo", target.getString());
+
+ ctx.clearIdentifier(Scope.SESSION);
+ sessionScope.onEvent(new HttpSessionEnd(this, session1));
+
+ //second session
+ Object session2 = new Object();
+ ctx.setIdentifier(Scope.SESSION, session2);
+ sessionScope.onEvent(new HttpSessionStart(this, session2));
+
+ Source source2 = (Source) sourceComponent.getTargetInstance();
+ assertNotNull(source2);
+ Target target2 = (Target) targetComponent.getTargetInstance();
+
+ assertNotNull(target2);
+ assertNull(target2.getString());
+ assertEquals(null, source2.getTarget().getString());
+ source2.getTarget().setString("baz");
+ assertEquals("baz", source2.getTarget().getString());
+ assertEquals("baz", target2.getString());
+ ctx.clearIdentifier(Scope.SESSION);
+ sessionScope.onEvent(new HttpSessionEnd(this, session2));
+ sessionScope.stop();
+ }
+*/
+
+
+ /**
+ * Tests a session-to-composite scoped wire
+ */
+/*
+ public void testSessionToComposite() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ ScopeContainer compositeScope = new CompositeScopeContainer(null);
+ compositeScope.start();
+ ScopeContainer sessionScope = new HttpSessionScopeContainer(ctx, null);
+ sessionScope.start();
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ sessionScope, members, "target", Target.class, TargetImpl.class, compositeScope);
+ compositeScope.onEvent(new ComponentStart(this, null));
+ Object session1 = new Object();
+ ctx.setIdentifier(Scope.SESSION, session1);
+ sessionScope.onEvent(new HttpSessionStart(this, session1));
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertEquals("foo", source.getTarget().getString());
+ ctx.clearIdentifier(Scope.SESSION);
+ sessionScope.onEvent(new HttpSessionEnd(this, session1));
+
+ //second session
+ Object session2 = new Object();
+ ctx.setIdentifier(Scope.SESSION, session2);
+ sessionScope.onEvent(new HttpSessionStart(this, session2));
+
+ Target target2 = (Target) targetComponent.getTargetInstance();
+ Source source2 = (Source) sourceComponent.getTargetInstance();
+ assertEquals("foo", target2.getString());
+ assertEquals("foo", source2.getTarget().getString());
+ source2.getTarget().setString("baz");
+ assertEquals("baz", source2.getTarget().getString());
+ assertEquals("baz", target2.getString());
+ assertEquals("baz", target.getString());
+ ctx.clearIdentifier(Scope.SESSION);
+ sessionScope.onEvent(new HttpSessionEnd(this, session2));
+ compositeScope.stop();
+ sessionScope.stop();
+ }
+*/
+
+ /**
+ * Tests a session-to-request scoped wire is setup properly by the runtime
+ */
+/*
+ public void testSessionToRequest() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ final ScopeContainer requestScope = new RequestScopeContainer(ctx, null);
+ requestScope.start();
+ ScopeContainer sessionScope = new HttpSessionScopeContainer(ctx, null);
+ sessionScope.start();
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ sessionScope, members, "target", Target.class, TargetImpl.class, requestScope);
+ Object session1 = new Object();
+ ctx.setIdentifier(Scope.SESSION, session1);
+ sessionScope.onEvent(new HttpSessionStart(this, session1));
+ requestScope.onEvent(new RequestStart(this));
+ AtomicComponent sourceComponent = contexts.get("source");
+ final AtomicComponent targetComponent = contexts.get("target");
+ final Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertEquals("foo", source.getTarget().getString());
+
+ // spin off another request
+ Executor executor = Executors.newSingleThreadExecutor();
+ FutureTask<Void> future = new FutureTask<Void>(new Runnable() {
+ public void run() {
+ requestScope.onEvent(new RequestStart(this));
+ Target target2 = null;
+ try {
+ target2 = (Target) targetComponent.getTargetInstance();
+ } catch (TargetException e) {
+ fail(e.getMessage());
+ }
+ assertFalse("foo".equals(target2.getString()));
+ assertFalse("foo".equals(source.getTarget().getString()));
+ source.getTarget().setString("bar");
+ assertEquals("bar", target2.getString());
+ assertEquals("bar", source.getTarget().getString());
+ requestScope.onEvent(new RequestEnd(this));
+ }
+ }, null);
+ executor.execute(future);
+ future.get();
+ assertEquals("foo", source.getTarget().getString());
+ requestScope.onEvent(new RequestEnd(this));
+ ctx.clearIdentifier(Scope.SESSION);
+ sessionScope.onEvent(new HttpSessionEnd(this, session1));
+ requestScope.stop();
+ sessionScope.stop();
+ }
+*/
+
+
+ /**
+ * Tests a session-to-stateless scoped wire is setup properly by the runtime
+ */
+/*
+ public void testSessionToStateless() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ ScopeContainer sessionScope = new HttpSessionScopeContainer(ctx, null);
+ sessionScope.start();
+ ScopeContainer statelessScope = new StatelessScopeContainer(null);
+ statelessScope.start();
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ sessionScope, members, "target", Target.class, TargetImpl.class, statelessScope);
+
+ Object session1 = new Object();
+ ctx.setIdentifier(Scope.SESSION, session1);
+ sessionScope.onEvent(new HttpSessionStart(this, session1));
+
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertFalse("foo".equals(source.getTarget().getString()));
+ Target target2 = (Target) targetComponent.getTargetInstance();
+ assertFalse("foo".equals(target2.getString()));
+ source.getTarget().setString("bar");
+ assertFalse("bar".equals(source.getTarget().getString()));
+
+ ctx.clearIdentifier(Scope.SESSION);
+ sessionScope.onEvent(new HttpSessionEnd(this, session1));
+ sessionScope.stop();
+ statelessScope.stop();
+ }
+*/
+
+ /**
+ * Tests a request-to-request scoped wire is setup properly by the runtime
+ */
+/*
+ public void testRequestToRequest() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ final ScopeContainer requestScope = new RequestScopeContainer(ctx, null);
+ requestScope.start();
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ requestScope, members, "target", Target.class, TargetImpl.class, requestScope);
+ requestScope.onEvent(new RequestStart(this));
+
+ final AtomicComponent sourceComponent = contexts.get("source");
+ final AtomicComponent targetComponent = contexts.get("target");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertEquals("foo", source.getTarget().getString());
+
+ // spin off another request
+ Executor executor = Executors.newSingleThreadExecutor();
+ FutureTask<Void> future = new FutureTask<Void>(new Runnable() {
+ public void run() {
+ requestScope.onEvent(new RequestStart(this));
+ Source source2 = null;
+ Target target2 = null;
+ try {
+ source2 = (Source) sourceComponent.getTargetInstance();
+ target2 = (Target) targetComponent.getTargetInstance();
+ } catch (TargetException e) {
+ fail(e.getMessage());
+ }
+ assertFalse("foo".equals(target2.getString()));
+ assertFalse("foo".equals(source2.getTarget().getString()));
+ source2.getTarget().setString("bar");
+ assertEquals("bar", target2.getString());
+ assertEquals("bar", source2.getTarget().getString());
+ requestScope.onEvent(new RequestEnd(this));
+ }
+ }, null);
+ executor.execute(future);
+ future.get();
+ requestScope.onEvent(new RequestEnd(this));
+ requestScope.stop();
+ }
+*/
+
+ /**
+ * Tests a request-to-composite scoped wire
+ */
+/*
+ public void testRequestToComposite() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ final ScopeContainer requestScope = new RequestScopeContainer(ctx, null);
+ final ScopeContainer compositeScope = new CompositeScopeContainer(null);
+ requestScope.start();
+ compositeScope.start();
+ compositeScope.onEvent(new ComponentStart(this, null));
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ requestScope, members, "target", Target.class, TargetImpl.class, compositeScope);
+ requestScope.onEvent(new RequestStart(this));
+
+ final AtomicComponent sourceComponent = contexts.get("source");
+ final AtomicComponent targetComponent = contexts.get("target");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertEquals("foo", source.getTarget().getString());
+
+ // spin off another request
+ Executor executor = Executors.newSingleThreadExecutor();
+ FutureTask<Void> future = new FutureTask<Void>(new Runnable() {
+ public void run() {
+ requestScope.onEvent(new RequestStart(this));
+ Source source2 = null;
+ Target target2 = null;
+ try {
+ source2 = (Source) sourceComponent.getTargetInstance();
+ target2 = (Target) targetComponent.getTargetInstance();
+ } catch (TargetException e) {
+ fail(e.getMessage());
+ }
+ assertEquals("foo", target2.getString());
+ assertEquals("foo", source2.getTarget().getString());
+ source2.getTarget().setString("bar");
+ assertEquals("bar", target2.getString());
+ assertEquals("bar", source2.getTarget().getString());
+ requestScope.onEvent(new RequestEnd(this));
+ }
+ }, null);
+ executor.execute(future);
+ future.get();
+ assertEquals("bar", target.getString());
+
+ requestScope.onEvent(new RequestEnd(this));
+ requestScope.stop();
+ compositeScope.onEvent(new ComponentStop(this, null));
+ compositeScope.stop();
+ }
+*/
+
+ /**
+ * Tests a request-to-session scoped wire is setup properly by the runtime
+ */
+/*
+ public void testRequestToSession() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ final ScopeContainer requestScope = new RequestScopeContainer(ctx, null);
+ final ScopeContainer sessionScope = new HttpSessionScopeContainer(ctx, null);
+ requestScope.start();
+ sessionScope.start();
+
+ Object session1 = new Object();
+ ctx.setIdentifier(Scope.SESSION, session1);
+ sessionScope.onEvent(new HttpSessionStart(this, session1));
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ requestScope, members, "target", Target.class, TargetImpl.class, sessionScope);
+
+ final AtomicComponent sourceComponent = contexts.get("source");
+ final AtomicComponent targetComponent = contexts.get("target");
+ requestScope.onEvent(new RequestStart(this));
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertEquals("foo", source.getTarget().getString());
+
+ // spin off another request
+ Executor executor = Executors.newSingleThreadExecutor();
+ FutureTask<Void> future = new FutureTask<Void>(new Runnable() {
+ public void run() {
+ requestScope.onEvent(new RequestStart(this));
+ Source source2 = null;
+ Target target2 = null;
+ try {
+ source2 = (Source) sourceComponent.getTargetInstance();
+ target2 = (Target) targetComponent.getTargetInstance();
+ } catch (TargetException e) {
+ fail(e.getMessage());
+ }
+ assertEquals("foo", target2.getString());
+ assertEquals("foo", source2.getTarget().getString());
+ source2.getTarget().setString("bar");
+ assertEquals("bar", target2.getString());
+ assertEquals("bar", source2.getTarget().getString());
+ requestScope.onEvent(new RequestEnd(this));
+ }
+ }, null);
+ executor.execute(future);
+ future.get();
+ assertEquals("bar", target.getString());
+
+ requestScope.onEvent(new RequestEnd(this));
+ requestScope.stop();
+ ctx.clearIdentifier(Scope.SESSION);
+ sessionScope.onEvent(new HttpSessionEnd(this, session1));
+ sessionScope.stop();
+ }
+*/
+
+
+ /**
+ * Tests a request-to-stateless scoped wire is setup properly by the runtime
+ */
+/*
+ public void testRequestToStateless() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ ScopeContainer requestScope = new RequestScopeContainer(ctx, null);
+ requestScope.start();
+ ScopeContainer statelessScope = new StatelessScopeContainer(null);
+ statelessScope.start();
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ requestScope, members, "target", Target.class, TargetImpl.class, statelessScope);
+
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ requestScope.onEvent(new RequestStart(this));
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertFalse("foo".equals(source.getTarget().getString()));
+ Target target2 = (Target) targetComponent.getTargetInstance();
+ assertFalse("foo".equals(target2.getString()));
+ source.getTarget().setString("bar");
+ assertFalse("bar".equals(source.getTarget().getString()));
+ requestScope.onEvent(new RequestEnd(this));
+ requestScope.stop();
+ statelessScope.stop();
+ }
+*/
+
+
+ /**
+ * Tests a stateless-to-stateless scoped wire is setup properly by the runtime
+ */
+ public void testStatelessToStateless() throws Exception {
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ statelessScope, members, "target", Target.class, TargetImpl.class, statelessScope);
+
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ PojoWorkContextTunnel.setThreadWorkContext(workContext);
+ try {
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertFalse("foo".equals(source.getTarget().getString()));
+ Target target2 = (Target) targetComponent.getTargetInstance();
+ assertFalse("foo".equals(target2.getString()));
+ source.getTarget().setString("bar");
+ assertFalse("bar".equals(source.getTarget().getString()));
+ } finally {
+ PojoWorkContextTunnel.setThreadWorkContext(null);
+ }
+ }
+
+ /**
+ * Tests a stateless-to-request scoped wire is setup properly by the runtime
+ */
+/*
+ public void testStatelessToRequest() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ final ScopeContainer requestScope = new RequestScopeContainer(ctx, null);
+ requestScope.start();
+ ScopeContainer statelessScope = new StatelessScopeContainer(null);
+ statelessScope.start();
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ statelessScope, members, "target", Target.class, TargetImpl.class, requestScope);
+ requestScope.onEvent(new RequestStart(this));
+ AtomicComponent sourceComponent = contexts.get("source");
+ final AtomicComponent targetComponent = contexts.get("target");
+ final Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertEquals("foo", source.getTarget().getString());
+
+ // spin off another request
+ Executor executor = Executors.newSingleThreadExecutor();
+ FutureTask<Void> future = new FutureTask<Void>(new Runnable() {
+ public void run() {
+ requestScope.onEvent(new RequestStart(this));
+ Target target2 = null;
+ try {
+ target2 = (Target) targetComponent.getTargetInstance();
+ } catch (TargetException e) {
+ fail(e.getMessage());
+ }
+ assertFalse("foo".equals(target2.getString()));
+ assertFalse("foo".equals(source.getTarget().getString()));
+ source.getTarget().setString("bar");
+ assertEquals("bar", target2.getString());
+ assertEquals("bar", source.getTarget().getString());
+ requestScope.onEvent(new RequestEnd(this));
+ }
+ }, null);
+ executor.execute(future);
+ future.get();
+ requestScope.stop();
+ statelessScope.stop();
+ }
+*/
+
+ /**
+ * Tests a stateless-to-session scoped wire is setup properly by the runtime
+ */
+/*
+ public void testStatelessToSession() throws Exception {
+ WorkContext ctx = new WorkContextImpl();
+ ScopeContainer statelessScope = new StatelessScopeContainer(null);
+ statelessScope.start();
+ ScopeContainer sessionScope = new HttpSessionScopeContainer(ctx, null);
+ sessionScope.start();
+
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ statelessScope, members, "target", Target.class, TargetImpl.class, sessionScope);
+ Object session1 = new Object();
+ ctx.setIdentifier(Scope.SESSION, session1);
+ sessionScope.onEvent(new HttpSessionStart(this, session1));
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertEquals("foo", source.getTarget().getString());
+ ctx.clearIdentifier(Scope.SESSION);
+ sessionScope.onEvent(new HttpSessionEnd(this, session1));
+
+ //second session
+ Object session2 = new Object();
+ ctx.setIdentifier(Scope.SESSION, session2);
+ sessionScope.onEvent(new HttpSessionStart(this, session2));
+
+ Target target2 = (Target) targetComponent.getTargetInstance();
+ assertFalse("foo".equals(target2.getString()));
+
+ assertFalse("foo".equals(source.getTarget().getString()));
+ source.getTarget().setString("bar");
+ assertEquals("bar", target2.getString());
+ assertEquals("bar", source.getTarget().getString());
+ sessionScope.onEvent(new HttpSessionEnd(this, session2));
+
+ ctx.clearIdentifier(Scope.SESSION);
+ sessionScope.stop();
+ statelessScope.stop();
+ }
+*/
+
+
+ /**
+ * Tests a stateless-to-composite scoped wire is setup properly by the runtime
+ */
+ public void testStatelessToComposite() throws Exception {
+ Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class,
+ statelessScope, members, "target", Target.class, TargetImpl.class, compositeScope);
+ AtomicComponent sourceComponent = contexts.get("source");
+ AtomicComponent targetComponent = contexts.get("target");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = (Target) targetComponent.getTargetInstance();
+ PojoWorkContextTunnel.setThreadWorkContext(workContext);
+ try {
+ assertNull(source.getTarget().getString());
+ assertNull(target.getString());
+ target.setString("foo");
+ assertTrue(Proxy.isProxyClass(source.getTarget().getClass()));
+ assertEquals("foo", source.getTarget().getString());
+ } finally {
+ PojoWorkContextTunnel.setThreadWorkContext(null);
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ groupId = URI.create("composite");
+ members = new HashMap<String, Member>();
+ Method[] methods = SourceImpl.class.getMethods();
+ for (Method method : methods) {
+ if (method.getName().startsWith("set")) {
+ members.put(JavaIntrospectionHelper.toPropertyName(method.getName()), method);
+ }
+ }
+
+ statelessScope = new StatelessScopeContainer(null);
+ statelessScope.start();
+ compositeScope = new CompositeScopeContainer(null);
+ compositeScope.start();
+ compositeScope.startContext(groupId, groupId);
+
+ workContext = EasyMock.createMock(WorkContext.class);
+ EasyMock.expect(workContext.getIdentifier(Scope.COMPOSITE)).andStubReturn(URI.create("composite"));
+ EasyMock.expect(workContext.getIdentifier(Scope.STATELESS)).andStubReturn(null);
+ EasyMock.expect(workContext.getCorrelationId()).andStubReturn(null);
+ EasyMock.expect(workContext.getCallbackUris()).andStubReturn(null);
+ EasyMock.replay(workContext);
+ }
+
+
+}
+
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/ReferenceInjectionTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/ReferenceInjectionTestCase.java
new file mode 100644
index 0000000000..9688906a15
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/ReferenceInjectionTestCase.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.core.integration.wire;
+
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.HashMap;
+import java.util.Map;
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ScopeContainer;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.scope.CompositeScopeContainer;
+import org.apache.tuscany.core.integration.mock.MockFactory;
+import org.apache.tuscany.core.mock.component.Source;
+import org.apache.tuscany.core.mock.component.SourceImpl;
+import org.apache.tuscany.core.mock.component.Target;
+import org.apache.tuscany.core.mock.component.TargetImpl;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public class ReferenceInjectionTestCase extends TestCase {
+ private Map<String, Member> members;
+
+ public void testProxiedReferenceInjection() throws Exception {
+ ScopeContainer scope = new CompositeScopeContainer(null);
+ scope.start();
+ URI groupId = URI.create("composite");
+ scope.startContext(groupId, groupId);
+ Map<String, AtomicComponent> components = MockFactory.createWiredComponents("source",
+ SourceImpl.class,
+ scope,
+ members,
+ "target",
+ Target.class,
+ TargetImpl.class,
+ scope);
+ AtomicComponent sourceComponent = components.get("source");
+ Source source = (Source) sourceComponent.getTargetInstance();
+ Target target = source.getTarget();
+ assertTrue(Proxy.isProxyClass(target.getClass()));
+
+ assertNotNull(target);
+ scope.stop();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ members = new HashMap<String, Member>();
+ Method m = SourceImpl.class.getMethod("setTarget", Target.class);
+ members.put("target", m);
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderNoBindingTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderNoBindingTestCase.java
new file mode 100644
index 0000000000..85ab48dde9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderNoBindingTestCase.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.core.loader;
+
+import java.net.URI;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.java.JavaImplementation;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ComponentLoaderNoBindingTestCase extends TestCase {
+ private static final QName COMPONENT = new QName(SCA_NS, "component");
+ private ComponentLoader loader;
+ private XMLStreamReader reader;
+ private ServiceDefinition service;
+ private ReferenceDefinition reference;
+ private DeploymentContext ctx;
+
+ public void testNoServiceBinding() throws Exception {
+ loader.load(null, reader, ctx);
+ assert service.getBindings().isEmpty();
+ }
+
+ public void testNoReferenceBinding() throws Exception {
+ loader.load(null, reader, ctx);
+ assert reference.getBindings().isEmpty();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ URI componentId = URI.create("sca://localhost/parent/");
+ service = new ServiceDefinition();
+ service.setUri(URI.create("service"));
+ reference = new ReferenceDefinition();
+ reference.setUri(URI.create("#ref"));
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ type.add(service);
+ type.add(reference);
+ JavaImplementation impl = new JavaImplementation(null, type);
+ LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class);
+ EasyMock.expect(registry.load(
+ (ModelObject) EasyMock.isNull(),
+ EasyMock.isA(XMLStreamReader.class),
+ EasyMock.isA(DeploymentContext.class))).andReturn(impl);
+ registry.loadComponentType(
+ EasyMock.isA(Implementation.class),
+ EasyMock.isA(DeploymentContext.class));
+ EasyMock.replay(registry);
+ loader = new ComponentLoader(registry, null);
+ reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getName()).andReturn(COMPONENT).atLeastOnce();
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn("foo");
+ EasyMock.expect(reader.getAttributeValue(null, "initLevel")).andReturn("0");
+ EasyMock.expect(reader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("autowire")))
+ .andReturn(null);
+ EasyMock.expect(reader.getAttributeValue(null, "runtimeId")).andReturn(null);
+ EasyMock.expect(reader.nextTag()).andReturn(1);
+ EasyMock.replay(reader);
+ ctx = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(ctx.getClassLoader()).andReturn(null);
+ EasyMock.expect(ctx.isAutowire()).andReturn(false);
+ EasyMock.expect(ctx.getScdlLocation()).andReturn(null);
+ EasyMock.expect(ctx.getComponentId()).andReturn(componentId);
+ EasyMock.replay(ctx);
+
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderNoReferenceTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderNoReferenceTestCase.java
new file mode 100644
index 0000000000..a644edb6d2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderNoReferenceTestCase.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.core.loader;
+
+import java.net.URI;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.UndefinedReferenceException;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.java.JavaImplementation;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.isNull;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ComponentLoaderNoReferenceTestCase extends TestCase {
+ private static final QName COMPONENT = new QName(SCA_NS, "component");
+ private static final QName REFERENCE = new QName(SCA_NS, "reference");
+ private static final String NAME = "testComponent";
+ private ComponentLoader loader;
+ private XMLStreamReader reader;
+ private DeploymentContext ctx;
+
+ /**
+ * Verifies an error is thrown when an attempt to configure a non-existent reference in SCDL is made
+ */
+ public void testNoReferenceOnComponentType() throws LoaderException, XMLStreamException {
+ try {
+ loader.load(null, reader, ctx);
+ fail();
+ } catch (UndefinedReferenceException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ URI componentId = URI.create("sca://localhost/parent/");
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ JavaImplementation impl = new JavaImplementation(null, type);
+ reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getName()).andReturn(COMPONENT);
+ EasyMock.expect(reader.getAttributeValue((String) EasyMock.isNull(), EasyMock.isA(String.class)))
+ .andReturn(NAME);
+ EasyMock.expect(reader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("initLevel")))
+ .andReturn(null);
+ EasyMock.expect(reader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("autowire")))
+ .andReturn(null);
+ EasyMock.expect(reader.getAttributeValue(EasyMock.isA(String.class), EasyMock.isA(String.class)))
+ .andReturn(null);
+ EasyMock.expect(reader.nextTag()).andReturn(0);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(REFERENCE);
+ EasyMock.expect(reader.getAttributeValue((String) isNull(), EasyMock.eq("name")))
+ .andReturn("noreference");
+ EasyMock.expect(reader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("autowire")))
+ .andReturn(null);
+ EasyMock.expect(reader.getAttributeValue(null, "runtimeId")).andReturn(null);
+ EasyMock.expect(reader.getAttributeValue(null, "target")).andReturn("text");
+
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(reader);
+ LoaderRegistry mockRegistry = EasyMock.createMock(LoaderRegistry.class);
+ mockRegistry.loadComponentType(
+ EasyMock.isA(Implementation.class),
+ EasyMock.isA(DeploymentContext.class));
+ EasyMock.expect(mockRegistry.load(
+ (ModelObject) isNull(),
+ EasyMock.isA(XMLStreamReader.class),
+ EasyMock.isA(DeploymentContext.class))).andReturn(impl);
+ EasyMock.replay(mockRegistry);
+ loader = new ComponentLoader(mockRegistry, null);
+ ctx = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(ctx.getClassLoader()).andReturn(null);
+ EasyMock.expect(ctx.isAutowire()).andReturn(false);
+ EasyMock.expect(ctx.getScdlLocation()).andReturn(null);
+ EasyMock.expect(ctx.getComponentId()).andReturn(componentId);
+ EasyMock.replay(ctx);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderPropertyTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderPropertyTestCase.java
new file mode 100644
index 0000000000..c6f65481b7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderPropertyTestCase.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.core.loader;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.MissingRequiredPropertyException;
+import org.apache.tuscany.spi.loader.PropertyObjectFactory;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.java.JavaImplementation;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ComponentLoaderPropertyTestCase extends TestCase {
+
+ private TestLoader loader;
+
+ /**
+ * Verifies that an optional property not cofigured in an assembly will avoid having a PropertyValue created for it
+ * so that the runtime does not erroneously inject null values
+ */
+ public void testOptionalPropertyNotConfigured() throws LoaderException, XMLStreamException {
+ PojoComponentType<?, ?, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ Property property = new Property();
+ property.setName("name");
+ type.add(property);
+ JavaImplementation impl = new JavaImplementation(null, type);
+ impl.setComponentType(type);
+ ComponentDefinition<Implementation<?>> defn = new ComponentDefinition<Implementation<?>>(impl);
+ loader.populatePropertyValues(defn);
+ assertTrue(defn.getPropertyValues().isEmpty());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ LoaderRegistry mockRegistry = EasyMock.createMock(LoaderRegistry.class);
+ PropertyObjectFactory mockPropertyFactory = EasyMock.createMock(PropertyObjectFactory.class);
+ loader = new TestLoader(mockRegistry, mockPropertyFactory);
+ }
+
+ private class TestLoader extends ComponentLoader {
+
+ public TestLoader(LoaderRegistry registry, PropertyObjectFactory propertyFactory) {
+ super(registry, propertyFactory);
+ }
+
+ @Override
+ public void populatePropertyValues(ComponentDefinition<Implementation<?>> componentDefinition)
+ throws MissingRequiredPropertyException {
+ super.populatePropertyValues(componentDefinition);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderRefTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderRefTestCase.java
new file mode 100644
index 0000000000..07ef7d6348
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderRefTestCase.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.core.loader;
+
+import java.net.URI;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.java.JavaImplementation;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ComponentLoaderRefTestCase extends TestCase {
+ private ComponentLoader loader;
+ private final URI componentId = URI.create("sca://localhost/parent/");
+ private DeploymentContext context;
+
+ public void testLoadReferenceNoFragment() throws LoaderException, XMLStreamException {
+ PojoComponentType<?, MockReferenceDefinition, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, MockReferenceDefinition, Property<?>>();
+ MockReferenceDefinition reference = new MockReferenceDefinition();
+ reference.setUri(URI.create("#reference"));
+ type.add(reference);
+ JavaImplementation impl = new JavaImplementation();
+ impl.setComponentType(type);
+ ComponentDefinition<?> definition = new ComponentDefinition<JavaImplementation>(impl);
+ definition.setUri(URI.create("component"));
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn("reference");
+ EasyMock.expect(reader.getAttributeValue(null, "target")).andReturn("target");
+ EasyMock.expect(reader.getAttributeValue(null, "autowire")).andReturn(null);
+ EasyMock.replay(reader);
+ loader.loadReference(reader, definition, context);
+ ReferenceTarget target = definition.getReferenceTargets().get("reference");
+ assertEquals(1, target.getTargets().size());
+ URI uri = target.getTargets().get(0);
+ assertEquals(componentId.resolve("target"), uri);
+ assertNull(uri.getFragment());
+ EasyMock.verify(reader);
+ }
+
+ public void testLoadReferenceWithFragment() throws LoaderException, XMLStreamException {
+ PojoComponentType<?, MockReferenceDefinition, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, MockReferenceDefinition, Property<?>>();
+ MockReferenceDefinition reference = new MockReferenceDefinition();
+ reference.setUri(URI.create("#reference"));
+ type.add(reference);
+ JavaImplementation impl = new JavaImplementation();
+ impl.setComponentType(type);
+ ComponentDefinition<?> definition = new ComponentDefinition<JavaImplementation>(impl);
+ definition.setUri(URI.create("component"));
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn("reference");
+ EasyMock.expect(reader.getAttributeValue(null, "target")).andReturn("target/fragment");
+ EasyMock.expect(reader.getAttributeValue(null, "autowire")).andReturn(null);
+ EasyMock.replay(reader);
+ loader.loadReference(reader, definition, context);
+ ReferenceTarget target = definition.getReferenceTargets().get("reference");
+ assertEquals(1, target.getTargets().size());
+ URI uri = target.getTargets().get(0);
+ assertEquals(componentId.resolve("target#fragment"), uri);
+ EasyMock.verify(reader);
+ }
+
+ public void testLoadReferenceWithMultipleTargetUris() throws LoaderException, XMLStreamException {
+ PojoComponentType<?, MockReferenceDefinition, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, MockReferenceDefinition, Property<?>>();
+ MockReferenceDefinition reference = new MockReferenceDefinition();
+ reference.setUri(URI.create("#reference"));
+ type.add(reference);
+ JavaImplementation impl = new JavaImplementation();
+ impl.setComponentType(type);
+ ComponentDefinition<?> definition = new ComponentDefinition<JavaImplementation>(impl);
+ definition.setUri(URI.create("component"));
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn("reference");
+ EasyMock.expect(reader.getAttributeValue(null, "target")).andReturn("target1/fragment1 target2/fragment2");
+ EasyMock.expect(reader.getAttributeValue(null, "autowire")).andReturn(null);
+ EasyMock.replay(reader);
+ loader.loadReference(reader, definition, context);
+ ReferenceTarget target = definition.getReferenceTargets().get("reference");
+ assertEquals(2, target.getTargets().size());
+ URI uri1 = target.getTargets().get(0);
+ assertEquals(componentId.resolve("target1#fragment1"), uri1);
+ URI uri2 = target.getTargets().get(1);
+ assertEquals(componentId.resolve("target2#fragment2"), uri2);
+ EasyMock.verify(reader);
+ }
+
+ public void testLoadReferenceAutowire() throws LoaderException, XMLStreamException {
+ PojoComponentType<?, MockReferenceDefinition, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, MockReferenceDefinition, Property<?>>();
+ MockReferenceDefinition reference = new MockReferenceDefinition();
+ reference.setUri(URI.create("#reference"));
+ type.add(reference);
+ JavaImplementation impl = new JavaImplementation();
+ impl.setComponentType(type);
+ ComponentDefinition<?> definition = new ComponentDefinition<JavaImplementation>(impl);
+ definition.setUri(URI.create("component"));
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn("reference");
+ EasyMock.expect(reader.getAttributeValue(null, "target")).andReturn("target/fragment");
+ EasyMock.expect(reader.getAttributeValue(null, "autowire")).andReturn("true");
+ EasyMock.replay(reader);
+ loader.loadReference(reader, definition, context);
+ ReferenceTarget target = definition.getReferenceTargets().get("reference");
+ assertTrue(target.isAutowire());
+ EasyMock.verify(reader);
+ }
+
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ LoaderRegistry mockRegistry = EasyMock.createMock(LoaderRegistry.class);
+ loader = new ComponentLoader(mockRegistry, null);
+ Component parent = EasyMock.createNiceMock(Component.class);
+ EasyMock.expect(parent.getUri()).andReturn(componentId).atLeastOnce();
+ EasyMock.replay(parent);
+
+ context = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(context.getComponentId()).andReturn(componentId);
+ EasyMock.replay(context);
+ }
+
+ private class MockReferenceDefinition extends ReferenceDefinition {
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderTestCase.java
new file mode 100644
index 0000000000..444f2894a0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderTestCase.java
@@ -0,0 +1,249 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.loader;
+
+import java.net.URI;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.PropertyObjectFactory;
+import org.apache.tuscany.spi.loader.UnrecognizedElementException;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.java.JavaImplementation;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isNull;
+import static org.easymock.EasyMock.replay;
+import org.easymock.IAnswer;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ComponentLoaderTestCase extends TestCase {
+ private static final QName COMPONENT = new QName(SCA_NS, "component");
+ private static final String COMPONENT_NAME = "sca://localhost/parent/";
+ private static final String NAME = "testComponent";
+ private JavaImplementation impl;
+
+ private XMLStreamReader mockReader;
+ private LoaderRegistry mockRegistry;
+ private PropertyObjectFactory mockPropertyFactory;
+ private ComponentLoader loader;
+ private Component parent;
+ private DeploymentContext ctx;
+ private URI componentId;
+
+ public void testEmptyComponent() throws LoaderException, XMLStreamException {
+ EasyMock.expect(mockReader.getName()).andReturn(COMPONENT).atLeastOnce();
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.isA(String.class)))
+ .andReturn(NAME);
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("initLevel")))
+ .andReturn(null);
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("autowire")))
+ .andReturn(null);
+ EasyMock.expect(mockReader.getAttributeValue(null, "runtimeId")).andReturn(null);
+ EasyMock.expect(mockReader.getAttributeValue(EasyMock.isA(String.class), EasyMock.isA(String.class)))
+ .andReturn(null);
+ EasyMock.expect(mockReader.nextTag()).andReturn(0);
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(mockReader);
+ mockRegistry.loadComponentType(
+ EasyMock.isA(Implementation.class),
+ EasyMock.isA(DeploymentContext.class));
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ @SuppressWarnings("unchecked")
+ public Object answer() throws Throwable {
+ Implementation impl = (Implementation) EasyMock.getCurrentArguments()[0];
+ impl.setComponentType(new PojoComponentType());
+ return impl;
+ }
+ });
+
+ EasyMock.expect(mockRegistry.load(
+ (ModelObject) isNull(),
+ EasyMock.eq(mockReader),
+ EasyMock.isA(DeploymentContext.class))).andReturn(impl);
+ EasyMock.replay(mockRegistry);
+ ComponentDefinition component = loader.load(null, mockReader, ctx);
+ assertEquals(COMPONENT_NAME + NAME, component.getUri().toString());
+ assertNull(component.getInitLevel());
+ }
+
+ public void testAutowire() throws LoaderException, XMLStreamException {
+ EasyMock.expect(mockReader.getName()).andReturn(COMPONENT).atLeastOnce();
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.isA(String.class)))
+ .andReturn(NAME);
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("initLevel")))
+ .andReturn(null);
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("autowire")))
+ .andReturn("true");
+ EasyMock.expect(mockReader.getAttributeValue(null, "runtimeId")).andReturn(null);
+ EasyMock.expect(mockReader.nextTag()).andReturn(0);
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(mockReader);
+
+ mockRegistry.loadComponentType(
+ EasyMock.isA(Implementation.class),
+ EasyMock.isA(DeploymentContext.class));
+
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ @SuppressWarnings("unchecked")
+ public Object answer() throws Throwable {
+ Implementation impl = (Implementation) EasyMock.getCurrentArguments()[0];
+ impl.setComponentType(new PojoComponentType());
+ return impl;
+ }
+ });
+ EasyMock.expect(mockRegistry.load(
+ (ModelObject) isNull(),
+ EasyMock.eq(mockReader),
+ EasyMock.isA(DeploymentContext.class))).andReturn(impl);
+ EasyMock.replay(mockRegistry);
+
+ ComponentDefinition component = loader.load(null, mockReader, ctx);
+
+ assertTrue(component.getAutowire());
+ }
+
+ public void testInitValue20() throws LoaderException, XMLStreamException {
+ EasyMock.expect(mockReader.getName()).andReturn(COMPONENT).atLeastOnce();
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.isA(String.class)))
+ .andReturn(NAME);
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("initLevel")))
+ .andReturn("20");
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("autowire")))
+ .andReturn(null);
+ EasyMock.expect(mockReader.getAttributeValue(null, "runtimeId")).andReturn(null);
+ EasyMock.expect(mockReader.nextTag()).andReturn(0);
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(mockReader);
+
+ mockRegistry.loadComponentType(
+ EasyMock.isA(Implementation.class),
+ EasyMock.isA(DeploymentContext.class));
+
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ @SuppressWarnings("unchecked")
+ public Object answer() throws Throwable {
+ Implementation impl = (Implementation) EasyMock.getCurrentArguments()[0];
+ impl.setComponentType(new PojoComponentType());
+ return impl;
+ }
+ });
+ EasyMock.expect(mockRegistry.load(
+ (ModelObject) isNull(),
+ EasyMock.eq(mockReader),
+ EasyMock.isA(DeploymentContext.class))).andReturn(impl);
+ EasyMock.replay(mockRegistry);
+
+ ComponentDefinition component = loader.load(null, mockReader, ctx);
+ assertEquals(COMPONENT_NAME + NAME, component.getUri().toString());
+ assertEquals(Integer.valueOf(20), component.getInitLevel());
+ }
+
+ public void testLoadPropertyWithSource() throws LoaderException, XMLStreamException {
+ PojoComponentType<?, ?, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ Property property = new Property();
+ property.setName("name");
+ type.add(property);
+ JavaImplementation impl = new JavaImplementation();
+ impl.setComponentType(type);
+ ComponentDefinition<?> defn = new ComponentDefinition<JavaImplementation>(impl);
+ XMLStreamReader reader = createMock(XMLStreamReader.class);
+ expect(reader.getAttributeValue(null, "name")).andReturn("name");
+ expect(reader.getAttributeValue(null, "source")).andReturn("$source");
+ expect(reader.getAttributeValue(null, "file")).andReturn(null);
+ expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ replay(reader);
+ loader.loadProperty(reader, defn, null);
+ assertEquals("$source", defn.getPropertyValues().get("name").getSource());
+ EasyMock.verify(reader);
+ }
+
+ public void testUnrecognizedElement() throws LoaderException, XMLStreamException {
+ EasyMock.expect(mockReader.getName()).andReturn(COMPONENT);
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.isA(String.class)))
+ .andReturn(NAME);
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("initLevel")))
+ .andReturn(null);
+ EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("autowire")))
+ .andReturn(null);
+ EasyMock.expect(mockReader.getAttributeValue(null, "runtimeId")).andReturn(null);
+ EasyMock.expect(mockReader.getAttributeValue(EasyMock.isA(String.class), EasyMock.isA(String.class)))
+ .andReturn(null);
+ EasyMock.expect(mockReader.nextTag()).andReturn(0);
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(mockReader.getName()).andReturn(new QName("foo", "bar"));
+ EasyMock.replay(mockReader);
+ mockRegistry.loadComponentType(
+ EasyMock.isA(Implementation.class),
+ EasyMock.isA(DeploymentContext.class));
+
+ EasyMock.expect(mockRegistry.load(
+ (ModelObject) isNull(),
+ EasyMock.eq(mockReader),
+ EasyMock.isA(DeploymentContext.class))).andReturn(impl);
+ EasyMock.replay(mockRegistry);
+ try {
+ loader.load(null, mockReader, ctx);
+ fail();
+ } catch (UnrecognizedElementException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ componentId = URI.create(COMPONENT_NAME);
+ impl = new JavaImplementation();
+ mockReader = EasyMock.createMock(XMLStreamReader.class);
+ mockRegistry = EasyMock.createMock(LoaderRegistry.class);
+ mockPropertyFactory = EasyMock.createMock(PropertyObjectFactory.class);
+ loader = new ComponentLoader(mockRegistry, mockPropertyFactory);
+ parent = EasyMock.createNiceMock(Component.class);
+ URI uri = URI.create("foo");
+ EasyMock.expect(parent.getUri()).andReturn(uri).atLeastOnce();
+ EasyMock.replay(parent);
+
+ ctx = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(ctx.isAutowire()).andReturn(false);
+ EasyMock.expect(ctx.getClassLoader()).andReturn(null);
+ EasyMock.expect(ctx.getScdlLocation()).andReturn(null);
+ EasyMock.expect(ctx.getComponentId()).andReturn(componentId);
+ EasyMock.replay(ctx);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderValidationTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderValidationTestCase.java
new file mode 100644
index 0000000000..fdfdaeaa7f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderValidationTestCase.java
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.loader;
+
+import java.net.URI;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.MissingReferenceException;
+import org.apache.tuscany.spi.loader.PropertyObjectFactory;
+import org.apache.tuscany.spi.loader.ReferenceMultiplicityViolationException;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.Multiplicity;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.implementation.java.JavaImplementation;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ComponentLoaderValidationTestCase extends TestCase {
+
+ private ComponentLoaderValidationTestCase.TestLoader loader;
+
+ public void testValidation() throws LoaderException, XMLStreamException {
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ReferenceDefinition refDefinition = new ReferenceDefinition();
+ refDefinition.setUri(URI.create("#name"));
+ type.add(refDefinition);
+ JavaImplementation impl = new JavaImplementation(null, type);
+ ComponentDefinition<Implementation<?>> defn = new ComponentDefinition<Implementation<?>>(impl);
+ ReferenceTarget target = new ReferenceTarget();
+ target.setReferenceName(URI.create("#name"));
+ defn.add(target);
+ loader.validate(defn);
+ }
+
+ public void testReferenceNotSet() throws LoaderException, XMLStreamException {
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ReferenceDefinition refDefinition = new ReferenceDefinition();
+ refDefinition.setUri(URI.create("#name"));
+ refDefinition.setRequired(true);
+ type.add(refDefinition);
+ JavaImplementation impl = new JavaImplementation(null, type);
+ ComponentDefinition<Implementation<?>> defn = new ComponentDefinition<Implementation<?>>(impl);
+ try {
+ loader.validate(defn);
+ fail();
+ } catch (MissingReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testNotRequiredReference() throws LoaderException, XMLStreamException {
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ReferenceDefinition refDefinition = new ReferenceDefinition();
+ refDefinition.setUri(URI.create("#name"));
+ refDefinition.setRequired(false);
+ type.add(refDefinition);
+ JavaImplementation impl = new JavaImplementation(null, type);
+ ComponentDefinition<Implementation<?>> defn = new ComponentDefinition<Implementation<?>>(impl);
+ loader.validate(defn);
+ }
+
+ public void testReferenceMultiplicity() throws LoaderException, XMLStreamException {
+ PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new PojoComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ReferenceDefinition refDefinition = new ReferenceDefinition();
+ URI uri = URI.create("#r1");
+ refDefinition.setUri(uri);
+ refDefinition.setRequired(true);
+ refDefinition.setMultiplicity(Multiplicity.ONE_N);
+ type.add(refDefinition);
+ JavaImplementation impl = new JavaImplementation(null, type);
+ ComponentDefinition<Implementation<?>> defn = new ComponentDefinition<Implementation<?>>(impl);
+ ReferenceTarget target = new ReferenceTarget();
+ target.setReferenceName(uri);
+ target.addTarget(URI.create("c1"));
+ target.addTarget(URI.create("c2"));
+ defn.add(target);
+ loader.validate(defn);
+
+ refDefinition.setMultiplicity(Multiplicity.ZERO_ONE);
+ try {
+ loader.validate(defn);
+ fail();
+ } catch (ReferenceMultiplicityViolationException e) {
+ // Expected
+ }
+
+ refDefinition.setMultiplicity(Multiplicity.ZERO_N);
+ loader.validate(defn);
+
+ refDefinition.setMultiplicity(Multiplicity.ONE_ONE);
+ try {
+ loader.validate(defn);
+ fail();
+ } catch (ReferenceMultiplicityViolationException e) {
+ // Expected
+ }
+
+ target.getTargets().clear();
+ refDefinition.setMultiplicity(Multiplicity.ONE_ONE);
+ try {
+ loader.validate(defn);
+ fail();
+ } catch (ReferenceMultiplicityViolationException e) {
+ // Expected
+ }
+ refDefinition.setMultiplicity(Multiplicity.ONE_N);
+ try {
+ loader.validate(defn);
+ fail();
+ } catch (ReferenceMultiplicityViolationException e) {
+ // Expected
+ }
+ refDefinition.setMultiplicity(Multiplicity.ZERO_N);
+ loader.validate(defn);
+ refDefinition.setMultiplicity(Multiplicity.ZERO_ONE);
+ loader.validate(defn);
+
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ LoaderRegistry mockRegistry = EasyMock.createMock(LoaderRegistry.class);
+ PropertyObjectFactory mockPropertyFactory = EasyMock.createMock(PropertyObjectFactory.class);
+ loader = new ComponentLoaderValidationTestCase.TestLoader(mockRegistry, mockPropertyFactory);
+ }
+
+ private class TestLoader extends ComponentLoader {
+
+ public TestLoader(LoaderRegistry registry, PropertyObjectFactory propertyFactory) {
+ super(registry, propertyFactory);
+ }
+
+ @Override
+ protected void validate(ComponentDefinition<Implementation<?>> definition) throws LoaderException {
+ super.validate(definition);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentTypeElementLoaderTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentTypeElementLoaderTestCase.java
new file mode 100644
index 0000000000..9948019b7b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentTypeElementLoaderTestCase.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.core.loader;
+
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ComponentTypeElementLoaderTestCase extends TestCase {
+
+ public void testSpecializedComponentTypePassedIn() throws Exception {
+ ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ComponentTypeElementLoader loader = new ComponentTypeElementLoader(null);
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getName()).andReturn(ComponentTypeElementLoader.COMPONENT_TYPE);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(reader);
+ // verify that the exact component type instance is returned. Some StAXElementLoader implementations may chose
+ // to copy the original instance but ComponentTypeElementLoader does not since it has no knowledge of the
+ // specialized instance
+ ModelObject object = loader.load(type, reader, null);
+ assertEquals(object, type);
+ }
+
+ public void testComponentTypePassedAsContext() throws Exception {
+ ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class);
+ EasyMock.expect(registry.load(
+ EasyMock.isA(ComponentType.class),
+ EasyMock.isA(XMLStreamReader.class),
+ (DeploymentContext) EasyMock.isNull())).andReturn(type);
+ EasyMock.replay(registry);
+ ComponentTypeElementLoader loader = new ComponentTypeElementLoader(registry);
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getName()).andReturn(ComponentTypeElementLoader.COMPONENT_TYPE);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(new QName("foo", "foo"));
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(reader);
+
+ loader.load(type, reader, null);
+ EasyMock.verify(registry);
+ }
+
+ public void testNonSpecializedComponentTypePassedIn() throws Exception {
+ ComponentTypeElementLoader loader = new ComponentTypeElementLoader(null);
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.getName()).andReturn(ComponentTypeElementLoader.COMPONENT_TYPE);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(reader);
+ ModelObject object = loader.load(null, reader, null);
+ assertEquals(ComponentType.class, object.getClass());
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/DependencyLoaderTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/DependencyLoaderTestCase.java
new file mode 100644
index 0000000000..41b56d2bab
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/DependencyLoaderTestCase.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.core.loader;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.UnrecognizedElementException;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import org.apache.tuscany.core.implementation.composite.Dependency;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DependencyLoaderTestCase extends TestCase {
+ private static final String NS = "http://tuscany.apache.org/xmlns/sca/2.0-alpha";
+ private static final QName DEPENDENCY = new QName(NS, "dependency");
+ private static final QName GROUP = new QName(NS, "group");
+ private static final QName NAME = new QName(NS, "name");
+ private static final QName VERSION = new QName(NS, "version");
+ private static final QName CLASSIFIER = new QName(NS, "classifier");
+ private static final QName TYPE = new QName(NS, "type");
+
+ public void testLoad() throws Exception {
+ LoaderRegistry registry = EasyMock.createNiceMock(LoaderRegistry.class);
+ EasyMock.replay(registry);
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.nextTag()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(GROUP);
+ EasyMock.expect(reader.getElementText()).andReturn("group");
+ EasyMock.expect(reader.nextTag()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(NAME);
+ EasyMock.expect(reader.getElementText()).andReturn("name");
+ EasyMock.expect(reader.nextTag()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(VERSION);
+ EasyMock.expect(reader.getElementText()).andReturn("1");
+ EasyMock.expect(reader.nextTag()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(CLASSIFIER);
+ EasyMock.expect(reader.getElementText()).andReturn("classifier");
+ EasyMock.expect(reader.nextTag()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(TYPE);
+ EasyMock.expect(reader.getElementText()).andReturn("type");
+ EasyMock.expect(reader.nextTag()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(reader);
+ DependencyLoader loader = new DependencyLoader(registry);
+ Dependency dependency = loader.load(null, reader, null);
+ assertEquals("group", dependency.getArtifact().getGroup());
+ assertEquals("name", dependency.getArtifact().getName());
+ assertEquals("1", dependency.getArtifact().getVersion());
+ assertEquals("classifier", dependency.getArtifact().getClassifier());
+ assertEquals("type", dependency.getArtifact().getType());
+ }
+
+ public void testLoaderRegister() {
+ LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class);
+ registry.registerLoader(EasyMock.eq(DEPENDENCY), EasyMock.isA(DependencyLoader.class));
+ EasyMock.replay(registry);
+ DependencyLoader loader = new DependencyLoader(registry);
+ loader.start();
+ EasyMock.verify(registry);
+ }
+
+ public void testUnrecognizedElement() throws Exception {
+ LoaderRegistry registry = EasyMock.createNiceMock(LoaderRegistry.class);
+ EasyMock.replay(registry);
+ XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+ EasyMock.expect(reader.nextTag()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.getName()).andReturn(new QName("foo", "bar"));
+ EasyMock.expect(reader.getElementText()).andReturn("foo");
+ EasyMock.expect(reader.getLocation()).andReturn(new MockLocation());
+ EasyMock.replay(reader);
+ DependencyLoader loader = new DependencyLoader(registry);
+ try {
+ loader.load(null, reader, null);
+ fail();
+ } catch (UnrecognizedElementException e) {
+ // expected
+ }
+ }
+
+ private class MockLocation implements 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;
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/IncludeLoaderTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/IncludeLoaderTestCase.java
new file mode 100644
index 0000000000..671c3a74d9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/IncludeLoaderTestCase.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.core.loader;
+
+import java.net.URI;
+import java.net.URL;
+import javax.xml.namespace.QName;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.isNull;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import org.osoa.sca.Constants;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.MissingIncludeException;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.Include;
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class IncludeLoaderTestCase extends TestCase {
+ private static final QName INCLUDE = new QName(Constants.SCA_NS, "include");
+
+ private LoaderRegistry registry;
+ private IncludeLoader loader;
+ private XMLStreamReader reader;
+ private DeploymentContext context;
+ private URL base;
+ private URL includeURL;
+ private ClassLoader cl;
+ private URI componentId;
+
+ public void testNoLocation() throws LoaderException, XMLStreamException {
+ String name = "foo";
+ expect(reader.getName()).andReturn(INCLUDE);
+ expect(reader.getAttributeValue(null, "name")).andReturn(name);
+ expect(reader.getAttributeValue(null, "scdlLocation")).andReturn(null);
+ expect(reader.getAttributeValue(null, "scdlResource")).andReturn(null);
+ expect(reader.next()).andReturn(END_ELEMENT);
+
+ expect(context.getClassLoader()).andReturn(cl);
+ replay(registry, reader, context);
+
+ try {
+ loader.load(null, reader, context);
+ fail();
+ } catch (MissingIncludeException e) {
+ // OK expected
+ }
+ verify(registry, reader, context);
+ }
+
+ public void testWithAbsoluteScdlLocation() throws LoaderException, XMLStreamException {
+ String name = "foo";
+ expect(reader.getName()).andReturn(INCLUDE);
+ expect(reader.getAttributeValue(null, "name")).andReturn(name);
+ expect(reader.getAttributeValue(null, "scdlLocation")).andReturn("http://example.com/include.scdl");
+ expect(reader.getAttributeValue(null, "scdlResource")).andReturn(null);
+ expect(reader.next()).andReturn(END_ELEMENT);
+
+ expect(context.getScdlLocation()).andReturn(base);
+ expect(context.getClassLoader()).andReturn(cl);
+ expect(context.isAutowire()).andReturn(false);
+ expect(context.getComponentId()).andReturn(componentId);
+
+ expect(registry.load(
+ (ModelObject) isNull(),
+ eq(includeURL),
+ eq(CompositeComponentType.class),
+ isA(DeploymentContext.class)))
+ .andReturn(null);
+ replay(registry, reader, context);
+
+ Include include = loader.load(null, reader, context);
+ assertEquals(name, include.getName());
+ assertEquals(includeURL, include.getScdlLocation());
+ verify(registry, reader, context);
+ }
+
+ public void testWithRelativeScdlLocation() throws LoaderException, XMLStreamException {
+ String name = "foo";
+ expect(reader.getName()).andReturn(INCLUDE);
+ expect(reader.getAttributeValue(null, "name")).andReturn(name);
+ expect(reader.getAttributeValue(null, "scdlLocation")).andReturn("include.scdl");
+ expect(reader.getAttributeValue(null, "scdlResource")).andReturn(null);
+ expect(reader.next()).andReturn(END_ELEMENT);
+
+ expect(context.getScdlLocation()).andReturn(base);
+ expect(context.getClassLoader()).andReturn(cl);
+ expect(context.isAutowire()).andReturn(false);
+ expect(context.getComponentId()).andReturn(componentId);
+
+ expect(registry.load(
+ (ModelObject) isNull(),
+ eq(includeURL),
+ eq(CompositeComponentType.class),
+ isA(DeploymentContext.class)))
+ .andReturn(null);
+ replay(registry, reader, context);
+
+ Include include = loader.load(null, reader, context);
+ assertEquals(name, include.getName());
+ assertEquals(includeURL, include.getScdlLocation());
+ verify(registry, reader, context);
+ }
+
+ public void testWithScdlResource() throws LoaderException, XMLStreamException {
+ String name = "foo";
+ String resource = "org/apache/tuscany/core/loader/test-include.scdl";
+ includeURL = cl.getResource(resource);
+ assertNotNull(includeURL);
+
+ expect(reader.getName()).andReturn(INCLUDE);
+ expect(reader.getAttributeValue(null, "name")).andReturn(name);
+ expect(reader.getAttributeValue(null, "scdlLocation")).andReturn(null);
+ expect(reader.getAttributeValue(null, "scdlResource")).andReturn(resource);
+ expect(reader.next()).andReturn(END_ELEMENT);
+
+ expect(context.getClassLoader()).andReturn(cl);
+ expect(context.isAutowire()).andReturn(false);
+ expect(context.getComponentId()).andReturn(componentId);
+
+ expect(registry.load(
+ (ModelObject) isNull(),
+ eq(includeURL),
+ eq(CompositeComponentType.class),
+ isA(DeploymentContext.class)))
+ .andReturn(null);
+ replay(registry, reader, context);
+
+ Include include = loader.load(null, reader, context);
+ assertEquals(name, include.getName());
+ assertEquals(includeURL, include.getScdlLocation());
+ verify(registry, reader, context);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ registry = createMock(LoaderRegistry.class);
+ reader = createMock(XMLStreamReader.class);
+ context = createMock(DeploymentContext.class);
+ cl = getClass().getClassLoader();
+ base = new URL("http://example.com/test.scdl");
+ includeURL = new URL("http://example.com/include.scdl");
+ loader = new IncludeLoader(registry);
+ componentId = URI.create("sca://localhost/parent/");
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/JNDIPropertyFactoryTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/JNDIPropertyFactoryTestCase.java
new file mode 100644
index 0000000000..fb5bfd32d3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/JNDIPropertyFactoryTestCase.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.core.loader;
+
+import java.lang.reflect.Type;
+import java.util.Hashtable;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.tuscany.spi.model.PropertyValue;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.injection.JNDIObjectFactory;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JNDIPropertyFactoryTestCase extends TestCase {
+
+ public void testCreate() throws Exception {
+ String old = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
+ try {
+ System.setProperty(Context.INITIAL_CONTEXT_FACTORY, MockInitialContextFactory.class.getName());
+ JNDIPropertyFactory factory = new JNDIPropertyFactory();
+ Element element = EasyMock.createMock(Element.class);
+ EasyMock.expect(element.getTextContent()).andReturn("foo");
+ EasyMock.replay(element);
+ Document doc = EasyMock.createMock(Document.class);
+ EasyMock.expect(doc.getDocumentElement()).andReturn(element);
+ EasyMock.replay(doc);
+ PropertyValue<?> value = new MockPropertyValue<Type>();
+ value.setValue(doc);
+ JNDIObjectFactory<?> jndiFactory = (JNDIObjectFactory<?>) factory.createObjectFactory(null, value);
+ assertEquals("bar", jndiFactory.getInstance());
+ } finally {
+ System.clearProperty(Context.INITIAL_CONTEXT_FACTORY);
+ if (old != null) {
+ System.setProperty(Context.INITIAL_CONTEXT_FACTORY, old);
+ }
+ }
+
+ }
+
+ private class MockPropertyValue<T> extends PropertyValue<T> {
+
+ }
+
+ public static class MockInitialContextFactory implements InitialContextFactory {
+ public MockInitialContextFactory() {
+ }
+
+ public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException {
+ Context context = EasyMock.createMock(Context.class);
+ EasyMock.expect(context.lookup("foo")).andReturn("bar");
+ EasyMock.replay(context);
+ return context;
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/LoaderExceptionFormatterTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/LoaderExceptionFormatterTestCase.java
new file mode 100644
index 0000000000..49c53935dc
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/LoaderExceptionFormatterTestCase.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.core.loader;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.tuscany.spi.loader.LoaderException;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import org.apache.tuscany.host.monitor.FormatterRegistry;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LoaderExceptionFormatterTestCase extends TestCase {
+
+ public void testLog() {
+ FormatterRegistry registry = EasyMock.createNiceMock(FormatterRegistry.class);
+ LoaderExceptionFormatter formatter = new LoaderExceptionFormatter(registry);
+ LoaderException e = new LoaderException("test");
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ formatter.write(pw, e);
+ pw.close();
+ assertTrue(!"message".equals(writer.toString()));
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/PolicySetLoaderTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/PolicySetLoaderTestCase.java
new file mode 100644
index 0000000000..2b3acc9d92
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/PolicySetLoaderTestCase.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.core.loader;
+
+import java.util.Collection;
+import java.util.Iterator;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+
+import org.apache.tuscany.spi.model.IntentMap;
+import org.apache.tuscany.spi.model.PolicySet;
+import org.apache.tuscany.spi.model.Qualifier;
+
+import junit.framework.TestCase;
+
+public class PolicySetLoaderTestCase extends TestCase {
+ private static final QName POLICYSET = new QName(SCA_NS, "policySet");
+
+ public void testLoader() throws Exception {
+ PolicySetLoader loader = new PolicySetLoader(null);
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ XMLStreamReader reader = factory.createXMLStreamReader(this.getClass().getResourceAsStream("TestPolicy.scdl"));
+ while (true) {
+ int state = reader.next();
+ if (START_ELEMENT == state && reader.getName().equals(POLICYSET)) {
+ break;
+ }
+ }
+ PolicySet policySet = loader.load(null, reader, null);
+ assertNotNull(policySet);
+ assertEquals(2, policySet.getAppliedArtifacts().size());
+ assertTrue(policySet.getAppliedArtifacts().contains(new QName(SCA_NS, "binding.ws")));
+ assertTrue(policySet.getAppliedArtifacts().contains(new QName(SCA_NS, "binding.jms")));
+ Collection<IntentMap> intentMaps = policySet.getIntentMaps();
+ assertEquals(1, intentMaps.size());
+ IntentMap intentMap = intentMaps.iterator().next();
+ assertEquals("transport", intentMap.getDefaultProvideIntent());
+ assertTrue(intentMap.getProvideIntents().contains("sec.confidentiality"));
+ Collection<Qualifier> qualifiers = intentMap.getQualifiers();
+ assertEquals(2, qualifiers.size());
+ Iterator qit = qualifiers.iterator();
+ Qualifier qualifier1 = (Qualifier) qit.next();
+ assertEquals(2, qualifier1.getWsPolicyAttachments().size());
+ assertEquals("transport", qualifier1.getName());
+ Qualifier qualifier2 = (Qualifier) qit.next();
+ assertEquals("message", qualifier2.getName());
+ IntentMap messageMap = qualifier2.getIntentMap();
+ assertEquals(2, messageMap.getQualifiers().size());
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/PropertyParsingTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/PropertyParsingTestCase.java
new file mode 100644
index 0000000000..eb732d9f74
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/PropertyParsingTestCase.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.core.loader;
+
+import java.io.StringReader;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PropertyParsingTestCase extends TestCase {
+ private XMLInputFactory xmlFactory;
+ private DocumentBuilder docBuilder;
+ private Element root;
+
+ public void testComplexProperty() throws XMLStreamException {
+ String xml = "<property xmlns:foo='http://foo.com'>"
+ + "<foo:a>aValue</foo:a>"
+ + "<foo:b>InterestingURI</foo:b>"
+ + "</property>";
+
+ XMLStreamReader reader = getReader(xml);
+ PropertyUtils.loadPropertyValue(reader, root);
+ NodeList childNodes = root.getChildNodes();
+ assertEquals(2, childNodes.getLength());
+
+ Element e = (Element) childNodes.item(0);
+ assertEquals("http://foo.com", e.getNamespaceURI());
+ assertEquals("a", e.getLocalName());
+ assertEquals("aValue", e.getTextContent());
+ e = (Element) childNodes.item(1);
+ assertEquals("http://foo.com", e.getNamespaceURI());
+ assertEquals("b", e.getLocalName());
+ assertEquals("InterestingURI", e.getTextContent());
+ }
+
+ public XMLStreamReader getReader(String xml) throws XMLStreamException {
+ XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(xml));
+ reader.next();
+ return reader;
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ xmlFactory = XMLInputFactory.newInstance();
+ DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
+ docBuilder = docFactory.newDocumentBuilder();
+ Document doc = docBuilder.newDocument();
+ root = doc.createElement("value");
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ReferenceLoaderTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ReferenceLoaderTestCase.java
new file mode 100644
index 0000000000..3d4bcaf195
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ReferenceLoaderTestCase.java
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import java.net.URI;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.osoa.sca.Constants;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.BindingDefinition;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * Verifies loading of a reference definition from an XML-based assembly
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReferenceLoaderTestCase extends TestCase {
+ private static final QName REFERENCE = new QName(Constants.SCA_NS, "reference");
+ private static final String COMPONENT_NAME = "sca://someComponent";
+ private URI componentId;
+ private ReferenceLoader loader;
+ private XMLStreamReader mockReader;
+ private LoaderRegistry mockRegistry;
+ private DeploymentContext ctx;
+
+ public void testWithNoInterface() throws LoaderException, XMLStreamException {
+ String name = "referenceDefinition";
+ EasyMock.expect(mockReader.getName()).andReturn(REFERENCE).anyTimes();
+ EasyMock.expect(mockReader.getAttributeValue(null, "name")).andReturn(name);
+ EasyMock.expect(mockReader.getAttributeValue(null, "multiplicity")).andReturn("0..1");
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(mockReader.getName()).andReturn(REFERENCE).anyTimes();
+ EasyMock.replay(mockReader);
+ ReferenceDefinition referenceDefinition = loader.load(null, mockReader, ctx);
+ assertNotNull(referenceDefinition);
+ assertEquals(COMPONENT_NAME + "#" + name, referenceDefinition.getUri().toString());
+ }
+
+ public void testComponentTypeService() throws LoaderException, XMLStreamException {
+ String name = "reference";
+ EasyMock.expect(mockReader.getName()).andReturn(REFERENCE).anyTimes();
+ EasyMock.expect(mockReader.getAttributeValue(null, "name")).andReturn(name);
+ EasyMock.expect(mockReader.getAttributeValue(null, "multiplicity")).andReturn("0..1");
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(mockReader.getName()).andReturn(REFERENCE).anyTimes();
+ EasyMock.replay(mockReader);
+ ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ReferenceDefinition referenceDefinition = loader.load(type, mockReader, ctx);
+ assertTrue(ReferenceDefinition.class.equals(referenceDefinition.getClass()));
+ }
+
+ public void testMultipleBindings() throws LoaderException, XMLStreamException {
+ String name = "referenceDefinition";
+ EasyMock.expect(mockReader.getName()).andReturn(REFERENCE).anyTimes();
+ EasyMock.expect(mockReader.getAttributeValue(null, "name")).andReturn(name);
+ EasyMock.expect(mockReader.getAttributeValue(null, "multiplicity")).andReturn("0..1");
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.START_ELEMENT).times(2);
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(mockReader.getName()).andReturn(REFERENCE).anyTimes();
+ EasyMock.replay(mockReader);
+
+ BindingDefinition binding = new BindingDefinition() {
+ };
+ EasyMock.expect(mockRegistry.load(
+ (ModelObject) EasyMock.isNull(),
+ EasyMock.eq(mockReader),
+ EasyMock.isA(DeploymentContext.class)))
+ .andReturn(binding).times(2);
+ EasyMock.replay(mockRegistry);
+
+ ReferenceDefinition referenceDefinition = loader.load(null, mockReader, ctx);
+ assertEquals(2, referenceDefinition.getBindings().size());
+ }
+
+ public void testWithInterface() throws LoaderException, XMLStreamException {
+ String name = "referenceDefinition";
+ ServiceContract sc = new ServiceContract() {
+ };
+ EasyMock.expect(mockReader.getName()).andReturn(REFERENCE).anyTimes();
+ EasyMock.expect(mockReader.getAttributeValue(null, "name")).andReturn(name);
+ EasyMock.expect(mockReader.getAttributeValue(null, "multiplicity")).andReturn("0..1");
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(mockRegistry.load(null, mockReader, ctx)).andReturn(sc);
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+
+ EasyMock.replay(mockReader);
+ EasyMock.replay(mockRegistry);
+
+ ReferenceDefinition referenceDefinition = loader.load(null, mockReader, ctx);
+ assertNotNull(referenceDefinition);
+ assertEquals(COMPONENT_NAME + "#" + name, referenceDefinition.getUri().toString());
+ assertSame(sc, referenceDefinition.getServiceContract());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ componentId = URI.create(COMPONENT_NAME);
+ mockReader = EasyMock.createStrictMock(XMLStreamReader.class);
+ mockRegistry = EasyMock.createMock(LoaderRegistry.class);
+ loader = new ReferenceLoader(mockRegistry);
+ ctx = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(ctx.getComponentId()).andReturn(componentId);
+ EasyMock.replay(ctx);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderPromoteTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderPromoteTestCase.java
new file mode 100644
index 0000000000..335d9f5aa9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderPromoteTestCase.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.core.loader;
+
+import java.net.URI;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.osoa.sca.Constants;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ServiceLoaderPromoteTestCase extends TestCase {
+ private static final QName SERVICE = new QName(Constants.SCA_NS, "service");
+ private static final String COMPONENT_NAME = "sca://domain/someComponent/";
+ private URI componentId;
+ private ServiceLoader loader;
+ private XMLStreamReader mockReader;
+ private DeploymentContext ctx;
+
+ public void testReferenceNoFragment() throws LoaderException, XMLStreamException {
+ String name = "serviceDefinition";
+ EasyMock.expect(mockReader.getName()).andReturn(SERVICE);
+ EasyMock.expect(mockReader.getAttributeValue(null, "name")).andReturn(name);
+ EasyMock.expect(mockReader.getAttributeValue(null, "promote")).andReturn("target");
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(mockReader.getName()).andReturn(SERVICE);
+ EasyMock.replay(mockReader);
+ ServiceDefinition serviceDefinition = loader.load(null, mockReader, ctx);
+ assertNotNull(serviceDefinition);
+ assertEquals(COMPONENT_NAME + "target", serviceDefinition.getTarget().toString());
+ }
+
+ public void testReferenceWithFragment() throws LoaderException, XMLStreamException {
+ String name = "serviceDefinition";
+ EasyMock.expect(mockReader.getName()).andReturn(SERVICE);
+ EasyMock.expect(mockReader.getAttributeValue(null, "name")).andReturn(name);
+ EasyMock.expect(mockReader.getAttributeValue(null, "promote")).andReturn("target/fragment");
+ EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.expect(mockReader.getName()).andReturn(SERVICE);
+ EasyMock.replay(mockReader);
+ ServiceDefinition serviceDefinition = loader.load(null, mockReader, ctx);
+ assertNotNull(serviceDefinition);
+ assertEquals(COMPONENT_NAME + "target#fragment", serviceDefinition.getTarget().toString());
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ mockReader = EasyMock.createStrictMock(XMLStreamReader.class);
+ LoaderRegistry mockRegistry = EasyMock.createMock(LoaderRegistry.class);
+ loader = new ServiceLoader(mockRegistry);
+
+ componentId = URI.create(COMPONENT_NAME);
+ ctx = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(ctx.getComponentId()).andReturn(componentId);
+ EasyMock.replay(ctx);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderTestCase.java
new file mode 100644
index 0000000000..b7cb8161c7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderTestCase.java
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import java.net.URI;
+import javax.xml.namespace.QName;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.BindingDefinition;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
+/**
+ * Verifies loading of a service definition from an XML-based assembly
+ *
+ * @version $Rev$ $Date$
+ */
+public class ServiceLoaderTestCase extends TestCase {
+ private static final QName SERVICE = new QName(SCA_NS, "service");
+ //private static final QName REFERENCE = new QName(SCA_NS, "reference");
+ private static final QName INTERFACE_JAVA = new QName(SCA_NS, "interface.java");
+ private static final String PARENT_NAME = "sca://localhost/parent/";
+ private ServiceLoader loader;
+ private DeploymentContext deploymentContext;
+ private XMLStreamReader mockReader;
+ private LoaderRegistry mockRegistry;
+ private URI componentId;
+
+ public void testWithNoInterface() throws LoaderException, XMLStreamException {
+ String name = "serviceDefinition";
+ expect(mockReader.getName()).andReturn(SERVICE).anyTimes();
+ expect(mockReader.getAttributeValue(null, "name")).andReturn(name);
+ expect(mockReader.getAttributeValue(null, "promote")).andReturn(null);
+ expect(mockReader.next()).andReturn(END_ELEMENT);
+ expect(mockReader.getName()).andReturn(SERVICE).anyTimes();
+ replay(mockReader);
+ ServiceDefinition serviceDefinition = loader.load(null, mockReader, deploymentContext);
+ assertNotNull(serviceDefinition);
+ assertEquals(PARENT_NAME + "#" + name, serviceDefinition.getUri().toString());
+ }
+
+ public void testComponentTypeService() throws LoaderException, XMLStreamException {
+ String name = "service";
+ expect(mockReader.getName()).andReturn(SERVICE).anyTimes();
+ expect(mockReader.getAttributeValue(null, "name")).andReturn(name);
+ expect(mockReader.getAttributeValue(null, "promote")).andReturn(null);
+ expect(mockReader.next()).andReturn(END_ELEMENT);
+ expect(mockReader.getName()).andReturn(SERVICE).anyTimes();
+ replay(mockReader);
+ ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ServiceDefinition serviceDefinition = loader.load(type, mockReader, deploymentContext);
+ assertTrue(ServiceDefinition.class.equals(serviceDefinition.getClass()));
+ }
+
+ public void testMultipleBindings() throws LoaderException, XMLStreamException {
+ String name = "serviceDefinition";
+ expect(mockReader.getName()).andReturn(SERVICE).anyTimes();
+ expect(mockReader.getAttributeValue(null, "name")).andReturn(name);
+ expect(mockReader.getAttributeValue(null, "promote")).andReturn("component/target");
+ expect(mockReader.next()).andReturn(START_ELEMENT);
+ expect(mockReader.next()).andReturn(START_ELEMENT);
+ expect(mockReader.next()).andReturn(END_ELEMENT);
+ expect(mockReader.getName()).andReturn(SERVICE).anyTimes();
+ replay(mockReader);
+
+ BindingDefinition binding = new BindingDefinition() {
+ };
+ expect(mockRegistry.load(null, mockReader, deploymentContext)).andReturn(binding).times(2);
+ replay(mockRegistry);
+
+ ServiceDefinition serviceDefinition = loader.load(null, mockReader, deploymentContext);
+ assertEquals(2, serviceDefinition.getBindings().size());
+ }
+
+ public void testWithInterface() throws LoaderException, XMLStreamException {
+ String name = "serviceDefinition";
+ String target = "target";
+ ServiceContract sc = new ServiceContract() {
+ };
+ expect(mockReader.getName()).andReturn(SERVICE).anyTimes();
+ expect(mockReader.getAttributeValue(null, "name")).andReturn(name);
+ expect(mockReader.getAttributeValue(null, "promote")).andReturn(target);
+ expect(mockReader.next()).andReturn(START_ELEMENT);
+ expect(mockRegistry.load(null, mockReader, deploymentContext)).andReturn(sc);
+ expect(mockReader.next()).andReturn(END_ELEMENT);
+ expect(mockReader.getName()).andReturn(SERVICE);
+
+ replay(mockReader);
+ replay(mockRegistry);
+
+ ServiceDefinition serviceDefinition = loader.load(null, mockReader, deploymentContext);
+ assertNotNull(serviceDefinition);
+ assertEquals(PARENT_NAME + "#" + name, serviceDefinition.getUri().toString());
+ assertSame(sc, serviceDefinition.getServiceContract());
+ }
+
+ public void testWithNoReference() throws LoaderException, XMLStreamException {
+ String name = "serviceDefinition";
+ ServiceContract sc = new ServiceContract() {
+ };
+ expect(mockReader.getName()).andReturn(SERVICE).anyTimes();
+ expect(mockReader.getAttributeValue(null, "name")).andReturn(name);
+ expect(mockReader.getAttributeValue(null, "promote")).andReturn(null);
+ expect(mockReader.next()).andReturn(START_ELEMENT);
+ expect(mockRegistry.load(null, mockReader, deploymentContext)).andReturn(sc);
+ expect(mockReader.next()).andReturn(END_ELEMENT);
+ expect(mockReader.getName()).andReturn(SERVICE);
+
+ replay(mockReader);
+ replay(mockRegistry);
+
+ ServiceDefinition serviceDefinition = loader.load(null, mockReader, deploymentContext);
+ assertNotNull(serviceDefinition);
+ assertEquals(PARENT_NAME + "#" + name, serviceDefinition.getUri().toString());
+ assertSame(sc, serviceDefinition.getServiceContract());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ mockReader = EasyMock.createStrictMock(XMLStreamReader.class);
+ mockRegistry = EasyMock.createMock(LoaderRegistry.class);
+ loader = new ServiceLoader(mockRegistry);
+ componentId = URI.create(PARENT_NAME);
+ deploymentContext = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(deploymentContext.getComponentId()).andReturn(componentId);
+ EasyMock.replay(deploymentContext);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryImplTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryImplTestCase.java
new file mode 100644
index 0000000000..b98051f3f8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryImplTestCase.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.StAXElementLoader;
+import org.apache.tuscany.spi.loader.UnrecognizedElementException;
+import org.apache.tuscany.spi.model.ModelObject;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.deployer.RootDeploymentContext;
+import static org.easymock.EasyMock.isNull;
+import org.easymock.classextension.EasyMock;
+
+/**
+ * Verifies the default loader registry
+ *
+ * @version $Rev$ $Date$
+ */
+public class StAXLoaderRegistryImplTestCase extends TestCase {
+ private LoaderRegistryImpl registry;
+ private QName name;
+ private LoaderRegistryImpl.Monitor mockMonitor;
+ private StAXElementLoader<ModelObject> mockLoader;
+ private XMLStreamReader mockReader;
+ private DeploymentContext deploymentContext;
+ private ModelObject modelObject;
+
+ public void testLoaderRegistration() {
+ mockMonitor.registeringLoader(EasyMock.eq(name));
+ EasyMock.replay(mockMonitor);
+ registry.registerLoader(name, mockLoader);
+ EasyMock.verify(mockMonitor);
+ }
+
+ public void testLoaderUnregistration() {
+ mockMonitor.unregisteringLoader(EasyMock.eq(name));
+ EasyMock.replay(mockMonitor);
+ registry.unregisterLoader(name, (StAXElementLoader<ModelObject>) mockLoader);
+ EasyMock.verify(mockMonitor);
+ }
+
+ public void testSuccessfulDispatch() throws LoaderException, XMLStreamException {
+ EasyMock.expect(mockReader.getName()).andReturn(name);
+ EasyMock.replay(mockReader);
+ mockMonitor.registeringLoader(EasyMock.eq(name));
+ mockMonitor.elementLoad(EasyMock.eq(name));
+ EasyMock.replay(mockMonitor);
+ EasyMock.expect(mockLoader.load(
+ (ModelObject) isNull(),
+ EasyMock.eq(mockReader),
+ EasyMock.eq(deploymentContext))).andReturn(modelObject);
+ EasyMock.replay(mockLoader);
+ registry.registerLoader(name, (StAXElementLoader<ModelObject>) mockLoader);
+ Component parent = EasyMock.createNiceMock(Component.class);
+ assertSame(modelObject, registry.load(null, mockReader, deploymentContext));
+ EasyMock.verify(mockLoader);
+ EasyMock.verify(mockMonitor);
+ EasyMock.verify(mockReader);
+
+ }
+
+ public void testUnsuccessfulDispatch() throws LoaderException, XMLStreamException {
+ EasyMock.expect(mockReader.getName()).andReturn(name);
+ EasyMock.replay(mockReader);
+ mockMonitor.elementLoad(EasyMock.eq(name));
+ EasyMock.replay(mockMonitor);
+ try {
+ registry.load(null, mockReader, deploymentContext);
+ fail();
+ } catch (UnrecognizedElementException e) {
+ assertSame(name, e.getElement());
+ }
+ EasyMock.verify(mockReader);
+ EasyMock.verify(mockMonitor);
+ }
+
+ public void testPregivenModelObject() throws Exception {
+ EasyMock.expect(mockReader.getName()).andReturn(name);
+ EasyMock.replay(mockReader);
+ mockMonitor.registeringLoader(EasyMock.eq(name));
+ mockMonitor.elementLoad(EasyMock.eq(name));
+ EasyMock.replay(mockMonitor);
+ EasyMock.expect(mockLoader.load(
+ EasyMock.eq(modelObject),
+ EasyMock.eq(mockReader),
+ EasyMock.eq(deploymentContext))).andReturn(modelObject);
+ EasyMock.replay(mockLoader);
+ registry.registerLoader(name, (StAXElementLoader<ModelObject>) mockLoader);
+ Component parent = EasyMock.createNiceMock(Component.class);
+ assertSame(modelObject, registry.load(modelObject, mockReader, deploymentContext));
+ EasyMock.verify(mockLoader);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+ name = new QName("http://mock", "test");
+ deploymentContext = new RootDeploymentContext(null, null, null, null, null, false);
+ mockMonitor = EasyMock.createMock(LoaderRegistryImpl.Monitor.class);
+ registry = new LoaderRegistryImpl(mockMonitor);
+
+ mockLoader = EasyMock.createMock(StAXElementLoader.class);
+ mockReader = EasyMock.createMock(XMLStreamReader.class);
+ modelObject = new ModelObject() {
+ };
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/StringParserPropertyFactoryTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/StringParserPropertyFactoryTestCase.java
new file mode 100644
index 0000000000..4445dfad2c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/StringParserPropertyFactoryTestCase.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.core.loader;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.PropertyValue;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class StringParserPropertyFactoryTestCase extends TestCase {
+
+ private <T> PropertyValue<T> mock(String value) {
+ Document document = EasyMock.createMock(Document.class);
+ Element element = EasyMock.createMock(Element.class);
+ EasyMock.expect(document.getDocumentElement()).andReturn(element);
+ EasyMock.expect(element.getTextContent()).andReturn(value);
+ EasyMock.replay(document, element);
+ return new PropertyValue<T>(null, document);
+ }
+
+ public void testInteger() throws Exception {
+
+ StringParserPropertyFactory factory = new StringParserPropertyFactory();
+ Property<Integer> property = new Property<Integer>();
+ property.setJavaType(Integer.class);
+ PropertyValue<Integer> propertyValue = mock("1");
+ ObjectFactory<Integer> oFactory = factory.createObjectFactory(property, propertyValue);
+ assertEquals(1, oFactory.getInstance().intValue());
+ }
+
+ public void testPrimitiveInt() throws Exception {
+ StringParserPropertyFactory factory = new StringParserPropertyFactory();
+ Property<Integer> property = new Property<Integer>();
+ property.setJavaType(Integer.TYPE);
+ PropertyValue<Integer> propertyValue = mock("1");
+ ObjectFactory<Integer> oFactory = factory.createObjectFactory(property, propertyValue);
+ assertEquals(1, oFactory.getInstance().intValue());
+ }
+
+ public void testString() throws Exception {
+ StringParserPropertyFactory factory = new StringParserPropertyFactory();
+ Property<String> property = new Property<String>();
+ property.setJavaType(String.class);
+ PropertyValue<String> propertyValue = mock("1");
+ ObjectFactory<String> oFactory = factory.createObjectFactory(property, propertyValue);
+ assertEquals("1", oFactory.getInstance());
+ }
+
+ public void testByteArray() throws Exception {
+ StringParserPropertyFactory factory = new StringParserPropertyFactory();
+ Property<byte[]> property = new Property<byte[]>();
+ property.setJavaType(byte[].class);
+ PropertyValue<byte[]> propertyValue = mock("1");
+ ObjectFactory<byte[]> oFactory = factory.createObjectFactory(property, propertyValue);
+ byte[] result = oFactory.getInstance();
+ byte[] expected = "1".getBytes();
+ for (int i = 0; i < result.length; i++) {
+ byte b = result[i];
+ if (b != expected[i]) {
+ fail();
+ }
+ }
+ }
+
+ public void testBoolean() throws Exception {
+ StringParserPropertyFactory factory = new StringParserPropertyFactory();
+ Property<Boolean> property = new Property<Boolean>();
+ property.setJavaType(Boolean.class);
+ PropertyValue<Boolean> propertyValue = mock("true");
+ ObjectFactory<Boolean> oFactory = factory.createObjectFactory(property, propertyValue);
+ assertTrue(oFactory.getInstance());
+ }
+
+ public void testPrimitiveBoolean() throws Exception {
+ StringParserPropertyFactory factory = new StringParserPropertyFactory();
+ Property<Boolean> property = new Property<Boolean>();
+ property.setJavaType(Boolean.TYPE);
+ PropertyValue<Boolean> propertyValue = mock("true");
+ ObjectFactory<Boolean> oFactory = factory.createObjectFactory(property, propertyValue);
+ assertTrue(oFactory.getInstance());
+ }
+
+ public void testStringConstructor() throws Exception {
+ StringParserPropertyFactory factory = new StringParserPropertyFactory();
+ Property<Foo> property = new Property<Foo>();
+ property.setJavaType(Foo.class);
+ PropertyValue<Foo> propertyValue = mock("test");
+ ObjectFactory<Foo> oFactory = factory.createObjectFactory(property, propertyValue);
+ assertEquals("test", oFactory.getInstance().getFoo());
+ }
+
+ private static class Foo {
+ private String foo;
+
+ public Foo(String foo) {
+ this.foo = foo;
+ }
+
+ public String getFoo() {
+ return foo;
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/WireLoaderTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/WireLoaderTestCase.java
new file mode 100644
index 0000000000..75e455d5a8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/loader/WireLoaderTestCase.java
@@ -0,0 +1,181 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.loader;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.InvalidWireException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.WireDefinition;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+/**
+ * @version $Rev: 471504 $ $Date: 2006-11-06 01:10:40 +0530 (Mon, 06 Nov 2006) $
+ */
+public class WireLoaderTestCase extends TestCase {
+ private static final QName WIRE = new QName(SCA_NS, "wire");
+ private static final QName SOURCE_URI = new QName(SCA_NS, "source.uri");
+ private static final QName TARGET_URI = new QName(SCA_NS, "target.uri");
+
+ private LoaderRegistry registry;
+ private WireLoader loader;
+ private XMLStreamReader reader;
+ private DeploymentContext context;
+ private Component composite;
+
+ public void testValidWire() throws LoaderException, XMLStreamException {
+ expect(reader.getName()).andReturn(WIRE);
+ expect(reader.next()).andReturn(START_ELEMENT);
+ expect(reader.getName()).andReturn(SOURCE_URI).times(1);
+ expect(reader.getElementText()).andReturn("source").times(1);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ expect(reader.next()).andReturn(START_ELEMENT);
+ expect(reader.getName()).andReturn(TARGET_URI).times(2);
+ expect(reader.getElementText()).andReturn("target").times(1);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ expect(reader.getName()).andReturn(WIRE).anyTimes();
+ replay(registry, reader, context);
+ WireDefinition wireDef = loader.load(null, reader, context);
+ assertNotNull(wireDef);
+ verify(registry, reader, context);
+ }
+
+ public void testInValidWireNoSourceElement() throws LoaderException, XMLStreamException {
+ expect(reader.getName()).andReturn(WIRE).times(1);
+ expect(reader.next()).andReturn(START_ELEMENT);
+ expect(reader.getName()).andReturn(TARGET_URI).times(2);
+ expect(reader.getElementText()).andReturn("target").times(1);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ expect(reader.getName()).andReturn(WIRE).anyTimes();
+ replay(registry, reader, context);
+ try {
+ loader.load(null, reader, context);
+ fail();
+ } catch (InvalidWireException e) {
+ //expected behaviour
+ }
+ verify(registry, reader, context);
+ }
+
+ public void testInValidWireNoTargetElement() throws LoaderException, XMLStreamException {
+ expect(reader.getName()).andReturn(WIRE).times(1);
+ expect(reader.next()).andReturn(START_ELEMENT);
+ expect(reader.getName()).andReturn(SOURCE_URI).times(1);
+ expect(reader.getElementText()).andReturn("source").times(1);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ expect(reader.getName()).andReturn(WIRE).anyTimes();
+ replay(registry, reader, context);
+ try {
+ loader.load(null, reader, context);
+ fail();
+ } catch (InvalidWireException e) {
+ //expected behaviour
+ }
+ verify(registry, reader, context);
+ }
+
+ public void testInValidWireNoSourceSpecified() throws LoaderException, XMLStreamException {
+ expect(reader.getName()).andReturn(WIRE).times(1);
+ expect(reader.next()).andReturn(START_ELEMENT);
+ expect(reader.getName()).andReturn(SOURCE_URI).times(1);
+ expect(reader.getElementText()).andReturn("").times(1);
+ replay(registry, reader, context);
+ try {
+ loader.load(null, reader, context);
+ fail();
+ } catch (InvalidWireException e) {
+ //expected behaviour
+ }
+ verify(registry, reader, context);
+ }
+
+ public void testInValidWireNoTargetSpecified() throws LoaderException, XMLStreamException {
+ expect(reader.getName()).andReturn(WIRE).times(1);
+ expect(reader.next()).andReturn(START_ELEMENT);
+ expect(reader.getName()).andReturn(SOURCE_URI).times(1);
+ expect(reader.getElementText()).andReturn("source").times(1);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ expect(reader.next()).andReturn(START_ELEMENT);
+ expect(reader.getName()).andReturn(TARGET_URI).times(2);
+ expect(reader.getElementText()).andReturn("").times(1);
+ expect(reader.getName()).andReturn(WIRE).anyTimes();
+ replay(registry, reader, context);
+ try {
+ loader.load(null, reader, context);
+ fail();
+ } catch (InvalidWireException e) {
+ //expected behaviour
+ }
+ verify(registry, reader, context);
+ }
+
+ public void testWireSourceAndTargetFragments() throws LoaderException, XMLStreamException {
+ expect(reader.getName()).andReturn(WIRE);
+ expect(reader.next()).andReturn(START_ELEMENT);
+ expect(reader.getName()).andReturn(SOURCE_URI).times(1);
+ expect(reader.getElementText()).andReturn("source/reference").times(1);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ expect(reader.next()).andReturn(START_ELEMENT);
+ expect(reader.getName()).andReturn(TARGET_URI).times(2);
+ expect(reader.getElementText()).andReturn("target/service").times(1);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ expect(reader.next()).andReturn(END_ELEMENT);
+ expect(reader.getName()).andReturn(WIRE).anyTimes();
+ replay(registry, reader, context);
+ WireDefinition wireDef = loader.load(null, reader, context);
+ assertNotNull(wireDef);
+ assertEquals("source", wireDef.getSource().getPath());
+ assertEquals("reference", wireDef.getSource().getFragment());
+ assertEquals("target", wireDef.getTarget().getPath());
+ assertEquals("service", wireDef.getTarget().getFragment());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ registry = createMock(LoaderRegistry.class);
+ reader = createMock(XMLStreamReader.class);
+ Location location = EasyMock.createNiceMock(Location.class);
+ EasyMock.replay(location);
+ EasyMock.expect(reader.getLocation()).andReturn(location).anyTimes();
+ context = createMock(DeploymentContext.class);
+ composite = createMock(Component.class);
+ loader = new WireLoader(registry);
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/marshaller/JavaPhysicalChangeSetMarshallerTest.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/marshaller/JavaPhysicalChangeSetMarshallerTest.java
new file mode 100644
index 0000000000..5d95b49796
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/marshaller/JavaPhysicalChangeSetMarshallerTest.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.core.marshaller;
+
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.util.Set;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.marshaller.extensions.instancefactory.ByteCodeIFProviderDefinitionMarshaller;
+import org.apache.tuscany.core.marshaller.extensions.instancefactory.ReflectiveIFProviderDefinitionMarshaller;
+import org.apache.tuscany.core.marshaller.extensions.java.JavaPhysicalComponentDefinitionMarshaller;
+import org.apache.tuscany.core.marshaller.extensions.java.JavaPhysicalWireSourceDefinitionMarshaller;
+import org.apache.tuscany.core.marshaller.extensions.java.JavaPhysicalWireTargetDefinitionMarshaller;
+import org.apache.tuscany.core.model.physical.java.JavaPhysicalComponentDefinition;
+import org.apache.tuscany.spi.marshaller.ModelMarshallerRegistry;
+import org.apache.tuscany.spi.model.physical.PhysicalChangeSet;
+import org.apache.tuscany.spi.model.physical.PhysicalComponentDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireDefinition;
+
+/**
+ * Test case for Java physical change set marshaller.
+ *
+ * @version $Revision$ $Date$
+ *
+ */
+public class JavaPhysicalChangeSetMarshallerTest extends TestCase {
+
+ private ModelMarshallerRegistry registry;
+
+ public JavaPhysicalChangeSetMarshallerTest(String arg0) {
+ super(arg0);
+ }
+
+ public void setUp() {
+
+ registry = new DefaultModelMarshallerRegistry();
+
+ AbstractMarshallerExtension<?>[] marshallers = new AbstractMarshallerExtension<?>[8];
+
+ marshallers[0] = new JavaPhysicalComponentDefinitionMarshaller();
+ marshallers[1] = new PhysicalOperationDefinitionMarshaller();
+ marshallers[2] = new PhysicalWireDefinitionMarshaller();
+ marshallers[3] = new PhysicalChangeSetMarshaller();
+ marshallers[4] = new JavaPhysicalWireSourceDefinitionMarshaller();
+ marshallers[5] = new JavaPhysicalWireTargetDefinitionMarshaller();
+ marshallers[6] = new ByteCodeIFProviderDefinitionMarshaller();
+ marshallers[7] = new ReflectiveIFProviderDefinitionMarshaller();
+
+ for (int i = 0; i < 8; i++) {
+ marshallers[i].setMarshallerRegistry(registry);
+ }
+
+ }
+
+ public void testMarshall() throws Exception {
+
+ ClassLoader cl = getClass().getClassLoader();
+ InputStream inputStream = cl.getResourceAsStream("marshall/javaChangeSet.xml");
+ XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(inputStream);
+
+ while(reader.next() != START_ELEMENT) {
+ }
+ PhysicalChangeSet changeSet = (PhysicalChangeSet)registry.unmarshall(reader);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(out);
+ registry.marshall(changeSet, writer);
+
+ byte[] xml = out.toByteArray();
+ inputStream = new ByteArrayInputStream(xml);
+ reader = XMLInputFactory.newInstance().createXMLStreamReader(inputStream);
+
+ while(reader.next() != START_ELEMENT) {
+ }
+ changeSet = (PhysicalChangeSet)registry.unmarshall(reader);
+ verifyChangeSet(changeSet);
+
+ }
+
+ public void testUnmarshall() throws Exception {
+
+ ClassLoader cl = getClass().getClassLoader();
+ InputStream inputStream = cl.getResourceAsStream("marshall/javaChangeSet.xml");
+ XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(inputStream);
+
+ while(reader.next() != START_ELEMENT) {
+ }
+ PhysicalChangeSet changeSet = (PhysicalChangeSet)registry.unmarshall(reader);
+ verifyChangeSet(changeSet);
+
+
+ }
+
+ private void verifyChangeSet(PhysicalChangeSet changeSet) {
+
+ assertNotNull(changeSet);
+ Set<? extends PhysicalComponentDefinition> pcds = changeSet.getComponentDefinitions();
+ assertEquals(2, pcds.size());
+ for (PhysicalComponentDefinition pcd : pcds) {
+
+ assertTrue(pcd instanceof JavaPhysicalComponentDefinition);
+ String componentId = pcd.getComponentId().toString();
+ assertTrue("cmp1".equals(componentId) || "cmp2".equals(componentId));
+ assertTrue(pcd instanceof JavaPhysicalComponentDefinition);
+
+ }
+
+ Set<PhysicalWireDefinition> pwds = changeSet.getWireDefinitions();
+
+ assertEquals(2, changeSet.getWireDefinitions().size());
+ for (PhysicalWireDefinition pwd : pwds) {
+
+ String sourceUri = pwd.getSourceUri().toString();
+ String targetUri = pwd.getTargetUri().toString();
+
+ assertTrue(("cmp1#rf1".equals(sourceUri) && "cmp2#sv2".equals(targetUri))
+ || ("cmp2#rf2".equals(sourceUri) && "cmp1#sv1"
+ .equals(targetUri)));
+
+ Set<PhysicalOperationDefinition> pods = pwd.getOperations();
+ assertEquals(1, pods.size());
+ PhysicalOperationDefinition pod = pods.iterator().next();
+
+ if (sourceUri.equals("cmp1#rf1")) {
+ assertEquals("op2", pod.getName());
+ } else {
+ assertEquals("op1", pod.getName());
+ }
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/binding/MockServiceBinding.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/binding/MockServiceBinding.java
new file mode 100644
index 0000000000..920b81e1a2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/binding/MockServiceBinding.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.core.mock.binding;
+
+import java.net.URI;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.component.AbstractSCAObject;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * @version $Rev$ $Date$
+ * @Deprecated
+ */
+public class MockServiceBinding extends AbstractSCAObject implements ServiceBinding {
+ private Wire wire;
+
+ public MockServiceBinding(URI uri) {
+ super(uri);
+ }
+
+ public QName getBindingType() {
+ return null;
+ }
+
+ public ServiceContract<?> getBindingServiceContract() {
+ return null;
+ }
+
+ public Wire getWire() {
+ return wire;
+ }
+
+ public void setWire(Wire wire) {
+ this.wire = wire;
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, Operation operation)
+ throws TargetInvokerCreationException {
+ return null;
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, PhysicalOperationDefinition operation)
+ throws TargetInvokerCreationException {
+ return null;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/AsyncTarget.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/AsyncTarget.java
new file mode 100644
index 0000000000..653d5d7335
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.core.mock.component;
+
+import org.osoa.sca.annotations.OneWay;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface AsyncTarget {
+ @OneWay
+ void invoke();
+
+ int getCount();
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BadContextPojo.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BadContextPojo.java
new file mode 100644
index 0000000000..066acc346d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.core.mock.component;
+
+import org.osoa.sca.annotations.Context;
+
+public class BadContextPojo {
+
+ @Context
+ String context;
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BadNamePojo.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BadNamePojo.java
new file mode 100644
index 0000000000..77ec37f9e4
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.core.mock.component;
+
+import org.osoa.sca.annotations.ComponentName;
+
+public class BadNamePojo {
+ @ComponentName
+ private int name;
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterface.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterface.java
new file mode 100644
index 0000000000..b7921c248f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.core.mock.component;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface BasicInterface {
+ String returnsProperty();
+
+ BasicInterface returnsReference();
+
+ int returnsInt();
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterfaceImpl.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterfaceImpl.java
new file mode 100644
index 0000000000..f7d7bb38cf
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponent.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponent.java
new file mode 100644
index 0000000000..88b97216cd
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.core.mock.component;
+
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@Scope("COMPOSITE")
+public interface CompositeScopeComponent {
+
+ //public boolean isInit();
+}
+
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponentImpl.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponentImpl.java
new file mode 100644
index 0000000000..93ee1f707a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeDestroyOnlyComponent.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeDestroyOnlyComponent.java
new file mode 100644
index 0000000000..16ce3b5569
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitDestroyComponent.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitDestroyComponent.java
new file mode 100644
index 0000000000..05b938a87c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitOnlyComponent.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitOnlyComponent.java
new file mode 100644
index 0000000000..f9f80ca15c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponent.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponent.java
new file mode 100644
index 0000000000..c71ac0586f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponentImpl.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponentImpl.java
new file mode 100644
index 0000000000..5ea7278e1f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeDestroyOnlyComponent.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeDestroyOnlyComponent.java
new file mode 100644
index 0000000000..8cea9efa49
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitDestroyComponent.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitDestroyComponent.java
new file mode 100644
index 0000000000..40dbfedf2c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitOnlyComponent.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitOnlyComponent.java
new file mode 100644
index 0000000000..caaa0c39e7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderException.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderException.java
new file mode 100644
index 0000000000..af257c226d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojo.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojo.java
new file mode 100644
index 0000000000..2033f0eca5
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.core.mock.component;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public interface OrderedDependentPojo extends OrderedInitPojo {
+
+ OrderedInitPojo getPojo();
+
+ void setPojo(OrderedInitPojo pojo);
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojoImpl.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojoImpl.java
new file mode 100644
index 0000000000..439c3d143c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedEagerInitPojo.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedEagerInitPojo.java
new file mode 100644
index 0000000000..1986952747
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.core.mock.component;
+
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Scope;
+import org.osoa.sca.annotations.EagerInit;
+
+@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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojo.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojo.java
new file mode 100644
index 0000000000..0b891cfa42
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.core.mock.component;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public interface OrderedInitPojo {
+ int getNumberInstantiated();
+
+ int getInitOrder();
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojoImpl.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojoImpl.java
new file mode 100644
index 0000000000..a7063f6353
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTarget.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTarget.java
new file mode 100644
index 0000000000..0b897daa40
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.core.mock.component;
+
+/**
+ * Implementations are used in wiring tests
+ *
+ * @version $Rev$ $Date$
+ */
+public interface OtherTarget {
+
+ String getString();
+
+ void setString(String val);
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTargetImpl.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTargetImpl.java
new file mode 100644
index 0000000000..a3b2bbf098
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeComponent.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeComponent.java
new file mode 100644
index 0000000000..8c7dc107ee
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.core.mock.component;
+
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@Scope("REQUEST")
+public interface RequestScopeComponent {
+
+}
+
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeDestroyOnlyComponent.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeDestroyOnlyComponent.java
new file mode 100644
index 0000000000..5224ceda5f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitDestroyComponent.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitDestroyComponent.java
new file mode 100644
index 0000000000..38b188a4b5
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitOnlyComponent.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitOnlyComponent.java
new file mode 100644
index 0000000000..707f8ab50f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponent.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponent.java
new file mode 100644
index 0000000000..827ba804f2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.core.mock.component;
+
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@Scope("SESSION")
+public interface SessionScopeComponent {
+
+}
+
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponentImpl.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponentImpl.java
new file mode 100644
index 0000000000..e547bf6113
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.core.mock.component;
+
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@Scope("SESSION")
+public class SessionScopeComponentImpl implements
+ SessionScopeComponent {
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitDestroyComponent.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitDestroyComponent.java
new file mode 100644
index 0000000000..c11bd1bd49
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitOnlyComponent.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitOnlyComponent.java
new file mode 100644
index 0000000000..095cc916ec
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTarget.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTarget.java
new file mode 100644
index 0000000000..c78ba00a7a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTargetImpl.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTargetImpl.java
new file mode 100644
index 0000000000..634a07a401
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/Source.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/Source.java
new file mode 100644
index 0000000000..f7969f748b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.core.mock.component;
+
+import java.util.List;
+
+/**
+ * Implementations are used in wiring tests
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Source {
+
+ Target getTarget();
+
+ List<Target> getTargets();
+
+ List<Target> getTargetsThroughField();
+
+}
+
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SourceImpl.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SourceImpl.java
new file mode 100644
index 0000000000..187e33b2bd
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.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<Target> targets;
+ private List<Target> targetsThroughField;
+ private Target[] targetsArray;
+
+ public void setTarget(Target target) {
+ this.target = target;
+ }
+
+ public Target getTarget() {
+ return target;
+ }
+
+ public List<Target> getTargets() {
+ return targets;
+ }
+
+ public void setTargets(List<Target> targets) {
+ this.targets = targets;
+ }
+
+ public List<Target> getTargetsThroughField() {
+ return targetsThroughField;
+ }
+
+ public Target[] getArrayOfTargets() {
+ return targetsArray;
+ }
+
+ public void setArrayOfTargets(Target[] targets) {
+ targetsArray = targets;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponent.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponent.java
new file mode 100644
index 0000000000..c16ac942a3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.core.mock.component;
+
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@Scope("STATELESS")
+public interface StatelessComponent {
+
+}
+
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponentImpl.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponentImpl.java
new file mode 100644
index 0000000000..64a23c12c8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.core.mock.component;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class StatelessComponentImpl implements
+ StatelessComponent {
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/Target.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/Target.java
new file mode 100644
index 0000000000..778c14665d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.core.mock.component;
+
+/**
+ * Implementations are used in wiring tests
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Target {
+
+ String getString();
+
+ void setString(String val);
+}
+
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/TargetImpl.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/TargetImpl.java
new file mode 100644
index 0000000000..037dd3a37c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/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.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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockStaticInvoker.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockStaticInvoker.java
new file mode 100644
index 0000000000..98f5973f62
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockStaticInvoker.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.core.mock.wire;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.component.WorkContext;
+
+/**
+ * Caches component instances that do not need to be resolved for every wire, e.g. an wire originating from a lesser
+ * scope intended for a target with a wider scope
+ *
+ * @version $Rev$ $Date$
+ */
+public class MockStaticInvoker implements TargetInvoker {
+
+ private Object instance;
+ private Method operation;
+ private boolean cacheable;
+
+
+ public MockStaticInvoker(Method operation, Object instance) {
+ this.operation = operation;
+ this.instance = instance;
+ }
+
+ public boolean isCacheable() {
+ return cacheable;
+ }
+
+ public void setCacheable(boolean cacheable) {
+ this.cacheable = cacheable;
+ }
+
+ public boolean isOptimizable() {
+ return isCacheable();
+ }
+
+ public Object invokeTarget(final Object payload, final short sequence, WorkContext workContext) throws InvocationTargetException {
+ try {
+ if (payload != null && !payload.getClass().isArray()) {
+ return operation.invoke(instance, payload);
+ } else {
+ return operation.invoke(instance, (Object[]) payload);
+ }
+ } catch (IllegalAccessException e) {
+ throw new InvocationRuntimeException(e);
+ }
+ }
+
+ public Message invoke(Message msg) throws InvocationRuntimeException {
+ try {
+ Object resp = invokeTarget(msg.getBody(), TargetInvoker.NONE, null);
+ msg.setBody(resp);
+ } catch (InvocationTargetException e) {
+ msg.setBodyWithFault(e.getCause());
+ } catch (Throwable e) {
+ msg.setBodyWithFault(e);
+ }
+ return msg;
+ }
+
+ public void setNext(Interceptor next) {
+ throw new IllegalStateException("This interceptor must be the last interceptor in an interceptor chain");
+ }
+
+ public Object clone() throws CloneNotSupportedException {
+ try {
+ MockStaticInvoker invoker = (MockStaticInvoker) super.clone();
+ invoker.instance = this.instance;
+ invoker.operation = this.operation;
+ return invoker;
+ } catch (CloneNotSupportedException e) {
+ return null; // will not happen
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockSyncInterceptor.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockSyncInterceptor.java
new file mode 100644
index 0000000000..1fe2c027ab
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockSyncInterceptor.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.core.mock.wire;
+
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+
+public class MockSyncInterceptor implements Interceptor {
+
+ private int count;
+
+ private Interceptor next;
+
+ public MockSyncInterceptor() {
+ }
+
+ public Message invoke(Message msg) {
+ ++count;
+ return next.invoke(msg);
+ }
+
+ public int getCount() {
+ return count;
+ }
+
+ public void setNext(Interceptor next) {
+ this.next = next;
+ }
+
+ public Interceptor getNext() {
+ return next;
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+
+}
+
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockTargetInvoker.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockTargetInvoker.java
new file mode 100644
index 0000000000..3fcc75bdb4
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockTargetInvoker.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.core.mock.wire;
+
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.Message;
+
+import org.apache.tuscany.core.binding.local.AbstractLocalTargetInvoker;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MockTargetInvoker extends AbstractLocalTargetInvoker {
+ public Message invoke(Message msg) throws InvocationRuntimeException {
+ return null;
+ }
+} \ No newline at end of file
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/monitor/DefaultExceptionFormatterTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/monitor/DefaultExceptionFormatterTestCase.java
new file mode 100644
index 0000000000..437e718206
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/monitor/DefaultExceptionFormatterTestCase.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.core.monitor;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.api.TuscanyException;
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DefaultExceptionFormatterTestCase extends TestCase {
+ private DefaultExceptionFormatter formatter = new DefaultExceptionFormatter();
+
+ public void testTuscanyExceptionFormat() throws Exception {
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ TuscanyException e = new TuscanyException("somemessage") {
+ };
+ formatter.write(pw, e);
+ assertTrue(writer.toString().indexOf("somemessage") >= 0);
+ }
+
+ public void testTuscanyRuntimeExceptionFormat() throws Exception {
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ TuscanyRuntimeException e = new TuscanyRuntimeException("somemessage") {
+ };
+ formatter.write(pw, e);
+ assertTrue(writer.toString().indexOf("somemessage") >= 0);
+ }
+
+ public void testNormalExceptionFormat() throws Exception {
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ Exception e = new Exception();
+ formatter.write(pw, e); // just verify there are no errors since no formatting needs to be doen
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/monitor/JavaLoggingTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/monitor/JavaLoggingTestCase.java
new file mode 100644
index 0000000000..5fdf035c7a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/monitor/JavaLoggingTestCase.java
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.monitor;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+import org.apache.tuscany.api.annotation.LogLevel;
+import org.apache.tuscany.host.MonitorFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case for the JavaLoggingMonitorFactory.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaLoggingTestCase extends TestCase {
+ private static final Logger LOGGER = Logger.getLogger(Monitor.class.getName());
+ private static final MockHandler HANDLER = new MockHandler();
+
+ private MonitorFactory factory;
+
+ /**
+ * Smoke test to ensure the LOGGER is working.
+ */
+ public void testLogger() {
+ LOGGER.info("test");
+ assertEquals(1, HANDLER.logs.size());
+ }
+
+ /**
+ * Test that no record is logged.
+ */
+ public void testUnloggedEvent() {
+ Monitor mon = factory.getMonitor(Monitor.class);
+ mon.eventNotToLog();
+ assertEquals(0, HANDLER.logs.size());
+ }
+
+ /**
+ * Test the correct record is written for an event with no arguments.
+ */
+ public void testEventWithNoArgs() {
+ Monitor mon = factory.getMonitor(Monitor.class);
+ mon.eventWithNoArgs();
+ assertEquals(1, HANDLER.logs.size());
+ LogRecord record = HANDLER.logs.get(0);
+ assertEquals(Level.INFO, record.getLevel());
+ assertEquals(LOGGER.getName(), record.getLoggerName());
+ assertEquals(Monitor.class.getName() + "#eventWithNoArgs", record.getMessage());
+ }
+
+ /**
+ * Test the correct record is written for an event defined by annotation.
+ */
+ public void testEventWithAnnotation() {
+ Monitor mon = factory.getMonitor(Monitor.class);
+ mon.eventWithAnnotation();
+ assertEquals(1, HANDLER.logs.size());
+ LogRecord record = HANDLER.logs.get(0);
+ assertEquals(Level.INFO, record.getLevel());
+ assertEquals(LOGGER.getName(), record.getLoggerName());
+ assertEquals(Monitor.class.getName() + "#eventWithAnnotation", record.getMessage());
+ }
+
+ /**
+ * Test the argument is logged.
+ */
+ public void testEventWithOneArg() {
+ Monitor mon = factory.getMonitor(Monitor.class);
+ mon.eventWithOneArg("ARG");
+ assertEquals(1, HANDLER.logs.size());
+ LogRecord record = HANDLER.logs.get(0);
+ assertEquals(Monitor.class.getName() + "#eventWithOneArg", record.getMessage());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ LOGGER.setUseParentHandlers(false);
+ LOGGER.addHandler(HANDLER);
+ HANDLER.flush();
+
+ String sourceClass = Monitor.class.getName();
+ Properties levels = new Properties();
+ levels.setProperty(sourceClass + "#eventWithNoArgs", "INFO");
+ levels.setProperty(sourceClass + "#eventWithOneArg", "INFO");
+ levels.setProperty(sourceClass + "#eventWithThrowable", "WARNING");
+ factory = new JavaLoggingMonitorFactory(levels, Level.FINE, "TestMessages");
+ }
+
+ protected void tearDown() throws Exception {
+ LOGGER.removeHandler(HANDLER);
+ HANDLER.flush();
+ super.tearDown();
+ }
+
+ /**
+ * Mock log HANDLER to capture records.
+ */
+ public static class MockHandler extends Handler {
+ List<LogRecord> logs = new ArrayList<LogRecord>();
+
+ public void publish(LogRecord record) {
+ logs.add(record);
+ }
+
+ public void flush() {
+ logs.clear();
+ }
+
+ public void close() throws SecurityException {
+ }
+ }
+
+ @SuppressWarnings({"JavaDoc"})
+ public static interface Monitor {
+ void eventNotToLog();
+
+ @LogLevel("INFO")
+ void eventWithNoArgs();
+
+ @LogLevel("INFO")
+ void eventWithOneArg(String msg);
+
+ @LogLevel("WARNING")
+ void eventWithThrowable(Exception e);
+
+ @LogLevel("INFO")
+ void eventWithAnnotation();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/policy/IntentRegistryImplTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/policy/IntentRegistryImplTestCase.java
new file mode 100644
index 0000000000..de1c91b741
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/policy/IntentRegistryImplTestCase.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.policy;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import javax.xml.namespace.QName;
+
+import static org.osoa.sca.Constants.SCA_NS;
+
+import org.apache.tuscany.spi.model.Intent;
+import org.apache.tuscany.spi.model.IntentName;
+import org.apache.tuscany.spi.policy.IntentRegistry;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class IntentRegistryImplTestCase extends TestCase {
+ private static final QName WS_BINDING = new QName(SCA_NS, "binding.ws");
+ private static final QName JMS_BINDING = new QName(SCA_NS, "binding.jms");
+ private IntentRegistry intentReg;
+
+ @Override
+ protected void setUp() throws Exception {
+ intentReg = new IntentRegistryImpl();
+
+ Intent bodyintent = new Intent(new IntentName("sec.confidentiality/message/body"), "test");
+ bodyintent.addAppliedArtifacts(WS_BINDING);
+ bodyintent.addAppliedArtifacts(JMS_BINDING);
+ intentReg.register(bodyintent);
+
+ Intent headintent = new Intent(new IntentName("sec.confidentiality/message/head"), "test");
+ headintent.addAppliedArtifacts(WS_BINDING);
+ headintent.addAppliedArtifacts(JMS_BINDING);
+ intentReg.register(headintent);
+
+ Intent confidentialityintent = new Intent(new IntentName("sec.confidentiality"), "test");
+ confidentialityintent.addAppliedArtifacts(WS_BINDING);
+ confidentialityintent.addAppliedArtifacts(JMS_BINDING);
+ intentReg.register(confidentialityintent);
+
+ Intent messageintent = new Intent(new IntentName("sec.confidentiality/message"), null);
+ messageintent.addAppliedArtifacts(WS_BINDING);
+ messageintent.addAppliedArtifacts(JMS_BINDING);
+ intentReg.register(messageintent);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ intentReg = null;
+ }
+
+// public void testGetQualifiedIntent() {
+// List<IntentName> intentNameList = new ArrayList<IntentName>();
+// intentReg.get
+// //intentReg.getConcretIntents(intentNameList, artifact)
+// }
+
+ public void testGetConcretIntents() {
+ Intent messageintent = new Intent(new IntentName("sec.confidentiality/transport"), null);
+ messageintent.addAppliedArtifacts(WS_BINDING);
+ messageintent.addAppliedArtifacts(JMS_BINDING);
+ intentReg.register(messageintent);
+
+ Intent allintent = new Intent(new IntentName("sec.confidentiality/all"), null);
+ allintent.addAppliedArtifacts(WS_BINDING);
+ allintent.addRequriedIntents(new IntentName("sec.confidentiality/message"));
+ allintent.addRequriedIntents(new IntentName("sec.confidentiality/transport"));
+
+
+ intentReg.register(allintent);
+ List<IntentName> intents = new ArrayList<IntentName>();
+ intents.add(new IntentName("sec.confidentiality/all"));
+ Collection<IntentName> concreteIntents = intentReg.inlineProfileIntent(intents, WS_BINDING);
+ assertEquals(2, concreteIntents.size());
+ assertTrue(concreteIntents.contains(new IntentName("sec.confidentiality/message")));
+ assertTrue(concreteIntents.contains(new IntentName("sec.confidentiality/transport")));
+ //fail("Not yet implemented");
+ }
+
+ public void testGetQualifiedIntents() {
+ IntentName message = new IntentName("sec.confidentiality/message");
+ Collection<IntentName> qualifiedIntents = intentReg.getQualifiedIntents(message, JMS_BINDING);
+ assertEquals(2, qualifiedIntents.size());
+ assertTrue(qualifiedIntents.contains(new IntentName("sec.confidentiality/message/body")));
+ assertTrue(qualifiedIntents.contains(new IntentName("sec.confidentiality/message/head")));
+ assertFalse(qualifiedIntents.contains(new IntentName("sec.confidentiality/message")));
+ assertFalse(qualifiedIntents.contains(new IntentName("sec.confidentiality")));
+ }
+
+ public void testIsApplicable() {
+ assertTrue(intentReg.isApplicable(new IntentName("sec.confidentiality/message"), WS_BINDING));
+ assertFalse(intentReg.isApplicable(new IntentName("sec.confidentiality/transport"), WS_BINDING));
+ assertFalse(intentReg.isApplicable(new IntentName("test.confidentiality/transport"), WS_BINDING));
+ }
+
+ public void testRegister() {
+ Intent messageintent = new Intent(new IntentName("sec.confidentiality/transport"), null);
+ messageintent.addAppliedArtifacts(WS_BINDING);
+ messageintent.addAppliedArtifacts(JMS_BINDING);
+ intentReg.register(messageintent);
+ assertTrue(intentReg.isApplicable(new IntentName("sec.confidentiality/transport"), WS_BINDING));
+ assertTrue(intentReg.isApplicable(new IntentName("sec.confidentiality/transport"), JMS_BINDING));
+
+ }
+
+ public void testIsQualifiedIntent() {
+ Intent messageintent = new Intent(new IntentName("sec.confidentiality/transport"), null);
+ messageintent.addAppliedArtifacts(WS_BINDING);
+ messageintent.addAppliedArtifacts(JMS_BINDING);
+ intentReg.register(messageintent);
+ Intent allintent = new Intent(new IntentName("sec.confidentiality/all"), null);
+ allintent.addAppliedArtifacts(WS_BINDING);
+
+ assertTrue(intentReg.isQualifiedIntent(new IntentName("sec.confidentiality/transport")));
+ assertTrue(intentReg.isQualifiedIntent(new IntentName("sec.confidentiality/message/body")));
+ assertTrue(intentReg.isQualifiedIntent(new IntentName("sec.confidentiality/message/body")));
+ assertFalse(intentReg.isQualifiedIntent(new IntentName("sec.confidentiality/message")));
+ assertFalse(intentReg.isQualifiedIntent(new IntentName("sec.confidentiality")));
+ }
+
+ public void testUnRegister() {
+ Intent messageintent = new Intent(new IntentName("sec.confidentiality/transport"), null);
+ messageintent.addAppliedArtifacts(WS_BINDING);
+ messageintent.addAppliedArtifacts(JMS_BINDING);
+ intentReg.register(messageintent);
+ intentReg.unRegister(messageintent);
+ assertFalse(intentReg.isApplicable(new IntentName("sec.confidentiality/transport"), WS_BINDING));
+ assertFalse(intentReg.isApplicable(new IntentName("sec.confidentiality/transport"), JMS_BINDING));
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/policy/PolicyEngineImplTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/policy/PolicyEngineImplTestCase.java
new file mode 100644
index 0000000000..f6db640e2b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/policy/PolicyEngineImplTestCase.java
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.policy;
+
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+
+import static org.osoa.sca.Constants.SCA_NS;
+
+import org.apache.tuscany.spi.model.Intent;
+import org.apache.tuscany.spi.model.IntentName;
+import org.apache.tuscany.spi.model.PolicyModel;
+import org.apache.tuscany.spi.model.PolicySet;
+import org.apache.tuscany.spi.policy.IntentRegistry;
+import org.apache.tuscany.spi.policy.PolicyEngine;
+import org.apache.tuscany.spi.policy.PolicySetContainer;
+import org.apache.tuscany.spi.policy.SCATypeManager;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.loader.PolicySetLoader;
+
+public class PolicyEngineImplTestCase extends TestCase {
+ private static final QName POLICYSET = new QName(SCA_NS, "policySet");
+ private static final QName WS_BINDING = new QName(SCA_NS, "binding.ws");
+ private IntentRegistry intentReg;
+ private PolicyEngine policyEngine;
+
+
+ public void testgetPolicy() throws Exception {
+ Collection<PolicyModel> policies =
+ policyEngine.getPolicy(new IntentName[]{new IntentName("sec.authentication/cert")}, null, WS_BINDING);
+ assertEquals(2, policies.size());
+ policies =
+ policyEngine.getPolicy(new IntentName[]{new IntentName("sec.authentication/basic")}, null, WS_BINDING);
+ assertEquals(1, policies.size());
+
+ //test for unqualified intent with default value on intentMap
+ policies = policyEngine.getPolicy(new IntentName[]{new IntentName("sec.authentication")}, null, WS_BINDING);
+ assertEquals(2, policies.size());
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ PolicySetLoader loader = new PolicySetLoader(null);
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ InputStream resourceAsStream = this.getClass().getResourceAsStream("PolicySet.scdl");
+ XMLStreamReader reader = factory.createXMLStreamReader(resourceAsStream);
+ PolicySetContainerImpl psc = new PolicySetContainerImpl();
+ while (true) {
+ int state = reader.next();
+ if (state == XMLStreamConstants.END_DOCUMENT) {
+ break;
+ }
+ if (XMLStreamConstants.START_ELEMENT == state && reader.getName().equals(POLICYSET)) {
+ psc.addPolicySet(loader.load(null, reader, null));
+ }
+
+ }
+ resourceAsStream.close();
+ intentReg = new IntentRegistryImpl();
+ policyEngine = new PolicyEngineImpl(intentReg, psc, new SCATypeManagerImpl());
+
+ Intent bodyintent = new Intent(new IntentName("sec.confidentiality/message/body"), "test");
+ bodyintent.addAppliedArtifacts(WS_BINDING);
+ intentReg.register(bodyintent);
+
+ Intent allintent = new Intent(new IntentName("sec.confidentiality/message/all"), "test");
+ allintent.addAppliedArtifacts(WS_BINDING);
+ intentReg.register(allintent);
+
+ Intent confidentialityintent = new Intent(new IntentName("sec.confidentiality"), "test");
+ confidentialityintent.addAppliedArtifacts(WS_BINDING);
+ intentReg.register(confidentialityintent);
+
+ Intent messageintent = new Intent(new IntentName("sec.confidentiality/message"), null);
+ messageintent.addAppliedArtifacts(WS_BINDING);
+ intentReg.register(messageintent);
+
+ Intent authintent = new Intent(new IntentName("sec.authentication"), null);
+ authintent.addAppliedArtifacts(WS_BINDING);
+ intentReg.register(authintent);
+
+ Intent certintent = new Intent(new IntentName("sec.authentication/cert"), null);
+ certintent.addAppliedArtifacts(WS_BINDING);
+ intentReg.register(certintent);
+
+ Intent basicintent = new Intent(new IntentName("sec.authentication/basic"), null);
+ basicintent.addAppliedArtifacts(WS_BINDING);
+ intentReg.register(basicintent);
+
+ }
+
+ private class PolicySetContainerImpl implements PolicySetContainer {
+
+ private Map<QName, PolicySet> sets = new HashMap<QName, PolicySet>();
+
+ public Collection<PolicySet> getAllPolicySet() {
+ return sets.values();
+ }
+
+ public PolicySet getPolicySet(QName name) {
+ return sets.get(name);
+ }
+
+ public void addPolicySet(PolicySet pset) {
+ sets.put(pset.getName(), pset);
+ }
+
+ }
+
+ private class SCATypeManagerImpl implements SCATypeManager {
+
+ public boolean isTypeOf(QName subType, QName type) {
+ return subType.equals(type);
+ }
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/property/PropertyHelperTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/property/PropertyHelperTestCase.java
new file mode 100644
index 0000000000..4f2e2fbf42
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/property/PropertyHelperTestCase.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.core.property;
+
+import java.net.URL;
+import javax.xml.namespace.NamespaceContext;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.databinding.xml.String2Node;
+import org.easymock.EasyMock;
+
+/**
+ *
+ */
+public class PropertyHelperTestCase extends TestCase {
+ private static final String IPO_XML =
+ "<?xml version=\"1.0\"?>" + "<ipo:purchaseOrder"
+ + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ + " xmlns:ipo=\"http://www.example.com/IPO\""
+ + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\""
+ + " orderDate=\"1999-12-01\">"
+ + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">"
+ + " <name>Helen Zoe</name>"
+ + " <street>47 Eden Street</street>"
+ + " <city>Cambridge</city>"
+ + " <postcode>CB1 1JR</postcode>"
+ + " </shipTo>"
+ + " <billTo xsi:type=\"ipo:USAddress\">"
+ + " <name>Robert Smith</name>"
+ + " <street>8 Oak Avenue</street>"
+ + " <city>Old Town</city>"
+ + " <state>PA</state>"
+ + " <zip>95819</zip>"
+ + " </billTo>"
+ + " <items>"
+ + " <item partNum=\"833-AA\">"
+ + " <productName>Lapis necklace</productName>"
+ + " <quantity>1</quantity>"
+ + " <USPrice>99.95</USPrice>"
+ + " <ipo:comment>Want this for the holidays</ipo:comment>"
+ + " <shipDate>1999-12-05</shipDate>"
+ + " </item>"
+ + " </items>"
+ + "</ipo:purchaseOrder>";
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testXPath() throws Exception {
+ String2Node t = new String2Node();
+ Node node = t.transform(IPO_XML, null);
+
+ Document doc = PropertyHelper.evaluate(null, node, "/ipo:purchaseOrder/billTo");
+ assertNotNull(doc);
+
+ NamespaceContext context = EasyMock.createMock(NamespaceContext.class);
+ EasyMock.expect(context.getNamespaceURI("ipo")).andReturn("http://www.example.com/IPO").anyTimes();
+ EasyMock.replay(context);
+ doc = PropertyHelper.evaluate(context, node, "/ipo:purchaseOrder/items");
+ assertNotNull(doc);
+ doc = PropertyHelper.evaluate(context, node, "/ipo:purchaseOrder/billTo");
+ assertNotNull(doc);
+ doc = PropertyHelper.evaluate(context, node, "/");
+ assertNotNull(doc);
+ doc = PropertyHelper.evaluate(context, node, "/ipo:purchaseOrder/billTo1");
+ assertNull(doc);
+ }
+
+ public void testFile() throws Exception {
+ URL url = getClass().getResource("ipo.xml");
+ Document doc = PropertyHelper.loadFromFile(url.toExternalForm(), null);
+ assertNotNull(doc);
+
+ DeploymentContext context = EasyMock.createMock(DeploymentContext.class);
+ EasyMock.expect(context.getClassLoader()).andReturn(getClass().getClassLoader());
+ EasyMock.replay(context);
+ doc = PropertyHelper.loadFromFile("org/apache/tuscany/core/property/ipo.xml", context);
+ assertNotNull(doc);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/property/SimplePropertyObjectFactoryTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/property/SimplePropertyObjectFactoryTestCase.java
new file mode 100644
index 0000000000..9ef1faccfe
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/property/SimplePropertyObjectFactoryTestCase.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.core.property;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.PropertyValue;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SimplePropertyObjectFactoryTestCase extends TestCase {
+
+ private <T> PropertyValue<T> mock(String value) {
+ Document document = EasyMock.createMock(Document.class);
+ Element element = EasyMock.createMock(Element.class);
+ EasyMock.expect(document.getDocumentElement()).andReturn(element);
+ EasyMock.expect(element.getTextContent()).andReturn(value);
+ EasyMock.replay(document, element);
+ return new PropertyValue<T>(null, document);
+ }
+
+ public void testInteger() throws Exception {
+
+ PropertyObjectFactoryImpl factory = new PropertyObjectFactoryImpl();
+ Property<Integer> property = new Property<Integer>();
+ property.setJavaType(Integer.class);
+ PropertyValue<Integer> propertyValue = mock("1");
+ ObjectFactory<Integer> oFactory = factory.createObjectFactory(property, propertyValue);
+ assertEquals(1, oFactory.getInstance().intValue());
+ }
+
+ public void testPrimitiveInt() throws Exception {
+ PropertyObjectFactoryImpl factory = new PropertyObjectFactoryImpl();
+ Property<Integer> property = new Property<Integer>();
+ property.setJavaType(Integer.TYPE);
+ PropertyValue<Integer> propertyValue = mock("1");
+ ObjectFactory<Integer> oFactory = factory.createObjectFactory(property, propertyValue);
+ assertEquals(1, oFactory.getInstance().intValue());
+ }
+
+ public void testString() throws Exception {
+ PropertyObjectFactoryImpl factory = new PropertyObjectFactoryImpl();
+ Property<String> property = new Property<String>();
+ property.setJavaType(String.class);
+ PropertyValue<String> propertyValue = mock("1");
+ ObjectFactory<String> oFactory = factory.createObjectFactory(property, propertyValue);
+ assertEquals("1", oFactory.getInstance());
+ }
+
+ public void testByteArray() throws Exception {
+ PropertyObjectFactoryImpl factory = new PropertyObjectFactoryImpl();
+ Property<byte[]> property = new Property<byte[]>();
+ property.setJavaType(byte[].class);
+ PropertyValue<byte[]> propertyValue = mock("TWFu"); // BASE64 for "Man"
+ ObjectFactory<byte[]> oFactory = factory.createObjectFactory(property, propertyValue);
+ byte[] result = oFactory.getInstance();
+ byte[] expected = "Man".getBytes();
+ for (int i = 0; i < result.length; i++) {
+ byte b = result[i];
+ if (b != expected[i]) {
+ fail();
+ }
+ }
+ }
+
+ public void testBoolean() throws Exception {
+ PropertyObjectFactoryImpl factory = new PropertyObjectFactoryImpl();
+ Property<Boolean> property = new Property<Boolean>();
+ property.setJavaType(Boolean.class);
+ PropertyValue<Boolean> propertyValue = mock("true");
+ ObjectFactory<Boolean> oFactory = factory.createObjectFactory(property, propertyValue);
+ assertTrue(oFactory.getInstance());
+ }
+
+ public void testPrimitiveBoolean() throws Exception {
+ PropertyObjectFactoryImpl factory = new PropertyObjectFactoryImpl();
+ Property<Boolean> property = new Property<Boolean>();
+ property.setJavaType(Boolean.TYPE);
+ PropertyValue<Boolean> propertyValue = mock("true");
+ ObjectFactory<Boolean> oFactory = factory.createObjectFactory(property, propertyValue);
+ assertTrue(oFactory.getInstance());
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/resolver/DefaultAutowireResolverTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/resolver/DefaultAutowireResolverTestCase.java
new file mode 100644
index 0000000000..6d50489f18
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/resolver/DefaultAutowireResolverTestCase.java
@@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.resolver;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.model.AtomicImplementation;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ReferenceTarget;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DefaultAutowireResolverTestCase extends TestCase {
+ private static final URI REFERENCE_URI = URI.create("source#ref");
+ private static final URI TARGET_URI = URI.create("target#service");
+ private DefaultAutowireResolver resolver;
+
+ public void testAutowireAtomicToAtomic() throws Exception {
+ ComponentDefinition<CompositeImplementation> composite = createComposite("composite");
+ CompositeComponentType<?, ?, ?> type = composite.getImplementation().getComponentType();
+ ComponentDefinition<MockAtomicImpl> source = createSourceAtomic(Foo.class);
+ type.add(source);
+ ComponentDefinition<MockAtomicImpl> target = createTargetAtomic(Foo.class);
+ type.add(target);
+ resolver.resolve(null, composite);
+ ReferenceTarget refTarget = source.getReferenceTargets().get(REFERENCE_URI.getFragment());
+ assertEquals(TARGET_URI, refTarget.getTargets().get(0));
+ }
+
+ public void testAutowireAtomicToAtomicRequiresSuperInterface() throws Exception {
+ ComponentDefinition<CompositeImplementation> composite = createComposite("composite");
+ CompositeComponentType<?, ?, ?> type = composite.getImplementation().getComponentType();
+ ComponentDefinition<MockAtomicImpl> source = createSourceAtomic(SuperFoo.class);
+ type.add(source);
+ ComponentDefinition<MockAtomicImpl> target = createTargetAtomic(Foo.class);
+ type.add(target);
+ resolver.resolve(null, composite);
+ ReferenceTarget refTarget = source.getReferenceTargets().get(REFERENCE_URI.getFragment());
+ assertEquals(TARGET_URI, refTarget.getTargets().get(0));
+ }
+
+ public void testAutowireAtomicToAtomicRequiresSubInterface() throws Exception {
+ ComponentDefinition<CompositeImplementation> composite = createComposite("composite");
+ CompositeComponentType<?, ?, ?> type = composite.getImplementation().getComponentType();
+ ComponentDefinition<MockAtomicImpl> source = createSourceAtomic(Foo.class);
+ type.add(source);
+ ComponentDefinition<MockAtomicImpl> target = createTargetAtomic(SuperFoo.class);
+ type.add(target);
+ try {
+ resolver.resolve(null, composite);
+ fail();
+ } catch (AutowireTargetNotFoundException e) {
+ // expected
+ }
+ }
+
+ public void testAutowireAtomicToAtomicIncompatibleInterfaces() throws Exception {
+ ComponentDefinition<CompositeImplementation> composite = createComposite("composite");
+ CompositeComponentType<?, ?, ?> type = composite.getImplementation().getComponentType();
+ ComponentDefinition<MockAtomicImpl> source = createSourceAtomic(Foo.class);
+ type.add(source);
+ ComponentDefinition<MockAtomicImpl> target = createTargetAtomic(String.class);
+ type.add(target);
+ try {
+ resolver.resolve(null, composite);
+ fail();
+ } catch (AutowireTargetNotFoundException e) {
+ // expected
+ }
+ }
+
+ public void testNestedAutowireAtomicToAtomic() throws Exception {
+ ComponentDefinition<CompositeImplementation> composite = createComposite("composite");
+ CompositeComponentType<?, ?, ?> type = composite.getImplementation().getComponentType();
+ ComponentDefinition<MockAtomicImpl> source = createSourceAtomic(Foo.class);
+ type.add(source);
+ ComponentDefinition<MockAtomicImpl> target = createTargetAtomic(Foo.class);
+ type.add(target);
+ ComponentDefinition<CompositeImplementation> parent = createComposite("parent");
+ parent.getImplementation().getComponentType().add(composite);
+ resolver.resolve(null, parent);
+ ReferenceTarget refTarget = source.getReferenceTargets().get(REFERENCE_URI.getFragment());
+ assertEquals(TARGET_URI, refTarget.getTargets().get(0));
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ resolver = new DefaultAutowireResolver();
+ }
+
+ private ComponentDefinition<CompositeImplementation> createComposite(String uri) {
+ URI parentUri = URI.create(uri);
+ CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ CompositeImplementation impl = new CompositeImplementation();
+ impl.setComponentType(type);
+ return new ComponentDefinition<CompositeImplementation>(parentUri, impl);
+ }
+
+ private ComponentDefinition<MockAtomicImpl> createSourceAtomic(Class<?> requiredInterface) {
+ URI uri = URI.create("source");
+ ServiceContract contract = new ServiceContract() {
+ };
+ contract.setInterfaceClass(requiredInterface);
+ ReferenceDefinition reference = new ReferenceDefinition(URI.create("#ref"), contract);
+ reference.setRequired(true);
+ MockComponentType type = new MockComponentType();
+ type.add(reference);
+ MockAtomicImpl impl = new MockAtomicImpl();
+ impl.setComponentType(type);
+ ComponentDefinition<MockAtomicImpl> definition = new ComponentDefinition<MockAtomicImpl>(uri, impl);
+ ReferenceTarget target = new ReferenceTarget();
+ target.setReferenceName(REFERENCE_URI);
+ target.setAutowire(true);
+ definition.add(target);
+ return definition;
+ }
+
+ private ComponentDefinition<MockAtomicImpl> createTargetAtomic(Class<?> serviceInterface) {
+ URI uri = URI.create("target");
+ ServiceDefinition service = new ServiceDefinition();
+ service.setUri(URI.create("#service"));
+ ServiceContract contract = new ServiceContract() {
+ };
+ contract.setInterfaceClass(serviceInterface);
+ service.setServiceContract(contract);
+ MockComponentType type = new MockComponentType();
+ type.add(service);
+ MockAtomicImpl impl = new MockAtomicImpl();
+ impl.setComponentType(type);
+ return new ComponentDefinition<MockAtomicImpl>(uri, impl);
+ }
+
+ private class MockAtomicImpl extends AtomicImplementation<MockComponentType> {
+
+ }
+
+ private class MockComponentType extends ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> {
+
+ }
+
+ private interface SuperFoo {
+
+ }
+
+ private interface Foo extends SuperFoo {
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/artifact/LocalMavenRepositoryTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/artifact/LocalMavenRepositoryTestCase.java
new file mode 100644
index 0000000000..0efecb9302
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/artifact/LocalMavenRepositoryTestCase.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.core.services.artifact;
+
+import java.io.File;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.services.artifact.Artifact;
+
+/**
+ * This testcase assumes that there is a maven repo in the default location.
+ *
+ * @version $Rev$ $Date$
+ */
+public class LocalMavenRepositoryTestCase extends TestCase {
+ private static final String VERSION = "3.8.1";
+ private LocalMavenRepository repo;
+ private Artifact artifact;
+ private String path;
+
+ public void testPathWithNoClassifier() {
+ assertEquals(path, repo.getPath(artifact));
+ }
+
+ public void testPathWithClassifier() {
+ artifact.setClassifier("x86");
+ path = "junit/junit/" + VERSION + "/junit-" + VERSION + "-x86.jar";
+ assertEquals(path, repo.getPath(artifact));
+ }
+
+ public void testArtifactFoundInRepo() throws MalformedURLException, UnsupportedEncodingException {
+ String home = System.getProperty("user.home");
+ File file = new File(home + "/.m2/repository", path);
+ repo.resolve(artifact);
+ assertEquals(file.toURI().toURL(), artifact.getUrl());
+ }
+
+ public void testArtifactNotFoundInRepo() throws MalformedURLException {
+ artifact.setClassifier("x86");
+ repo.resolve(artifact);
+ assertNull(artifact.getUrl());
+ }
+
+ public void testNonNullURLIsUnmodified() throws MalformedURLException {
+ URL url = new URL("http://www.apache.org");
+ artifact.setUrl(url);
+ repo.resolve(artifact);
+ assertSame(url, artifact.getUrl());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ repo = new LocalMavenRepository(".m2/repository");
+
+ artifact = new Artifact();
+ artifact.setGroup("junit");
+ artifact.setName("junit");
+ artifact.setVersion(VERSION);
+ artifact.setType("jar");
+ path = "junit/junit/" + VERSION + "/junit-" + VERSION + ".jar";
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/AssemblyServiceImplTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/AssemblyServiceImplTestCase.java
new file mode 100644
index 0000000000..bf48d9061a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/AssemblyServiceImplTestCase.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.core.services.deployment;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.generator.GeneratorRegistry;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.marshaller.ModelMarshallerRegistry;
+import org.apache.tuscany.spi.services.discovery.DiscoveryService;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.resolver.AutowireResolver;
+import org.apache.tuscany.host.deployment.UnsupportedContentTypeException;
+import org.easymock.classextension.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AssemblyServiceImplTestCase extends TestCase {
+ private AssemblyServiceImpl service;
+
+ public void testApplyChangesWithNullURL() {
+ try {
+ service.applyChanges(null);
+ fail();
+ } catch (IllegalArgumentException e) {
+ //ok
+ } catch (Throwable t) {
+ fail();
+ }
+ }
+
+ public void testApplyChangesWhenURLContentTypeIsNull() throws Exception {
+ final URLConnection urlConnection = EasyMock.createMock(URLConnection.class);
+ EasyMock.expect(urlConnection.getContentType()).andReturn(null);
+ EasyMock.replay(urlConnection);
+ URLStreamHandler handler = new MockURLStreamHandler(urlConnection);
+
+ URL url = new URL(null, "file:/tmp/foo.xml", handler);
+ try {
+ service.applyChanges(url);
+ } catch (UnsupportedContentTypeException e) {
+ assertNull(e.getMessage());
+ assertEquals(url.toString(), e.getIdentifier());
+ EasyMock.verify(urlConnection);
+ } catch (Throwable t) {
+ fail();
+ }
+ }
+
+ public void testApplyChangesWithNullStream() {
+ try {
+ service.applyChanges(null, "xxx/xxx");
+ fail();
+ } catch (IllegalArgumentException e) {
+ //ok
+ } catch (Throwable t) {
+ fail();
+ }
+ }
+
+ public void testApplyChangesWithNullContentType() {
+ InputStream is = EasyMock.createMock(InputStream.class);
+ EasyMock.replay(is);
+ try {
+ service.applyChanges(is, null);
+ fail();
+ } catch (IllegalArgumentException e) {
+ EasyMock.verify(is);
+ } catch (Throwable t) {
+ fail();
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ LoaderRegistry loaderRegistry = EasyMock.createMock(LoaderRegistry.class);
+ EasyMock.replay(loaderRegistry);
+ GeneratorRegistry generatorRegistry = EasyMock.createMock(GeneratorRegistry.class);
+ EasyMock.replay(generatorRegistry);
+ AutowireResolver resolver = EasyMock.createMock(AutowireResolver.class);
+ EasyMock.replay(resolver);
+ ScopeRegistry scopeRegistry = EasyMock.createMock(ScopeRegistry.class);
+ EasyMock.replay(scopeRegistry);
+ ModelMarshallerRegistry marshallerRegistry = EasyMock.createMock(ModelMarshallerRegistry.class);
+ EasyMock.replay(marshallerRegistry);
+ DiscoveryService discoveryService = EasyMock.createMock(DiscoveryService.class);
+ EasyMock.replay(discoveryService);
+ service = new AssemblyServiceImpl(loaderRegistry, generatorRegistry, resolver, scopeRegistry, marshallerRegistry, discoveryService);
+ }
+
+ private static class MockURLStreamHandler extends URLStreamHandler {
+ private final URLConnection urlConnection;
+
+ public MockURLStreamHandler(URLConnection urlConnection) {
+ this.urlConnection = urlConnection;
+ }
+
+ protected URLConnection openConnection(URL url) throws IOException {
+ return urlConnection;
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContentTypeDescriberImplTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContentTypeDescriberImplTestCase.java
new file mode 100644
index 0000000000..f163edea6d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContentTypeDescriberImplTestCase.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.core.services.deployment;
+
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+public class ContentTypeDescriberImplTestCase extends TestCase {
+ private ContentTypeDescriberImpl contentTypeBuilder;
+
+ public void testResolveContentType() throws Exception {
+ URL artifactURL = getClass().getResource("test.scdl");
+ assertEquals("application/v.tuscany.scdl", contentTypeBuilder.getContentType(artifactURL, null));
+ }
+
+ public void testUnknownResolveContentType() throws Exception {
+ URL artifactURL = getClass().getResource("test.ext");
+ assertNull(contentTypeBuilder.getContentType(artifactURL, null));
+ }
+
+ public void testDefaultContentType() throws Exception {
+ URL artifactURL = getClass().getResource("test.ext");
+ assertEquals("application/v.tuscany.ext", contentTypeBuilder.getContentType(artifactURL,
+ "application/v.tuscany.ext"));
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ contentTypeBuilder = new ContentTypeDescriberImpl();
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryTestCase.java
new file mode 100644
index 0000000000..fa21ccfd20
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryTestCase.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.core.services.deployment;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+
+import org.apache.tuscany.core.util.FileHelper;
+
+import junit.framework.TestCase;
+
+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";
+ URI contribution = URI.create("sample-calculator.jar");
+ InputStream contributionStream = getClass().getResourceAsStream(resourceLocation);
+ repository.store(contribution, contributionStream);
+
+ URL contributionURL = repository.find(contribution);
+ assertNotNull(contributionURL);
+ }
+
+ public void testRemove() throws Exception {
+ String resourceLocation = "/repository/sample-calculator.jar";
+ URI contribution = URI.create("sample-calculator.jar");
+ InputStream contributionStream = getClass().getResourceAsStream(resourceLocation);
+ repository.store(contribution, contributionStream);
+
+ repository.remove(contribution);
+ URL contributionURL = repository.find(contribution);
+ assertNull(contributionURL);
+ }
+
+ public void testList() throws Exception {
+ String resourceLocation = "/repository/sample-calculator.jar";
+ URI contribution = URI.create("sample-calculator.jar");
+ InputStream contributionStream = getClass().getResourceAsStream(resourceLocation);
+ repository.store(contribution, contributionStream);
+
+ assertEquals(1, repository.list().size());
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ FileHelper.deleteDirectory(new File("target/repository"));
+ }
+} \ No newline at end of file
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionServiceImplTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionServiceImplTestCase.java
new file mode 100644
index 0000000000..3f259fe0a3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionServiceImplTestCase.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.core.services.deployment;
+
+import org.apache.tuscany.spi.deployer.ContentTypeDescriber;
+import org.apache.tuscany.spi.deployer.ContributionProcessorRegistry;
+import org.apache.tuscany.spi.deployer.ContributionRepository;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.host.deployment.ContributionService;
+
+/**
+ * This is more intended to be a integration test then a unit test. *
+ */
+public class ContributionServiceImplTestCase extends TestCase {
+ private static final String JAR_CONTRIBUTION = "/repository/sample-calculator.jar";
+ private ContributionRepository repository;
+ private ContentTypeDescriber contentTypeDescriber;
+ private ContributionProcessorRegistry registry;
+ private ContributionService contributionService;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+// this.repository = new ContributionRepositoryImpl("target/repository");
+//
+// this.contentTypeDescriber = new ContentTypeDescriberImpl();
+//
+// this.registry = new ContributionProcessorRegistryImpl(contentTypeDescriber);
+//
+// JarContributionProcessor jarProcessor = new JarContributionProcessor();
+// jarProcessor.setContributionProcessorRegistry(this.registry);
+// this.registry.register(JarContributionProcessor.CONTENT_TYPE, jarProcessor);
+//
+// JavaContributionProcessor javaProcessor = new JavaContributionProcessor(null);
+// javaProcessor.setContributionProcessorRegistry(this.registry);
+// this.registry.register(JavaContributionProcessor.CONTENT_TYPE, javaProcessor);
+//
+//
+// contributionService = new ContributionServiceImpl(repository, registry);
+ }
+
+ public void testContributeURL() throws Exception {
+// URL contribution = getClass().getResource(JAR_CONTRIBUTION);
+//
+// URI contributionURI = contributionService.contribute(contribution);
+// assertNotNull(contributionURI);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessorTestCase.java
new file mode 100644
index 0000000000..a6205e4b9b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessorTestCase.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.core.services.deployment.contribution;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+public class FolderContributionProcessorTestCase extends TestCase {
+ private static final String DIRECTORY_CONTRIBUTION =
+ "//D:/DEV/Projects/Tuscany/source/java-sca-integration/samples/sca/calculator";
+
+ private File contributionRoot;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.contributionRoot = new File(DIRECTORY_CONTRIBUTION);
+ }
+
+ public final void testProcessJarArtifacts() throws Exception {
+ // FolderContributionProcessor folderContribution = new FolderContributionProcessor();
+ // ContributionProcessorRegistry mockRegistry = EasyMock.createMock(ContributionProcessorRegistry.class);
+ // mockRegistry.register(FolderContributionProcessor.CONTENT_TYPE, folderContribution);
+ // EasyMock.expectLastCall().anyTimes();
+ // EasyMock.replay(mockRegistry);
+ // folderContribution.setContributionProcessorRegistry(mockRegistry);
+ // folderContribution.start();
+ // EasyMock.verify(mockRegistry);
+ //
+ // Contribution contribution = new Contribution(URI.create("sca://contributions/001"));
+ // contribution.setLocation(this.contributionRoot.toURL());
+ // folderContribution.processContent(contribution, contribution.getUri(), null);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessorTestCase.java
new file mode 100644
index 0000000000..3762622425
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessorTestCase.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.core.services.deployment.contribution;
+
+import junit.framework.TestCase;
+
+public class JarContributionProcessorTestCase extends TestCase {
+ private static final String JAR_CONTRIBUTION = "/repository/sample-calculator.jar";
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public final void testProcessJarArtifacts() throws Exception {
+ /*
+ JarContributionProcessor jarContribution = new JarContributionProcessor();
+ ContributionProcessorRegistry mockRegistry = EasyMock.createMock(ContributionProcessorRegistry.class);
+ mockRegistry.register(JarContributionProcessor.CONTENT_TYPE, jarContribution);
+ EasyMock.expectLastCall().once();
+ EasyMock.replay(mockRegistry);
+ jarContribution.setContributionProcessorRegistry(mockRegistry);
+ jarContribution.start();
+ EasyMock.verify(mockRegistry);
+ URL jarURL = getClass().getResource(JarContributionProcessorTestCase.JAR_CONTRIBUTION);
+ Contribution contribution = new Contribution(URI.create("sca://contributions/001"));
+ contribution.setLocation(jarURL);
+ jarContribution.processContent(contribution, contribution.getUri(), jarURL.openStream());
+ */
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessorTestCase.java
new file mode 100644
index 0000000000..89f9a20b6b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessorTestCase.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.core.services.deployment.contribution;
+
+import java.net.URL;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+
+import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.implementation.IntrospectionRegistryImpl;
+import org.apache.tuscany.core.implementation.processor.DestroyProcessor;
+import org.apache.tuscany.core.implementation.processor.ImplementationProcessorServiceImpl;
+import org.apache.tuscany.core.implementation.processor.InitProcessor;
+import org.apache.tuscany.core.implementation.processor.PropertyProcessor;
+import org.apache.tuscany.core.implementation.processor.ReferenceProcessor;
+import org.apache.tuscany.core.implementation.processor.ResourceProcessor;
+import org.apache.tuscany.core.implementation.processor.ScopeProcessor;
+import org.apache.tuscany.core.monitor.NullMonitorFactory;
+
+public class JavaContributionProcessorTestCase extends TestCase {
+ private static final String JAR_CONTRIBUTION = "/repository/sample-calculator.jar";
+ private static final String JAVA_ARTIFACT_URL =
+ "jar:file://repository/sample-calculator.jar!/calculator/AddService.class";
+ private IntrospectionRegistryImpl registry;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ registry = new IntrospectionRegistryImpl();
+ registry.setMonitor(new NullMonitorFactory().getMonitor(IntrospectionRegistryImpl.Monitor.class));
+ registry.registerProcessor(new DestroyProcessor());
+ registry.registerProcessor(new InitProcessor());
+ registry.registerProcessor(new ScopeProcessor());
+ JavaInterfaceProcessorRegistryImpl interfaceProcessorRegistry = new JavaInterfaceProcessorRegistryImpl();
+ ImplementationProcessorService service = new ImplementationProcessorServiceImpl(interfaceProcessorRegistry);
+ registry.registerProcessor(new PropertyProcessor(service));
+ registry.registerProcessor(new ReferenceProcessor(interfaceProcessorRegistry));
+ registry.registerProcessor(new ResourceProcessor());
+ }
+
+ protected URL getClassURL() throws Exception {
+ URL jarURL = getClass().getResource(JAR_CONTRIBUTION);
+ JarInputStream jar = new JarInputStream(getClass().getResourceAsStream(JAR_CONTRIBUTION));
+ URL rootURL = new URL("jar:" + jarURL.toString() + "!/");
+ URL classURL = null;
+
+ try {
+ while (true) {
+ JarEntry entry = jar.getNextJarEntry();
+ if (entry.getName().endsWith(".class")) {
+
+ classURL = new URL(rootURL, entry.getName());
+ break;
+ }
+ }
+ } finally {
+ jar.close();
+ }
+ return classURL;
+ }
+
+ public final void testProcessJarArtifacts() throws Exception {
+ //ContributionProcessor javaContributionProcessor = new JavaContributionProcessor(registry);
+
+ //URL jarURL = this.getClassURL();
+ //javaContributionProcessor.processContent(null, jarURL, jarURL.openStream());
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistryTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistryTestCase.java
new file mode 100644
index 0000000000..c3eb2fa1bf
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistryTestCase.java
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.services.host;
+
+import org.apache.tuscany.spi.host.ResourceHost;
+import org.apache.tuscany.spi.host.ResourceResolutionException;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DelegatingResourceHostRegistryTestCase extends TestCase {
+
+ public void testResolveByType() throws Exception {
+ Object ret = new Object();
+ DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+ registry.registerResource(Object.class, ret);
+ assertEquals(ret, registry.resolveResource(Object.class));
+ }
+
+ public void testResolveByUri() throws Exception {
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(String.class, "Foo://foo")).andReturn("result");
+ EasyMock.replay(host);
+ DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+ registry.registerResourceHost("Foo://", host);
+ assertEquals("result", registry.resolveResource(String.class, "Foo://foo"));
+ EasyMock.verify(host);
+ }
+
+ public void testResolveBySCAUri() throws Exception {
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.replay(host);
+ DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+ registry.registerResourceHost("Foo://", host);
+ Object ret = new Object();
+ registry.registerResource(Object.class, "foo", ret);
+ assertEquals(ret, registry.resolveResource(Object.class, "SCA://foo"));
+ EasyMock.verify(host);
+ }
+
+ public void testResolveByUriNotFound() throws Exception {
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.replay(host);
+ DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+ registry.registerResourceHost("Foo://", host);
+ try {
+ assertEquals("result", registry.resolveResource(String.class, "Bar://bar"));
+ fail();
+ } catch (ResourceResolutionException e) {
+ //expected
+ }
+ EasyMock.verify(host);
+ }
+
+ public void testUnregisterHost() throws Exception {
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.replay(host);
+ DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+ registry.registerResourceHost("Foo://", host);
+ registry.unregisterResourceHost("Foo://");
+ try {
+ registry.resolveResource(String.class, "Foo://foo");
+ fail();
+ } catch (ResourceResolutionException e) {
+ //expected
+ }
+ EasyMock.verify(host);
+ }
+
+ public void testUnregisterResource() throws Exception {
+ DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+ registry.registerResource(Object.class, new Object());
+ registry.unregisterResource(Object.class);
+ assertNull(registry.resolveResource(Object.class));
+ }
+
+ public void testUnregisterMappedResource() throws Exception {
+ DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+ registry.registerResource(Object.class, "foo", new Object());
+ registry.registerResource(Object.class, new Object());
+ registry.unregisterResource(Object.class);
+ assertNull(registry.resolveResource(Object.class));
+ assertNotNull(registry.resolveResource(Object.class, "foo"));
+ registry.unregisterResource(Object.class, "foo");
+ assertNull(registry.resolveResource(Object.class));
+ }
+
+ public void testReolvedByTypeToMappedResource() throws Exception {
+ DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+ registry.registerResource(Object.class, "foo", new Object());
+ assertNull(registry.resolveResource(Object.class));
+ }
+
+ public void testDelegatingResolveResource() throws Exception {
+ Object ret = new Object();
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(Object.class)).andReturn(ret);
+ EasyMock.replay(host);
+ DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+ registry.registerResourceHost("Foo://", host);
+ assertEquals(ret, registry.resolveResource(Object.class));
+ EasyMock.verify(host);
+ }
+
+ public void testDelegatingResolveResourceByTypeandName() throws Exception {
+ Object ret = new Object();
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.expect(host.resolveResource(EasyMock.eq(Object.class), EasyMock.eq("Foo://bar"))).andReturn(ret);
+ EasyMock.replay(host);
+ DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+ registry.registerResourceHost("Foo://", host);
+ assertEquals(ret, registry.resolveResource(Object.class, "Foo://bar"));
+ EasyMock.verify(host);
+ }
+
+ public void testResolveLocalResourceFirst() throws Exception {
+ Object local = new Object();
+ ResourceHost host = EasyMock.createMock(ResourceHost.class);
+ EasyMock.replay(host);
+ DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry();
+ registry.registerResourceHost("Foo://", host);
+ registry.registerResource(Object.class, local);
+ assertEquals(local, registry.resolveResource(Object.class));
+ EasyMock.verify(host);
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/store/memory/MemoryStoreTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/store/memory/MemoryStoreTestCase.java
new file mode 100644
index 0000000000..06ea7cf903
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/store/memory/MemoryStoreTestCase.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.core.services.store.memory;
+
+import java.net.URI;
+import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+import org.apache.tuscany.spi.services.store.DuplicateRecordException;
+import org.apache.tuscany.spi.services.store.Store;
+import org.apache.tuscany.spi.services.store.StoreExpirationEvent;
+import org.apache.tuscany.spi.services.store.StoreMonitor;
+
+import junit.framework.TestCase;
+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();
+ AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class);
+ EasyMock.replay(component);
+ String id = UUID.randomUUID().toString();
+ Object value = new Object();
+ store.insertRecord(component, id, value, 1);
+ Thread.sleep(100);
+ 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));
+ org.easymock.classextension.EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ 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();
+ AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.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();
+ AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.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();
+ AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.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();
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.getUri()).andReturn(URI.create("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();
+ AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.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();
+ AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.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/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTest.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTest.java
new file mode 100644
index 0000000000..1a5cb4ebe1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTest.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.core.services.work.jsr237;
+
+import org.apache.tuscany.spi.services.work.NotificationListener;
+import org.apache.tuscany.spi.services.work.WorkScheduler;
+
+import commonj.work.WorkManager;
+import junit.framework.TestCase;
+import org.apache.tuscany.core.services.work.jsr237.workmanager.ThreadPoolWorkManager;
+
+public class Jsr237WorkSchedulerTest extends TestCase {
+
+ /*
+ * Test method for 'org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler.scheduleWork(T) <T>'
+ */
+ public void testScheduleWorkT() {
+
+
+ WorkManager workManager = new ThreadPoolWorkManager(1);
+ WorkScheduler workScheduler = new Jsr237WorkScheduler(workManager);
+
+ workScheduler.scheduleWork(new MyRunnable(), new MyNotificationListener());
+
+ }
+
+ /*
+ * Test method for 'org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler.scheduleWork(T,
+ * NotificationListener<T>) <T>'
+ */
+ public void testScheduleWorkTNotificationListenerOfT() {
+
+ }
+
+ private class MyRunnable implements Runnable {
+ public void run() {
+ System.err.println("Test executed");
+ }
+ }
+
+ private class MyNotificationListener implements NotificationListener<MyRunnable> {
+
+ public void workAccepted(MyRunnable work) {
+ System.err.println("Work accepted");
+ }
+
+ public void workCompleted(MyRunnable work) {
+ System.err.println("Work completed");
+ }
+
+ public void workStarted(MyRunnable work) {
+ System.err.println("Work started");
+ }
+
+ public void workRejected(MyRunnable work) {
+ System.err.println("Work rejected");
+ }
+
+ public void workFailed(MyRunnable work, Throwable error) {
+ System.err.println("Work failed");
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTestCase.java
new file mode 100644
index 0000000000..3966f65683
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTestCase.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.core.services.work.jsr237;
+
+import org.apache.tuscany.spi.services.work.NotificationListener;
+import org.apache.tuscany.spi.services.work.WorkSchedulerException;
+
+import commonj.work.Work;
+import commonj.work.WorkItem;
+import commonj.work.WorkListener;
+import commonj.work.WorkManager;
+import commonj.work.WorkRejectedException;
+import junit.framework.TestCase;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class Jsr237WorkSchedulerTestCase extends TestCase {
+
+ public void testSchedule() throws Exception {
+ WorkItem item = createMock(WorkItem.class);
+ WorkManager mgr = createMock(WorkManager.class);
+ mgr.schedule(isA(Work.class));
+ expectLastCall().andReturn(item);
+ replay(mgr);
+ Jsr237WorkScheduler scheduler = new Jsr237WorkScheduler(mgr);
+ Work work = createMock(Work.class);
+ scheduler.scheduleWork(work);
+ verify(mgr);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testListener() throws Exception {
+ WorkItem item = createMock(WorkItem.class);
+ WorkManager mgr = createMock(WorkManager.class);
+ mgr.schedule(isA(Work.class), isA(WorkListener.class));
+ expectLastCall().andReturn(item);
+ replay(mgr);
+ Jsr237WorkScheduler scheduler = new Jsr237WorkScheduler(mgr);
+ Work work = createMock(Work.class);
+ NotificationListener<Runnable> listener = createMock(NotificationListener.class);
+ scheduler.scheduleWork(work, listener);
+ verify(mgr);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testWorkRejectedListener() throws Exception {
+ WorkManager mgr = createMock(WorkManager.class);
+ mgr.schedule(isA(Work.class), isA(WorkListener.class));
+ expectLastCall().andThrow(new WorkRejectedException());
+ replay(mgr);
+ Jsr237WorkScheduler scheduler = new Jsr237WorkScheduler(mgr);
+ Work work = createMock(Work.class);
+ NotificationListener<Runnable> listener = createMock(NotificationListener.class);
+ listener.workRejected(isA(Runnable.class));
+ expectLastCall();
+ replay(listener);
+ scheduler.scheduleWork(work, listener);
+ verify(mgr);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testWorkRejectedNoListener() throws Exception {
+ WorkManager mgr = createMock(WorkManager.class);
+ mgr.schedule(isA(Work.class));
+ expectLastCall().andThrow(new WorkRejectedException());
+ replay(mgr);
+ Jsr237WorkScheduler scheduler = new Jsr237WorkScheduler(mgr);
+ Work work = createMock(Work.class);
+ try {
+ scheduler.scheduleWork(work);
+ fail();
+ } catch (WorkSchedulerException e) {
+ // expected
+ }
+ verify(mgr);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/workmanager/ThreadPoolWorkManagerTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/workmanager/ThreadPoolWorkManagerTestCase.java
new file mode 100644
index 0000000000..33ecd66fdc
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/workmanager/ThreadPoolWorkManagerTestCase.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.core.services.work.jsr237.workmanager;
+
+import java.util.concurrent.CountDownLatch;
+
+import commonj.work.Work;
+import commonj.work.WorkEvent;
+import commonj.work.WorkListener;
+import junit.framework.TestCase;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import org.easymock.IAnswer;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ThreadPoolWorkManagerTestCase extends TestCase {
+
+ public void testSchedule() throws Exception {
+ final CountDownLatch latch = new CountDownLatch(1);
+ Work work = createMock(Work.class);
+ work.run();
+ expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ latch.countDown();
+ return null;
+ }
+ });
+ replay(work);
+ ThreadPoolWorkManager mgr = new ThreadPoolWorkManager(1);
+ mgr.schedule(work);
+ latch.await();
+ verify(work);
+ }
+
+ public void testListener() throws Exception {
+ final CountDownLatch latch = new CountDownLatch(1);
+ WorkListener listener = createStrictMock(WorkListener.class);
+ listener.workAccepted(isA(WorkEvent.class));
+ listener.workStarted(isA(WorkEvent.class));
+ listener.workCompleted(isA(WorkEvent.class));
+ expectLastCall();
+ replay(listener);
+ Work work = createMock(Work.class);
+ work.run();
+ expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ latch.countDown();
+ return null;
+ }
+ });
+ replay(work);
+ ThreadPoolWorkManager mgr = new ThreadPoolWorkManager(1);
+ mgr.schedule(work, listener);
+ latch.await();
+ verify(work);
+ }
+
+ public void testDelayListener() throws Exception {
+ final CountDownLatch latch = new CountDownLatch(1);
+ final CountDownLatch latch2 = new CountDownLatch(1);
+ WorkListener listener = createStrictMock(WorkListener.class);
+ listener.workAccepted(isA(WorkEvent.class));
+ listener.workStarted(isA(WorkEvent.class));
+ listener.workCompleted(isA(WorkEvent.class));
+ expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ latch2.countDown();
+ return null;
+ }
+ });
+ replay(listener);
+ Work work = createMock(Work.class);
+ work.run();
+ expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ latch.await();
+ return null;
+ }
+ });
+ replay(work);
+ ThreadPoolWorkManager mgr = new ThreadPoolWorkManager(1);
+ mgr.schedule(work, listener);
+ latch.countDown();
+ verify(work);
+ }
+
+ public void testErrorListener() throws Exception {
+ final CountDownLatch latch = new CountDownLatch(1);
+ WorkListener listener = createStrictMock(WorkListener.class);
+ listener.workAccepted(isA(WorkEvent.class));
+ listener.workStarted(isA(WorkEvent.class));
+ listener.workCompleted(isA(WorkEvent.class));
+ replay(listener);
+ Work work = createMock(Work.class);
+ work.run();
+ expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ latch.countDown();
+ throw new RuntimeException();
+ }
+ });
+ replay(work);
+ ThreadPoolWorkManager mgr = new ThreadPoolWorkManager(1);
+ mgr.schedule(work, listener);
+ latch.await();
+ verify(work);
+ }
+
+}
+
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/util/Bean1.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/util/Bean1.java
new file mode 100644
index 0000000000..79fad549aa
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/util/Bean1.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.core.util;
+
+
+public class Bean1 extends SuperBean {
+
+ public static final int ALL_BEAN1_FIELDS = 6 + ALL_SUPER_FIELDS;
+ public static final int ALL_BEAN1_PUBLIC_PROTECTED_FIELDS = 5 + ALL_SUPER_PUBLIC_PROTECTED_FIELDS;
+ public static final int ALL_BEAN1_METHODS = 4 + ALL_SUPER_METHODS - 1;
+ public String field3;
+ protected String field2;
+ private String field1;
+
+ public void setMethod1(String param) {
+ }
+
+ public void setMethod1(int param) {
+ }
+
+ public void override(String param) throws Exception {
+ }
+
+
+ public void noOverride(String param) throws Exception {
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/util/Bean2.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/util/Bean2.java
new file mode 100644
index 0000000000..7f7f03da9e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/util/Bean2.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.core.util;
+
+import java.util.List;
+
+import junit.framework.AssertionFailedError;
+
+public class Bean2 {
+
+ private List methodList;
+ private List fieldList;
+
+ public List getMethodList() {
+ return methodList;
+ }
+
+ public void setMethodList(List list) {
+ methodList = list;
+ }
+
+ public List getfieldList() {
+ return fieldList;
+ }
+
+ public void setfieldList(List list) {
+ throw new AssertionFailedError("setter inadvertantly called");
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/util/JavaIntrospectionHelperTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/util/JavaIntrospectionHelperTestCase.java
new file mode 100644
index 0000000000..797b147b54
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/util/JavaIntrospectionHelperTestCase.java
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.util;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.mock.component.Target;
+
+public class JavaIntrospectionHelperTestCase extends TestCase {
+
+ private List testNoGenericsList;
+ private List<String> testList;
+ private Map<String, Bean1> testMap;
+ private Target[] testArray;
+ private String[] testStringArray;
+
+ public JavaIntrospectionHelperTestCase() {
+ super();
+ }
+
+ public JavaIntrospectionHelperTestCase(String arg0) {
+ super(arg0);
+ }
+
+ public void testBean1AllPublicProtectedFields() throws Exception {
+ Set<Field> beanFields = JavaIntrospectionHelper.getAllPublicAndProtectedFields(Bean1.class);
+ assertEquals(4, beanFields.size()); //Bean1.ALL_BEAN1_PUBLIC_PROTECTED_FIELDS
+ }
+
+ public void testGetSuperAllMethods() throws Exception {
+ Set<Method> superBeanMethods = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(SuperBean.class);
+ assertEquals(SuperBean.ALL_SUPER_METHODS, superBeanMethods.size());
+ }
+
+ public void testGetBean1AllMethods() throws Exception {
+ Set<Method> beanMethods = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(Bean1.class);
+ assertEquals(Bean1.ALL_BEAN1_METHODS, beanMethods.size());
+ }
+
+ public void testOverrideMethod() throws Exception {
+ Set<Method> beanFields = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(Bean1.class);
+ boolean invoked = false;
+ for (Method method : beanFields) {
+ if (method.getName().equals("override")) {
+ method.invoke(new Bean1(), "foo");
+ invoked = true;
+ }
+ }
+ if (!invoked) {
+ throw new Exception("Override never invoked");
+ }
+ }
+
+ public void testNoOverrideMethod() throws Exception {
+ Set<Method> beanFields = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(Bean1.class);
+ boolean found = false;
+ for (Method method : beanFields) {
+ if (method.getName().equals("noOverride") && method.getParameterTypes().length == 0) {
+ found = true;
+ }
+ }
+ if (!found) {
+ throw new Exception("No override not found");
+ }
+ }
+
+ public void testDefaultConstructor() throws Exception {
+ Constructor ctr = JavaIntrospectionHelper.getDefaultConstructor(Bean2.class);
+ assertEquals(ctr, Bean2.class.getConstructor());
+ assertTrue(Bean2.class == ctr.newInstance((Object[]) null).getClass());
+ }
+
+
+ public void testGetAllInterfaces() {
+ Set<Class> interfaces = JavaIntrospectionHelper.getAllInterfaces(Z.class);
+ assertEquals(2, interfaces.size());
+ assertTrue(interfaces.contains(W.class));
+ assertTrue(interfaces.contains(W2.class));
+ }
+
+
+ public void testGetAllInterfacesObject() {
+ Set<Class> interfaces = JavaIntrospectionHelper.getAllInterfaces(Object.class);
+ assertEquals(0, interfaces.size());
+ }
+
+ public void testGetAllInterfacesNoInterfaces() {
+ Set<Class> interfaces = JavaIntrospectionHelper.getAllInterfaces(NoInterface.class);
+ assertEquals(0, interfaces.size());
+ }
+
+ /**
+ * Tests generics introspection capabilities
+ */
+ public void testGenerics() throws Exception {
+
+ List classes = JavaIntrospectionHelper.getGenerics(getClass().getDeclaredField("testList").getGenericType());
+ assertEquals(1, classes.size());
+ assertEquals(String.class, classes.get(0));
+
+ classes =
+ JavaIntrospectionHelper.getGenerics(getClass().getDeclaredField("testNoGenericsList").getGenericType());
+ assertEquals(0, classes.size());
+
+ classes = JavaIntrospectionHelper.getGenerics(getClass().getDeclaredField("testMap").getGenericType());
+ assertEquals(2, classes.size());
+ assertEquals(String.class, classes.get(0));
+ assertEquals(Bean1.class, classes.get(1));
+
+ classes = JavaIntrospectionHelper
+ .getGenerics(getClass().getDeclaredMethod("fooMethod", Map.class).getGenericParameterTypes()[0]);
+ assertEquals(2, classes.size());
+ assertEquals(String.class, classes.get(0));
+ assertEquals(Bean1.class, classes.get(1));
+
+ classes = JavaIntrospectionHelper
+ .getGenerics(getClass().getDeclaredMethod("fooMethod", List.class).getGenericParameterTypes()[0]);
+ assertEquals(1, classes.size());
+ assertEquals(String.class, classes.get(0));
+
+ }
+
+ private void fooMethod(List<String> foo) {
+
+ }
+
+ private void fooMethod(Map<String, Bean1> foo) {
+
+ }
+
+ public void setTestArray(Target[] array) {
+ }
+
+ private interface W {
+
+ }
+
+ private interface W2 {
+
+ }
+
+ private class X implements W {
+
+ }
+
+ private class Y extends X implements W, W2 {
+
+ }
+
+ private class Z extends Y {
+
+ }
+
+ private class NoInterface {
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/util/SuperBean.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/util/SuperBean.java
new file mode 100644
index 0000000000..83aef7fb5e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/util/SuperBean.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.core.util;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SuperBean {
+
+ public static final int ALL_SUPER_FIELDS = 6;
+ public static final int ALL_SUPER_PUBLIC_PROTECTED_FIELDS = 5;
+ public static final int ALL_SUPER_METHODS = 4;
+ public String superField2;
+
+ protected String superField3;
+
+ private String superField1;
+
+ public void setSuperMethod1(String param) {
+ }
+
+ public void setSuperMethod1(int param) {
+ }
+
+ public void override(String param) throws Exception {
+ throw new Exception("Override not handled");
+ }
+
+ public void noOverride() throws Exception {
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/BasicReferenceInvocationHandlerTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/BasicReferenceInvocationHandlerTestCase.java
new file mode 100644
index 0000000000..6e7d891cd0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/BasicReferenceInvocationHandlerTestCase.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire;
+
+import java.lang.reflect.Method;
+import java.net.URI;
+
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.component.WorkContext;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.mock.component.SimpleTarget;
+import org.apache.tuscany.core.mock.component.SimpleTargetImpl;
+import org.apache.tuscany.core.mock.wire.MockStaticInvoker;
+import org.apache.tuscany.core.mock.wire.MockSyncInterceptor;
+import org.apache.tuscany.core.wire.jdk.JDKInvocationHandler;
+import org.apache.tuscany.core.implementation.PojoWorkContextTunnel;
+
+import org.easymock.EasyMock;
+
+/**
+ * @version $$Rev$$ $$Date$$
+ */
+public class BasicReferenceInvocationHandlerTestCase extends TestCase {
+
+ private Method echo;
+ private WorkContext workContext;
+
+ public void testInterceptorInvoke() throws Throwable {
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ ServiceContract<?> contract = registry.introspect(SimpleTarget.class);
+ Operation<?> operation = contract.getOperations().get("echo");
+ MockStaticInvoker invoker = new MockStaticInvoker(echo, new SimpleTargetImpl());
+ InvocationChain chain = new InvocationChainImpl(operation);
+ MockSyncInterceptor interceptor = new MockSyncInterceptor();
+ chain.addInterceptor(interceptor);
+ chain.addInterceptor(new InvokerInterceptor());
+ chain.setTargetInvoker(invoker);
+ //chains.put(echo, chain);
+ Wire wire = new WireImpl();
+ wire.addInvocationChain(operation, chain);
+ wire.setSourceContract(contract);
+ wire.setSourceUri(URI.create("#wire"));
+ JDKInvocationHandler handler = new JDKInvocationHandler(SimpleTarget.class, wire, workContext);
+ PojoWorkContextTunnel.setThreadWorkContext(workContext);
+ try {
+ assertEquals("foo", handler.invoke(null, echo, new String[]{"foo"}));
+ assertEquals(1, interceptor.getCount());
+ } finally {
+ PojoWorkContextTunnel.setThreadWorkContext(null);
+ }
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ echo = SimpleTarget.class.getMethod("echo", String.class);
+ workContext = EasyMock.createMock(WorkContext.class);
+ EasyMock.expect(workContext.getCorrelationId()).andStubReturn(null);
+ EasyMock.expect(workContext.getCallbackUris()).andStubReturn(null);
+ EasyMock.replay(workContext);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptorTestCase.java
new file mode 100644
index 0000000000..6c50cb406f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptorTestCase.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.core.wire;
+
+import org.osoa.sca.NoRegisteredCallbackException;
+
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CallbackInterfaceInterceptorTestCase extends TestCase {
+
+ public void testOptimize() throws Exception {
+ CallbackInterfaceInterceptor interceptor = new CallbackInterfaceInterceptor(true);
+ assertFalse(interceptor.isOptimizable());
+ }
+
+ 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 MessageImpl());
+ EasyMock.verify(next);
+ }
+
+ public void testDoesNotImplement() {
+ CallbackInterfaceInterceptor interceptor = new CallbackInterfaceInterceptor(false);
+ try {
+ interceptor.invoke(new MessageImpl());
+ fail();
+ } catch (NoRegisteredCallbackException e) {
+ // expected
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java
new file mode 100644
index 0000000000..c955faf7b1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java
@@ -0,0 +1,390 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.QualifiedName;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.ChainHolder;
+import org.apache.tuscany.spi.wire.IncompatibleServiceContractException;
+import org.apache.tuscany.spi.wire.ProxyCreationException;
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.ProxyService;
+import org.apache.tuscany.spi.wire.InvocationChain;
+
+import junit.framework.TestCase;
+import org.osoa.sca.CallableReference;
+
+/**
+ * TODO some tests commented out due to DataType.equals() needing to be strict
+ *
+ * @version $Rev$ $Date$
+ */
+public class ContractCompatibilityTestCase extends TestCase {
+
+ private ProxyService proxyService = new MockProxyService();
+
+ public void testNoOperation() throws Exception {
+ ServiceContract source = new MockContract<Type>("FooContract");
+ ServiceContract target = new MockContract<Type>("FooContract");
+ proxyService.checkCompatibility(source, target, false, false);
+ }
+
+ public void testBasic() throws Exception {
+ ServiceContract<Type> source = new MockContract<Type>("FooContract");
+ Operation<Type> opSource1 = new Operation<Type>("op1", null, null, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+ sourceOperations.put("op1", opSource1);
+ source.setOperations(sourceOperations);
+ ServiceContract<Type> target = new MockContract<Type>("FooContract");
+ Operation<Type> opSource2 = new Operation<Type>("op1", null, null, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+ targetOperations.put("op1", opSource2);
+ target.setOperations(targetOperations);
+ proxyService.checkCompatibility(source, target, false, false);
+ }
+
+ public void testBasicIncompatibleOperationNames() throws Exception {
+ ServiceContract<Type> source = new MockContract<Type>("FooContract");
+ Operation<Type> opSource1 = new Operation<Type>("op1", null, null, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+ sourceOperations.put("op1", opSource1);
+ source.setOperations(sourceOperations);
+ ServiceContract<Type> target = new MockContract<Type>("FooContract");
+ Operation<Type> opSource2 = new Operation<Type>("op2", null, null, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+ targetOperations.put("op2", opSource2);
+ target.setOperations(targetOperations);
+ try {
+ proxyService.checkCompatibility(source, target, false, false);
+ fail();
+ } catch (IncompatibleServiceContractException e) {
+ //expected
+ }
+ }
+
+ public void testInputTypes() throws Exception {
+ ServiceContract<Type> source = new MockContract<Type>("FooContract");
+ List<DataType<Type>> sourceInputTypes = new ArrayList<DataType<Type>>();
+ sourceInputTypes.add(new DataType<Type>(Object.class, Object.class));
+ DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(String.class, sourceInputTypes);
+ Operation<Type> opSource1 = new Operation<Type>("op1", inputType, null, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+ sourceOperations.put("op1", opSource1);
+ source.setOperations(sourceOperations);
+
+ ServiceContract<Type> target = new MockContract<Type>("FooContract");
+ List<DataType<Type>> targetInputTypes = new ArrayList<DataType<Type>>();
+ targetInputTypes.add(new DataType<Type>(Object.class, Object.class));
+ DataType<List<DataType<Type>>> targetInputType =
+ new DataType<List<DataType<Type>>>(String.class, targetInputTypes);
+
+ Operation<Type> opTarget =
+ new Operation<Type>("op1", targetInputType, null, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+ targetOperations.put("op1", opTarget);
+ target.setOperations(targetOperations);
+ proxyService.checkCompatibility(source, target, false, false);
+ }
+
+
+ public void testIncompatibleInputTypes() throws Exception {
+ ServiceContract<Type> source = new MockContract<Type>("FooContract");
+ List<DataType<Type>> sourceInputTypes = new ArrayList<DataType<Type>>();
+ sourceInputTypes.add(new DataType<Type>(Integer.class, Integer.class));
+ DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(String.class, sourceInputTypes);
+ Operation<Type> opSource1 = new Operation<Type>("op1", inputType, null, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+ sourceOperations.put("op1", opSource1);
+ source.setOperations(sourceOperations);
+
+ ServiceContract<Type> target = new MockContract<Type>("FooContract");
+ List<DataType<Type>> targetInputTypes = new ArrayList<DataType<Type>>();
+ targetInputTypes.add(new DataType<Type>(String.class, String.class));
+ DataType<List<DataType<Type>>> targetInputType =
+ new DataType<List<DataType<Type>>>(String.class, targetInputTypes);
+
+ Operation<Type> opTarget =
+ new Operation<Type>("op1", targetInputType, null, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+ targetOperations.put("op1", opTarget);
+ target.setOperations(targetOperations);
+ try {
+ proxyService.checkCompatibility(source, target, false, false);
+ fail();
+ } catch (IncompatibleServiceContractException e) {
+ //expected
+ }
+ }
+
+ /**
+ * Verfies source input types can be super types of the target
+ */
+ public void testSourceSuperTypeInputCompatibility() throws Exception {
+// ServiceContract<Type> source = new MockContract<Type>("FooContract");
+// List<DataType<Type>> sourceInputTypes = new ArrayList<DataType<Type>>();
+// sourceInputTypes.add(new DataType<Type>(Object.class, Object.class));
+// DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(String.class, sourceInputTypes);
+// Operation<Type> opSource1 = new Operation<Type>("op1", inputType, null, null, false, null);
+// Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+// sourceOperations.put("op1", opSource1);
+// source.setOperations(sourceOperations);
+//
+// ServiceContract<Type> target = new MockContract<Type>("FooContract");
+// List<DataType<Type>> targetInputTypes = new ArrayList<DataType<Type>>();
+// targetInputTypes.add(new DataType<Type>(String.class, String.class));
+// DataType<List<DataType<Type>>> targetInputType =
+// new DataType<List<DataType<Type>>>(String.class, targetInputTypes);
+//
+// Operation<Type> opTarget = new Operation<Type>("op1", targetInputType, null, null, false, null);
+// Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+// targetOperations.put("op1", opTarget);
+// target.setOperations(targetOperations);
+// wireService.checkCompatibility(source, target, false);
+ }
+
+ public void testOutputTypes() throws Exception {
+ ServiceContract<Type> source = new MockContract<Type>("FooContract");
+ DataType<Type> sourceOutputType = new DataType<Type>(String.class, String.class);
+ Operation<Type> opSource1 =
+ new Operation<Type>("op1", null, sourceOutputType, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+ sourceOperations.put("op1", opSource1);
+ source.setOperations(sourceOperations);
+
+ ServiceContract<Type> target = new MockContract<Type>("FooContract");
+ DataType<Type> targetOutputType = new DataType<Type>(String.class, String.class);
+ Operation<Type> opTarget =
+ new Operation<Type>("op1", null, targetOutputType, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+ targetOperations.put("op1", opTarget);
+ target.setOperations(targetOperations);
+ proxyService.checkCompatibility(source, target, false, false);
+ }
+
+ /**
+ * Verfies a return type that is a supertype of of the target is compatible
+ */
+ public void testSupertypeOutputTypes() throws Exception {
+// ServiceContract<Type> source = new MockContract<Type>("FooContract");
+// DataType<Type> sourceOutputType = new DataType<Type>(Object.class, Object.class);
+// Operation<Type> opSource1 = new Operation<Type>("op1", null, sourceOutputType, null, false, null);
+// Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+// sourceOperations.put("op1", opSource1);
+// source.setOperations(sourceOperations);
+//
+// ServiceContract<Type> target = new MockContract<Type>("FooContract");
+// DataType<Type> targetOutputType = new DataType<Type>(String.class, String.class);
+// Operation<Type> opTarget = new Operation<Type>("op1", null, targetOutputType, null, false, null);
+// Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+// targetOperations.put("op1", opTarget);
+// target.setOperations(targetOperations);
+// wireService.checkCompatibility(source, target, false);
+ }
+
+ public void testIncompatibleOutputTypes() throws Exception {
+ ServiceContract<Type> source = new MockContract<Type>("FooContract");
+ DataType<Type> sourceOutputType = new DataType<Type>(String.class, String.class);
+ Operation<Type> opSource1 =
+ new Operation<Type>("op1", null, sourceOutputType, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+ sourceOperations.put("op1", opSource1);
+ source.setOperations(sourceOperations);
+
+ ServiceContract<Type> target = new MockContract<Type>("FooContract");
+ DataType<Type> targetOutputType = new DataType<Type>(Integer.class, Integer.class);
+ Operation<Type> opTarget =
+ new Operation<Type>("op1", null, targetOutputType, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+ targetOperations.put("op1", opTarget);
+ target.setOperations(targetOperations);
+ try {
+ proxyService.checkCompatibility(source, target, false, false);
+ fail();
+ } catch (IncompatibleServiceContractException e) {
+ //expected
+ }
+ }
+
+ public void testFaultTypes() throws Exception {
+ ServiceContract<Type> source = new MockContract<Type>("FooContract");
+ DataType<Type> sourceFaultType = new DataType<Type>(String.class, String.class);
+ List<DataType<Type>> sourceFaultTypes = new ArrayList<DataType<Type>>();
+ sourceFaultTypes.add(0, sourceFaultType);
+ Operation<Type> opSource1 =
+ new Operation<Type>("op1", null, null, sourceFaultTypes, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+ sourceOperations.put("op1", opSource1);
+ source.setOperations(sourceOperations);
+
+ ServiceContract<Type> target = new MockContract<Type>("FooContract");
+ DataType<Type> targetFaultType = new DataType<Type>(String.class, String.class);
+ List<DataType<Type>> targetFaultTypes = new ArrayList<DataType<Type>>();
+ targetFaultTypes.add(0, targetFaultType);
+
+ Operation<Type> opTarget =
+ new Operation<Type>("op1", null, null, targetFaultTypes, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+ targetOperations.put("op1", opTarget);
+ target.setOperations(targetOperations);
+ proxyService.checkCompatibility(source, target, false, false);
+ }
+
+ public void testSourceFaultTargetNoFaultCompatibility() throws Exception {
+ ServiceContract<Type> source = new MockContract<Type>("FooContract");
+ DataType<Type> sourceFaultType = new DataType<Type>(String.class, String.class);
+ List<DataType<Type>> sourceFaultTypes = new ArrayList<DataType<Type>>();
+ sourceFaultTypes.add(0, sourceFaultType);
+ Operation<Type> opSource1 =
+ new Operation<Type>("op1", null, null, sourceFaultTypes, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+ sourceOperations.put("op1", opSource1);
+ source.setOperations(sourceOperations);
+
+ ServiceContract<Type> target = new MockContract<Type>("FooContract");
+ Operation<Type> opTarget = new Operation<Type>("op1", null, null, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+ targetOperations.put("op1", opTarget);
+ target.setOperations(targetOperations);
+ proxyService.checkCompatibility(source, target, false, false);
+ }
+
+ /**
+ * Verifies a source's fault which is a supertype of the target's fault are compatibile
+ *
+ * @throws Exception
+ */
+ public void testFaultSuperTypes() throws Exception {
+// ServiceContract<Type> source = new MockContract<Type>("FooContract");
+// DataType<Type> sourceFaultType = new DataType<Type>(Exception.class, Exception.class);
+// List<DataType<Type>> sourceFaultTypes = new ArrayList<DataType<Type>>();
+// sourceFaultTypes.add(0, sourceFaultType);
+// Operation<Type> opSource1 = new Operation<Type>("op1", null, null, sourceFaultTypes, false, null);
+// Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+// sourceOperations.put("op1", opSource1);
+// source.setOperations(sourceOperations);
+//
+// ServiceContract<Type> target = new MockContract<Type>("FooContract");
+// DataType<Type> targetFaultType = new DataType<Type>(TuscanyException.class, TuscanyException.class);
+// List<DataType<Type>> targetFaultTypes = new ArrayList<DataType<Type>>();
+// targetFaultTypes.add(0, targetFaultType);
+//
+// Operation<Type> opTarget = new Operation<Type>("op1", null, null, targetFaultTypes, false, null);
+// Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+// targetOperations.put("op1", opTarget);
+// target.setOperations(targetOperations);
+// wireService.checkCompatibility(source, target, false);
+ }
+
+ /**
+ * Verifies a source's faults which are supertypes and a superset of the target's faults are compatibile
+ */
+ public void testFaultSuperTypesAndSuperset() throws Exception {
+// ServiceContract<Type> source = new MockContract<Type>("FooContract");
+// DataType<Type> sourceFaultType = new DataType<Type>(Exception.class, Exception.class);
+// DataType<Type> sourceFaultType2 = new DataType<Type>(RuntimeException.class, RuntimeException.class);
+// List<DataType<Type>> sourceFaultTypes = new ArrayList<DataType<Type>>();
+// sourceFaultTypes.add(0, sourceFaultType);
+// sourceFaultTypes.add(1, sourceFaultType2);
+// Operation<Type> opSource1 = new Operation<Type>("op1", null, null, sourceFaultTypes, false, null);
+// Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>();
+// sourceOperations.put("op1", opSource1);
+// source.setOperations(sourceOperations);
+//
+// ServiceContract<Type> target = new MockContract<Type>("FooContract");
+// DataType<Type> targetFaultType = new DataType<Type>(TuscanyException.class, TuscanyException.class);
+// List<DataType<Type>> targetFaultTypes = new ArrayList<DataType<Type>>();
+// targetFaultTypes.add(0, targetFaultType);
+//
+// Operation<Type> opTarget = new Operation<Type>("op1", null, null, targetFaultTypes, false, null);
+// Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>();
+// targetOperations.put("op1", opTarget);
+// target.setOperations(targetOperations);
+// wireService.checkCompatibility(source, target, false);
+ }
+
+ private class MockContract<T> extends ServiceContract<T> {
+ public MockContract() {
+ }
+
+ public MockContract(Class interfaceClass) {
+ super(interfaceClass);
+ }
+
+ public MockContract(String interfaceName) {
+ super(interfaceName);
+ }
+ }
+
+ private class MockProxyService extends ProxyServiceExtension {
+ public MockProxyService() {
+ super(null);
+ }
+
+ public <T> T createProxy(Class<T> interfaze, Wire wire) throws ProxyCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public <T> T createProxy2(Class<T> interfaze, boolean conversational, Wire wire) throws ProxyCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public <T> T createProxy2(Class<T> interfaze, Wire wire) throws ProxyCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public <T> T createProxy(Class<T> interfaze, Wire wire, Map<Method, ChainHolder> mapping)
+ throws ProxyCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public <T> T createProxy2(Class<T> interfaze, Wire wire, Map<Method, InvocationChain> mapping)
+ throws ProxyCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object createCallbackProxy(Class<?> interfaze, List<Wire> wires) throws ProxyCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object createCallbackProxy(Class<?> interfaze) throws ProxyCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void createWires(ReferenceBinding referenceBinding, ServiceContract<?> contract,
+ QualifiedName targetName) {
+ throw new UnsupportedOperationException();
+ }
+
+ public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatterTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatterTestCase.java
new file mode 100644
index 0000000000..a9f455bc62
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatterTestCase.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.core.wire;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.IncompatibleServiceContractException;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.host.monitor.FormatterRegistry;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class IncompatibleServiceContractExceptionFormatterTestCase extends TestCase {
+ FormatterRegistry registry = EasyMock.createNiceMock(FormatterRegistry.class);
+ IncompatibleServiceContractExceptionFormatter formatter =
+ new IncompatibleServiceContractExceptionFormatter(registry);
+
+ public void testFormat() throws Exception {
+ ServiceContract<Object> source = new ServiceContract<Object>() {
+ };
+ source.setInterfaceName("sourceInterface");
+ ServiceContract<Object> target = new ServiceContract<Object>() {
+ };
+ target.setInterfaceName("targetInterface");
+ Operation<Object> sourceOp = new Operation<Object>("sourceOp", null, null, null);
+ Operation<Object> targetOp = new Operation<Object>("targetOp", null, null, null);
+
+ IncompatibleServiceContractException e =
+ new IncompatibleServiceContractException("message", source, target, sourceOp, targetOp);
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ formatter.write(pw, e);
+ String buffer = writer.toString();
+ assertTrue(buffer.indexOf("message") >= 0);
+ assertTrue(buffer.indexOf("sourceInterface") >= 0);
+ assertTrue(buffer.indexOf("targetInterface") >= 0);
+ assertTrue(buffer.indexOf("sourceOp") >= 0);
+ assertTrue(buffer.indexOf("targetOp") >= 0);
+ }
+
+
+ public void testFormatNulls() throws Exception {
+ ServiceContract<Object> source = new ServiceContract<Object>() {
+ };
+ source.setInterfaceName("sourceInterface");
+ ServiceContract<Object> target = new ServiceContract<Object>() {
+ };
+ target.setInterfaceName("targetInterface");
+
+ IncompatibleServiceContractException e =
+ new IncompatibleServiceContractException("message", source, target);
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ formatter.write(pw, e);
+ String buffer = writer.toString();
+ assertTrue(buffer.indexOf("message") >= 0);
+ assertTrue(buffer.indexOf("sourceInterface") >= 0);
+ assertTrue(buffer.indexOf("targetInterface") >= 0);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationChainImplTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationChainImplTestCase.java
new file mode 100644
index 0000000000..9875058abb
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationChainImplTestCase.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire;
+
+import java.lang.reflect.Type;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.InvocationChain;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InvocationChainImplTestCase extends TestCase {
+
+ public void testInsertAtPos() throws Exception {
+ InvocationChain chain = new InvocationChainImpl(new Operation<Type>("foo", null, null, null));
+ Interceptor inter3 = new MockInterceptor();
+ Interceptor inter2 = new MockInterceptor();
+ Interceptor inter1 = new MockInterceptor();
+ chain.addInterceptor(inter3);
+ chain.addInterceptor(0, inter1);
+ chain.addInterceptor(1, inter2);
+ Interceptor head = chain.getHeadInterceptor();
+ assertEquals(inter1, head);
+ assertEquals(inter2, head.getNext());
+ assertEquals(inter3, head.getNext().getNext());
+ }
+
+ public void testInsertAtEnd() throws Exception {
+ InvocationChain chain = new InvocationChainImpl(new Operation<Type>("foo", null, null, null));
+ Interceptor inter2 = new MockInterceptor();
+ Interceptor inter1 = new MockInterceptor();
+ chain.addInterceptor(0, inter1);
+ chain.addInterceptor(1, inter2);
+ Interceptor head = chain.getHeadInterceptor();
+ assertEquals(inter1, head);
+ assertEquals(inter2, head.getNext());
+ assertEquals(inter2, chain.getTailInterceptor());
+
+ }
+
+ private class MockInterceptor implements Interceptor {
+
+ private Interceptor next;
+
+ public Message invoke(Message msg) {
+ return null;
+ }
+
+ public void setNext(Interceptor next) {
+ this.next = next;
+ }
+
+ public Interceptor getNext() {
+ return next;
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationErrorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationErrorTestCase.java
new file mode 100644
index 0000000000..b8e0b0b8ea
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationErrorTestCase.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.core.wire;
+
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.mock.component.SimpleTarget;
+import org.apache.tuscany.core.mock.component.SimpleTargetImpl;
+import org.apache.tuscany.core.mock.wire.MockStaticInvoker;
+import org.apache.tuscany.core.mock.wire.MockSyncInterceptor;
+
+/**
+ * Tests error propagation through an innvocation
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvocationConfigurationErrorTestCase extends TestCase {
+
+ private ServiceContract<?> contract;
+ private Method hello;
+
+ public InvocationConfigurationErrorTestCase() {
+ super();
+ }
+
+ public InvocationConfigurationErrorTestCase(String arg0) {
+ super(arg0);
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ contract = registry.introspect(SimpleTarget.class);
+ hello = SimpleTarget.class.getMethod("hello", String.class);
+ }
+
+ /**
+ * Tests basic wiring of a source to a target, including handlers and interceptors
+ */
+ public void testInvokeWithInterceptors() throws Exception {
+ Operation operation = contract.getOperations().get("hello");
+ InvocationChain source = new InvocationChainImpl(operation);
+ MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor();
+ source.addInterceptor(sourceInterceptor);
+
+ InvocationChain target = new InvocationChainImpl(operation);
+ MockSyncInterceptor targetInterceptor = new MockSyncInterceptor();
+ target.addInterceptor(targetInterceptor);
+ target.addInterceptor(new InvokerInterceptor());
+
+ // connect the source to the target
+ source.addInterceptor(target.getHeadInterceptor());
+ MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl());
+ source.setTargetInvoker(invoker);
+
+ Message msg = new MessageImpl();
+ msg.setTargetInvoker(invoker);
+ Message response = source.getHeadInterceptor().invoke(msg);
+ assertTrue(response.isFault());
+ assertTrue(response.getBody() instanceof IllegalArgumentException);
+ assertEquals(1, sourceInterceptor.getCount());
+ assertEquals(1, targetInterceptor.getCount());
+
+ }
+
+}
+
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationTestCase.java
new file mode 100644
index 0000000000..000101771a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationTestCase.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.core.wire;
+
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.mock.component.SimpleTarget;
+import org.apache.tuscany.core.mock.component.SimpleTargetImpl;
+import org.apache.tuscany.core.mock.wire.MockStaticInvoker;
+import org.apache.tuscany.core.mock.wire.MockSyncInterceptor;
+
+public class InvocationConfigurationTestCase extends TestCase {
+
+ private Method hello;
+ private Operation operation;
+
+
+ public InvocationConfigurationTestCase() {
+ super();
+ }
+
+ public InvocationConfigurationTestCase(String arg0) {
+ super(arg0);
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ ServiceContract<?> contract;
+ try {
+ contract = registry.introspect(SimpleTarget.class);
+ } catch (InvalidServiceContractException e) {
+ throw new AssertionError();
+ }
+
+ operation = contract.getOperations().get("echo");
+ hello = SimpleTarget.class.getMethod("hello", String.class);
+ }
+
+ /**
+ * Tests basic wiring of a source to a target, including handlers and interceptors
+ */
+ public void testInvokeWithInterceptors() throws Exception {
+ InvocationChain source = new InvocationChainImpl(operation);
+ MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor();
+ source.addInterceptor(sourceInterceptor);
+
+ InvocationChain target = new InvocationChainImpl(operation);
+ MockSyncInterceptor targetInterceptor = new MockSyncInterceptor();
+ target.addInterceptor(targetInterceptor);
+ target.addInterceptor(new InvokerInterceptor());
+
+ // connect the source to the target
+ source.addInterceptor(target.getHeadInterceptor());
+ MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl());
+ source.setTargetInvoker(invoker);
+
+ Message msg = new MessageImpl();
+ msg.setBody("foo");
+ msg.setTargetInvoker(invoker);
+ Message response = source.getHeadInterceptor().invoke(msg);
+ assertEquals("foo", response.getBody());
+ assertEquals(1, sourceInterceptor.getCount());
+ assertEquals(1, targetInterceptor.getCount());
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationHandlerTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationHandlerTestCase.java
new file mode 100644
index 0000000000..930fcfcea7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationHandlerTestCase.java
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire;
+
+import java.lang.reflect.Method;
+import java.net.URI;
+
+import org.apache.tuscany.spi.idl.java.JavaIDLUtils;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.component.WorkContext;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.mock.component.SimpleTarget;
+import org.apache.tuscany.core.mock.component.SimpleTargetImpl;
+import org.apache.tuscany.core.mock.wire.MockStaticInvoker;
+import org.apache.tuscany.core.mock.wire.MockSyncInterceptor;
+import org.apache.tuscany.core.wire.jdk.JDKInvocationHandler;
+import org.apache.tuscany.core.implementation.PojoWorkContextTunnel;
+
+import org.easymock.EasyMock;
+
+public class InvocationHandlerTestCase extends TestCase {
+
+ private Method hello;
+ private ServiceContract<?> contract;
+ private WorkContext workContext;
+
+ public InvocationHandlerTestCase() {
+ super();
+ }
+
+ public InvocationHandlerTestCase(String arg0) {
+ super(arg0);
+ }
+
+ public void testBasicInvoke() throws Throwable {
+ Wire wire = new WireImpl();
+ wire.setSourceUri(URI.create("#wire"));
+ Operation operation = contract.getOperations().get("hello");
+ wire.addInvocationChain(operation, createChain(operation));
+ wire.setSourceContract(contract);
+ JDKInvocationHandler handler = new JDKInvocationHandler(SimpleTarget.class, wire, workContext);
+ assertEquals("foo", handler.invoke(hello, new Object[]{"foo"}));
+ }
+
+ public void testErrorInvoke() throws Throwable {
+ Wire wire = new WireImpl();
+ wire.setSourceUri(URI.create("#wire"));
+ Operation operation = contract.getOperations().get("hello");
+ wire.addInvocationChain(operation, createChain(operation));
+ wire.setSourceContract(contract);
+ JDKInvocationHandler handler = new JDKInvocationHandler(SimpleTarget.class, wire, workContext);
+ try {
+ handler.invoke(hello, new Object[]{});
+ fail("Expected " + IllegalArgumentException.class.getName());
+ } catch (IllegalArgumentException e) {
+ // should throw
+ }
+ }
+
+ public void testDirectErrorInvoke() throws Throwable {
+ Operation operation = contract.getOperations().get("hello");
+ InvocationChain source = new InvocationChainImpl(operation);
+ MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl());
+ source.setTargetInvoker(invoker);
+
+ Wire wire = new WireImpl();
+ wire.setSourceUri(URI.create("#wire"));
+ wire.setSourceContract(contract);
+ wire.addInvocationChain(operation, source);
+ JDKInvocationHandler handler = new JDKInvocationHandler(SimpleTarget.class, wire, workContext);
+ try {
+ assertEquals("foo", handler.invoke(hello, new Object[]{}));
+ fail("Expected " + IllegalArgumentException.class.getName());
+ } catch (IllegalArgumentException e) {
+ // should throw
+ }
+ }
+
+ public void testDirectInvoke() throws Throwable {
+ Operation operation = contract.getOperations().get("hello");
+ InvocationChain source = new InvocationChainImpl(operation);
+ MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl());
+ source.setTargetInvoker(invoker);
+
+ Wire wire = new WireImpl();
+ wire.setSourceUri(URI.create("#wire"));
+ wire.setSourceContract(contract);
+ wire.addInvocationChain(operation, source);
+ JDKInvocationHandler handler = new JDKInvocationHandler(SimpleTarget.class, wire, workContext);
+ assertEquals("foo", handler.invoke(hello, new Object[]{"foo"}));
+ }
+
+ private InvocationChain createChain(Operation operation) {
+ InvocationChain chain = new InvocationChainImpl(operation);
+ MockSyncInterceptor targetInterceptor = new MockSyncInterceptor();
+ chain.addInterceptor(targetInterceptor);
+ chain.addInterceptor(new InvokerInterceptor());
+
+ MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl());
+ chain.setTargetInvoker(invoker);
+ return chain;
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ contract = registry.introspect(SimpleTarget.class);
+ hello = SimpleTarget.class.getMethod("hello", String.class);
+ workContext = EasyMock.createMock(WorkContext.class);
+ EasyMock.expect(workContext.getCorrelationId()).andStubReturn(null);
+ EasyMock.expect(workContext.getCallbackUris()).andStubReturn(null);
+ EasyMock.replay(workContext);
+ PojoWorkContextTunnel.setThreadWorkContext(workContext);
+ }
+
+ protected void tearDown() throws Exception {
+ PojoWorkContextTunnel.setThreadWorkContext(null);
+ super.tearDown();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/NonBlockingInterceptorBuilderTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/NonBlockingInterceptorBuilderTestCase.java
new file mode 100644
index 0000000000..c563217306
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/NonBlockingInterceptorBuilderTestCase.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.core.wire;
+
+import static org.apache.tuscany.core.wire.NonBlockingInterceptorBuilder.QNAME;
+
+import org.apache.tuscany.spi.model.physical.PhysicalInterceptorDefinition;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class NonBlockingInterceptorBuilderTestCase extends TestCase {
+
+ public void testBuild() throws Exception {
+ NonBlockingInterceptorBuilder builder = new NonBlockingInterceptorBuilder(null, null);
+ PhysicalInterceptorDefinition definition = new PhysicalInterceptorDefinition(QNAME);
+ definition.setBuilder(QNAME);
+ assertTrue(builder.build(definition) instanceof NonBlockingInterceptor);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/NonBlockingInterceptorTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/NonBlockingInterceptorTestCase.java
new file mode 100644
index 0000000000..c08d1453db
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/NonBlockingInterceptorTestCase.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.core.wire;
+
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.services.work.WorkScheduler;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+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 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<Object>() {
+ public Object answer() throws Throwable {
+ Runnable runnable = (Runnable) getCurrentArguments()[0];
+ runnable.run();
+ return null;
+ }
+ });
+ replay(scheduler);
+ WorkContext context = createMock(WorkContext.class);
+ String convID = "convID";
+ EasyMock.expect(context.getIdentifier(Scope.CONVERSATION)).andReturn(convID);
+ context.setCorrelationId(null);
+ context.setIdentifier(Scope.CONVERSATION, convID);
+ EasyMock.replay(context);
+ Message msg = new MessageImpl();
+ Interceptor next = EasyMock.createMock(Interceptor.class);
+ EasyMock.expect(next.invoke(EasyMock.eq(msg))).andReturn(msg);
+ EasyMock.replay(next);
+ Interceptor interceptor = new NonBlockingInterceptor(scheduler, context, next);
+ interceptor.invoke(msg);
+ verify(context);
+ verify(next);
+ }
+
+ public void testOptimizable() {
+ NonBlockingInterceptor interceptor = new NonBlockingInterceptor(null, null);
+ assertFalse(interceptor.isOptimizable());
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactoryTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactoryTestCase.java
new file mode 100644
index 0000000000..5293678d12
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactoryTestCase.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.core.wire;
+
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class OptimizedWireObjectFactoryTestCase extends TestCase {
+
+ public void testGetInstance() throws Exception {
+ Foo foo = new Foo();
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.getTargetInstance()).andReturn(foo);
+ EasyMock.replay(wire);
+ OptimizedWireObjectFactory<Foo> factory = new OptimizedWireObjectFactory<Foo>(Foo.class, wire);
+ assertEquals(foo, factory.getInstance());
+ EasyMock.verify(wire);
+ }
+
+ private class Foo {
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireImplTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireImplTestCase.java
new file mode 100644
index 0000000000..e337133523
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireImplTestCase.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.core.wire;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WireImplTestCase extends TestCase {
+
+ /**
+ * Tests that the target wire returns null if there is no connected wire. This behavior is needed for optional
+ * autowires.
+ */
+ public void testGetNonExistentTarget() throws Exception {
+ Wire wire = new WireImpl();
+ assertNull(wire.getTargetInstance());
+ }
+
+ public void testTargetInstance() throws Exception {
+ Wire wire = new WireImpl();
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.getTargetInstance()).andReturn(new Object());
+ EasyMock.replay(component);
+ wire.setTarget(component);
+ assertNotNull(wire.getTargetInstance());
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireObjectFactoryTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireObjectFactoryTestCase.java
new file mode 100644
index 0000000000..9f21b9efdb
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireObjectFactoryTestCase.java
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.wire;
+
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.ProxyService;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WireObjectFactoryTestCase extends TestCase {
+
+ @SuppressWarnings({"unchecked"})
+ public void testCreateInstance() throws Exception {
+ Operation<Type> op = new Operation<Type>("hello", null, null, null);
+ InvocationChain chain = new InvocationChainImpl(op);
+ Wire wire = EasyMock.createMock(Wire.class);
+ Map<Operation<?>, InvocationChain> chains = new HashMap<Operation<?>, InvocationChain>();
+ chains.put(op, chain);
+ EasyMock.expect(wire.getInvocationChains()).andReturn(chains);
+ EasyMock.expect(wire.isOptimizable()).andReturn(false);
+ EasyMock.replay(wire);
+ ProxyService service = EasyMock.createMock(ProxyService.class);
+ service.createProxy(EasyMock.eq(Foo.class), EasyMock.eq(wire), EasyMock.isA(Map.class));
+ EasyMock.expectLastCall().andReturn(new Foo() {
+ public void hello() {
+
+ }
+ });
+ EasyMock.replay(service);
+
+ WireObjectFactory<Foo> factory = new WireObjectFactory<Foo>(Foo.class, wire, service);
+ factory.getInstance();
+ EasyMock.verify(service);
+ EasyMock.verify(wire);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testOptimizedCreateInstance() throws Exception {
+ ServiceContract<?> contract = new JavaServiceContract(Foo.class);
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.isOptimizable()).andReturn(true);
+ EasyMock.expect(wire.getSourceContract()).andReturn(contract).atLeastOnce();
+ EasyMock.expect(wire.getInvocationChains()).andReturn((Map) Collections.emptyMap());
+ EasyMock.expect(wire.getTargetInstance()).andReturn(new Foo() {
+ public void hello() {
+ }
+ });
+ EasyMock.replay(wire);
+ WireObjectFactory<Foo> factory = new WireObjectFactory<Foo>(Foo.class, wire, null);
+ factory.getInstance();
+ EasyMock.verify(wire);
+
+ }
+
+ /**
+ * Verifies that a proxy is created when the required client contract is different than the wire contract
+ */
+ @SuppressWarnings("unchecked")
+ public void testCannotOptimizeDifferentContractsCreateInstance() throws Exception {
+ ServiceContract<?> contract = new JavaServiceContract(Object.class);
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.isOptimizable()).andReturn(true);
+ EasyMock.expect(wire.getSourceContract()).andReturn(contract).atLeastOnce();
+ EasyMock.expect(wire.getInvocationChains()).andReturn((Map) Collections.emptyMap());
+ EasyMock.replay(wire);
+ ProxyService service = EasyMock.createMock(ProxyService.class);
+ service.createProxy(EasyMock.eq(Foo.class), EasyMock.eq(wire), EasyMock.isA(Map.class));
+ EasyMock.expectLastCall().andReturn(new Foo() {
+ public void hello() {
+
+ }
+ });
+ EasyMock.replay(service);
+
+ WireObjectFactory<Foo> factory = new WireObjectFactory<Foo>(Foo.class, wire, service);
+ factory.getInstance();
+ EasyMock.verify(service);
+ EasyMock.verify(wire);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testNoJavaInterfaceCreateInstance() throws Exception {
+ ServiceContract<?> contract = new JavaServiceContract();
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.expect(wire.isOptimizable()).andReturn(true);
+ EasyMock.expect(wire.getSourceContract()).andReturn(contract).atLeastOnce();
+ EasyMock.expect(wire.getInvocationChains()).andReturn((Map) Collections.emptyMap());
+ EasyMock.replay(wire);
+ ProxyService service = EasyMock.createMock(ProxyService.class);
+ service.createProxy(EasyMock.eq(Foo.class), EasyMock.eq(wire), EasyMock.isA(Map.class));
+ EasyMock.expectLastCall().andReturn(new Foo() {
+ public void hello() {
+
+ }
+ });
+ EasyMock.replay(service);
+
+ WireObjectFactory<Foo> factory = new WireObjectFactory<Foo>(Foo.class, wire, service);
+ factory.getInstance();
+ EasyMock.verify(service);
+ EasyMock.verify(wire);
+ }
+
+ private interface Foo {
+ void hello();
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireOptimizationTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireOptimizationTestCase.java
new file mode 100644
index 0000000000..1db3892471
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireOptimizationTestCase.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.core.wire;
+
+import java.lang.reflect.Type;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.model.Operation;
+import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * Verifies wire optimization analysis
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class WireOptimizationTestCase extends TestCase {
+ private Operation operation;
+
+ public void foo() {
+ }
+
+ public void testWireInterceptorOptimization() throws Exception {
+ AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class);
+ EasyMock.replay(component);
+ Wire wire = new WireImpl();
+ InvocationChain chain = new InvocationChainImpl(operation);
+ chain.addInterceptor(new OptimizableInterceptor());
+ wire.addInvocationChain(operation, chain);
+ assertTrue(WireUtils.isOptimizable(wire));
+ }
+
+ public void testWireNonInterceptorOptimization() throws Exception {
+ AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class);
+ EasyMock.replay(component);
+ Wire wire = new WireImpl();
+ InvocationChain chain = new InvocationChainImpl(operation);
+ chain.addInterceptor(new NonOptimizableInterceptor());
+ wire.addInvocationChain(operation, chain);
+ assertFalse(WireUtils.isOptimizable(wire));
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ operation = new Operation<Type>("foo", null, null, null, false, null, NO_CONVERSATION);
+
+ }
+
+ private class OptimizableInterceptor implements Interceptor {
+
+ public Message invoke(Message msg) {
+ return null;
+ }
+
+ public void setNext(Interceptor next) {
+
+ }
+
+ public Interceptor getNext() {
+ return null;
+ }
+
+ public boolean isOptimizable() {
+ return true;
+ }
+ }
+
+ private class NonOptimizableInterceptor implements Interceptor {
+
+ public Message invoke(Message msg) {
+ return null;
+ }
+
+ public void setNext(Interceptor next) {
+
+ }
+
+ public Interceptor getNext() {
+ return null;
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java
new file mode 100644
index 0000000000..a9da65e0ba
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.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.core.wire;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.Map;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.ChainHolder;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WireUtilsTestCase extends TestCase {
+ private Method m;
+
+ public void testCreateInterfaceToWireMapping() throws Exception {
+ Wire wire = new WireImpl();
+ Operation<Type> op = new Operation<Type>("hello", null, null, null);
+ InvocationChain chain = new InvocationChainImpl(op);
+ wire.addInvocationChain(op, chain);
+ Map<Method, ChainHolder> chains = WireUtils.createInterfaceToWireMapping(Foo.class, wire);
+ assertEquals(1, chains.size());
+ assertNotNull(chains.get(m));
+ }
+
+ public void testCreateInterfaceToWireMappingNoOperation() throws Exception {
+ Wire wire = new WireImpl();
+ Operation<Type> op = new Operation<Type>("goodbye", null, null, null);
+ InvocationChain chain = new InvocationChainImpl(op);
+ wire.addInvocationChain(op, chain);
+ try {
+ WireUtils.createInterfaceToWireMapping(Foo.class, wire);
+ fail();
+ } catch (NoMethodForOperationException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ m = Foo.class.getMethod("hello");
+ }
+
+ private interface Foo {
+ void hello();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerSerializationTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerSerializationTestCase.java
new file mode 100644
index 0000000000..ff4f882b42
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerSerializationTestCase.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.core.wire.jdk;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.SCAExternalizable;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.wire.WireImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JDKCallbackInvocationHandlerSerializationTestCase extends TestCase {
+ private WorkContext workContext;
+ private List<Wire> wires;
+ private AtomicComponent component;
+
+ public void testSerializeDeserialize() throws Exception {
+ JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(wires, workContext);
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ ObjectOutputStream ostream = new ObjectOutputStream(stream);
+ ostream.writeObject(handler);
+
+ ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(stream.toByteArray()));
+ SCAExternalizable externalizable = (SCAExternalizable) istream.readObject();
+
+ externalizable.setWorkContext(workContext);
+ externalizable.reactivate();
+ EasyMock.verify(component);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ URI uri = URI.create("#foo");
+ Wire wire = new WireImpl();
+ wire.setSourceUri(uri);
+ wires = new ArrayList<Wire>();
+ wires.add(wire);
+ List<Wire> wireList = new ArrayList<Wire>();
+ wireList.add(wire);
+ component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.getWires("foo")).andReturn(wireList);
+ EasyMock.replay(component);
+ workContext = new WorkContextImpl();
+ workContext.setCurrentAtomicComponent(component);
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ workContext.setCurrentAtomicComponent(null);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerTestCase.java
new file mode 100644
index 0000000000..90e5c4f818
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerTestCase.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.core.wire.jdk;
+
+import java.lang.reflect.Proxy;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.wire.WireImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JDKCallbackInvocationHandlerTestCase extends TestCase {
+
+ public void testToString() {
+ Wire wire = new WireImpl();
+ URI uri = URI.create("#wire");
+ wire.setSourceUri(uri);
+ List<Wire> wires = new ArrayList<Wire>();
+ wires.add(wire);
+ wire.setSourceContract(new JavaServiceContract(Foo.class));
+ JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(wires, new WorkContextImpl());
+ Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler);
+ assertNotNull(foo.toString());
+ }
+
+ public void testHashCode() {
+ Wire wire = new WireImpl();
+ wire.setSourceContract(new JavaServiceContract(Foo.class));
+ URI uri = URI.create("#wire");
+ wire.setSourceUri(uri);
+ List<Wire> wires = new ArrayList<Wire>();
+ wires.add(wire);
+ JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(wires, new WorkContextImpl());
+ Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler);
+ assertNotNull(foo.hashCode());
+ }
+
+ private interface Foo {
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerProxyTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerProxyTestCase.java
new file mode 100644
index 0000000000..78eae4621f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerProxyTestCase.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.core.wire.jdk;
+
+import java.lang.reflect.Method;
+import java.net.URI;
+
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
+import org.apache.tuscany.core.wire.InvocationChainImpl;
+import org.apache.tuscany.core.wire.WireImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JDKInvocationHandlerProxyTestCase extends TestCase {
+ private JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl();
+ private Method clientHello;
+
+ /**
+ * Verifies a handler configured to use a different interface than the wire target can dispatch
+ */
+ public void testDifferentInterface() throws Throwable {
+ Wire wire = new WireImpl();
+ JavaServiceContract<Target> contract = registry.introspect(Target.class);
+ for (Operation<?> operation : contract.getOperations().values()) {
+ InvocationChain chain = new InvocationChainImpl(operation);
+ wire.addInvocationChain(operation, chain);
+ }
+ wire.setSourceContract(contract);
+ wire.setSourceUri(URI.create("foo#bar"));
+ TargetInvoker targetInvoker = EasyMock.createMock(TargetInvoker.class);
+ MessageImpl response = new MessageImpl();
+ EasyMock.expect(targetInvoker.invokeTarget(null, TargetInvoker.NONE, null)).andReturn(response);
+ EasyMock.expect(targetInvoker.isCacheable()).andReturn(false);
+ EasyMock.replay(targetInvoker);
+ wire.getInvocationChains().values().iterator().next().setTargetInvoker(targetInvoker);
+
+ JDKInvocationHandler handler = new JDKInvocationHandler(Client.class, wire, null);
+ assertSame(response, handler.invoke(null, clientHello, null));
+ EasyMock.verify(targetInvoker);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ clientHello = Client.class.getMethod("hello");
+ }
+
+ private interface Target {
+ String hello();
+ }
+
+ private interface Client {
+ String hello();
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerSerializationTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerSerializationTestCase.java
new file mode 100644
index 0000000000..0881439cc8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerSerializationTestCase.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.core.wire.jdk;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Operation;
+import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.component.WorkContextImpl;
+import org.apache.tuscany.core.wire.InvocationChainImpl;
+import org.apache.tuscany.core.wire.InvokerInterceptor;
+import org.apache.tuscany.core.implementation.PojoWorkContextTunnel;
+
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JDKInvocationHandlerSerializationTestCase extends TestCase {
+ private Wire wire;
+ private WorkContext workContext;
+ private TargetInvoker invoker;
+
+ public void testSerializeDeserialize() throws Throwable {
+ JDKInvocationHandler handler =
+ new JDKInvocationHandler(Foo.class, wire, workContext);
+ PojoWorkContextTunnel.setThreadWorkContext(workContext);
+ try {
+ handler.invoke(null, Foo.class.getMethod("invoke"), null);
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ ObjectOutputStream ostream = new ObjectOutputStream(stream);
+ ostream.writeObject(handler);
+
+ ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(stream.toByteArray()));
+ JDKInvocationHandler externalizable = (JDKInvocationHandler) istream.readObject();
+
+ externalizable.setWorkContext(workContext);
+ externalizable.reactivate();
+ externalizable.invoke(Foo.class.getMethod("invoke"), null);
+ EasyMock.verify(invoker);
+ EasyMock.verify(wire);
+ } finally {
+ PojoWorkContextTunnel.setThreadWorkContext(null);
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ SCAObject container = EasyMock.createMock(SCAObject.class);
+ ServiceContract<Foo> contract = new ServiceContract<Foo>() {
+ };
+ contract.setInterfaceClass(Foo.class);
+ contract.setConversational(false);
+ EasyMock.expect(container.getUri()).andReturn(URI.create("bar")).atLeastOnce();
+
+ wire = EasyMock.createMock(Wire.class);
+ Map<Operation<?>, InvocationChain> map = new HashMap<Operation<?>, InvocationChain>();
+ Operation<Object> operation = new Operation<Object>("invoke", null, null, null, false, null, NO_CONVERSATION);
+ ServiceContract<Object> opContract = new ServiceContract<Object>() {
+ };
+ contract.setInterfaceClass(Foo.class);
+ contract.setConversational(false);
+ operation.setServiceContract(opContract);
+ map.put(operation, createChain(operation));
+ EasyMock.expect(wire.getSourceContract()).andReturn(contract).atLeastOnce();
+ URI uri = URI.create("#foo");
+ EasyMock.expect(wire.getSourceUri()).andReturn(uri).atLeastOnce();
+ EasyMock.expect(wire.getInvocationChains()).andReturn(map).times(2);
+ EasyMock.replay(wire);
+ List<Wire> list = new ArrayList<Wire>();
+ list.add(wire);
+ AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
+ EasyMock.expect(component.getWires("foo")).andReturn(list);
+ EasyMock.replay(component);
+ workContext = new WorkContextImpl();
+ workContext.setCurrentAtomicComponent(component);
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ workContext.setCurrentAtomicComponent(null);
+ }
+
+ private InvocationChain createChain(Operation operation) {
+ invoker = EasyMock.createMock(TargetInvoker.class);
+ EasyMock.expect(invoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl()).times(2);
+ EasyMock.expect(invoker.isCacheable()).andReturn(false).atLeastOnce();
+ EasyMock.replay(invoker);
+ InvocationChain chain = new InvocationChainImpl(operation);
+ chain.setTargetInvoker(invoker);
+ chain.addInterceptor(new InvokerInterceptor());
+ return chain;
+ }
+
+ public class Foo {
+
+ public void invoke() {
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.java
new file mode 100644
index 0000000000..b57e89d138
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.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.core.wire.jdk;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Proxy;
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.component.SimpleWorkContext;
+import org.apache.tuscany.core.wire.InvocationChainImpl;
+import org.apache.tuscany.core.wire.WireImpl;
+import org.apache.tuscany.core.implementation.PojoWorkContextTunnel;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JDKInvocationHandlerTestCase extends TestCase {
+
+ public void testToString() {
+ Wire wire = new WireImpl();
+ ServiceContract contract = new JavaServiceContract(Foo.class);
+ contract.setConversational(false);
+ wire.setSourceContract(contract);
+ wire.setSourceUri(URI.create("foo#bar"));
+ JDKInvocationHandler handler = new JDKInvocationHandler(Foo.class, wire, null);
+ Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler);
+ assertNotNull(foo.toString());
+ }
+
+ public void testHashCode() {
+ Wire wire = new WireImpl();
+ ServiceContract contract = new JavaServiceContract(Foo.class);
+ contract.setConversational(false);
+ wire.setSourceContract(contract);
+ wire.setSourceUri(URI.create("foo#bar"));
+ JDKInvocationHandler handler = new JDKInvocationHandler(Foo.class, wire, null);
+ Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler);
+ assertNotNull(foo.hashCode());
+ }
+
+ public void testConversational() throws Throwable {
+ Wire wire = new WireImpl();
+ DataType<Type> type1 = new DataType<Type>(String.class, String.class);
+ List<DataType<Type>> types = new ArrayList<DataType<Type>>();
+ types.add(type1);
+ DataType<List<DataType<Type>>> inputType1 = new DataType<List<DataType<Type>>>(Object[].class, types);
+ DataType<Type> outputType1 = new DataType<Type>(String.class, String.class);
+ Operation<Type> op1 = new Operation<Type>("test", inputType1, outputType1, null);
+ ServiceContract<Type> contract = new JavaServiceContract(Foo.class);
+ contract.setConversational(true);
+ op1.setServiceContract(contract);
+
+ WorkContext wc = new SimpleWorkContext();
+ PojoWorkContextTunnel.setThreadWorkContext(wc);
+ try {
+ MockInvoker invoker = new MockInvoker();
+
+ InvocationChain chain = new InvocationChainImpl(op1);
+ chain.setTargetInvoker(invoker);
+ wire.addInvocationChain(op1, chain);
+ URI uri = URI.create("fooRef");
+ wire.setSourceUri(uri);
+ wire.setSourceContract(contract);
+
+ String convID = UUID.randomUUID().toString();
+ wc.setIdentifier(Scope.CONVERSATION, convID);
+ invoker.setCurrentConversationID(convID);
+
+ JDKInvocationHandler handler = new JDKInvocationHandler(Foo.class, wire, wc);
+ handler.invoke(null, Foo.class.getMethod("test", String.class), new Object[]{"bar"});
+ String currentConvID = (String) wc.getIdentifier(Scope.CONVERSATION);
+ assertSame(convID, currentConvID);
+
+ JDKInvocationHandler handler2 = new JDKInvocationHandler(Foo.class, wire, wc);
+ handler2.invoke(null, Foo.class.getMethod("test", String.class), new Object[]{"bar"});
+ currentConvID = (String) wc.getIdentifier(Scope.CONVERSATION);
+ assertSame(convID, currentConvID);
+ } finally {
+ PojoWorkContextTunnel.setThreadWorkContext(null);
+ }
+ }
+
+ private interface Foo {
+ String test(String s);
+ }
+
+ private class MockInvoker implements TargetInvoker {
+
+ private String currentConversationID;
+
+ public void setCurrentConversationID(String id) {
+ currentConversationID = id;
+ }
+
+ public Object invokeTarget(final Object payload, final short sequence, WorkContext workContext) throws InvocationTargetException {
+ assertEquals("bar", Array.get(payload, 0));
+ String convID = (String) workContext.getIdentifier(Scope.CONVERSATION);
+ assertSame(convID, currentConversationID);
+ return "response";
+ }
+
+ public Message invoke(Message msg) throws InvocationRuntimeException {
+ fail();
+ return null;
+ }
+
+ public boolean isCacheable() {
+ return false;
+ }
+
+ public void setCacheable(boolean cacheable) {
+
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCase.java b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCase.java
new file mode 100644
index 0000000000..d140c699c6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCase.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.core.wire.jdk;
+
+import java.lang.reflect.Proxy;
+import java.net.URI;
+
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.wire.WireImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JDKProxyTestCase extends TestCase {
+ private JDKProxyService proxyService;
+
+ public void testCreateProxy() {
+ URI uri = URI.create("#service");
+ Wire wire = new WireImpl();
+ wire.setSourceUri(uri);
+ ServiceContract contract = new ServiceContract() {
+ };
+ wire.setSourceContract(contract);
+ TestInterface proxy = proxyService.createProxy(TestInterface.class, wire);
+ assertTrue(Proxy.isProxyClass(proxy.getClass()));
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ proxyService = new JDKProxyService();
+ }
+
+ public static interface TestInterface {
+ int primitives(int i);
+
+ String objects(String object);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/core/src/test/resources/deployables/sample-calculator.jar b/tags/java/tsss-demo/kernel/core/src/test/resources/deployables/sample-calculator.jar
new file mode 100644
index 0000000000..0ca3a1b781
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/resources/deployables/sample-calculator.jar
Binary files differ
diff --git a/tags/java/tsss-demo/kernel/core/src/test/resources/marshall/javaChangeSet.xml b/tags/java/tsss-demo/kernel/core/src/test/resources/marshall/javaChangeSet.xml
new file mode 100644
index 0000000000..2ac4c6932e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/resources/marshall/javaChangeSet.xml
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<core:changeSet xmlns:core="http://tuscany.apache.org/xmlns/marshaller/1.0-SNAPSHOT">
+
+ <!-- Component 1 -->
+ <java:component initLevel="0" groupId="xyz" xmlns:java="http://tuscany.apache.org/xmlns/marshaller/java/1.0-SNAPSHOT" componentId="cmp1" scope="STATELESS">
+ <java:classLoaderId>#123</java:classLoaderId>
+ <bc:instanceFactoryProvider xmlns:bc="http://tuscany.apache.org/xmlns/marshaller/byteCode/1.0-SNAPSHOT">
+ <bc:byteCode>AB12345</bc:byteCode>
+ </bc:instanceFactoryProvider>
+ </java:component>
+
+ <!-- Component 2 -->
+ <java:component initLevel="0" groupId="xyz" xmlns:java="http://tuscany.apache.org/xmlns/marshaller/java/1.0-SNAPSHOT" componentId="cmp2" scope="STATELESS">
+ <java:classLoaderId>#123</java:classLoaderId>
+ <reflect:instanceFactoryProvider xmlns:reflect="http://tuscany.apache.org/xmlns/marshaller/reflect/1.0-SNAPSHOT">
+ <reflect:implementationClass>com.acme.Foo</reflect:implementationClass>
+ <reflect:initMethod>init</reflect:initMethod>
+ <reflect:destroyMethod>destroy</reflect:destroyMethod>
+ <reflect:constructorArgument>java.lang.String</reflect:constructorArgument>
+ <reflect:constructorArgument>java.lang.Long</reflect:constructorArgument>
+ <reflect:cdiSource type="REFERENCE" name="abc"/>
+ <reflect:injectionSite elementType="FIELD" type="PROPERTY" name="xyz" physicalName="xyz"/>
+ <reflect:injectionSite elementType="METHOD" type="CALLBACK" name="abc" physicalName="abc"/>
+ <reflect:property name="abc" value="123"/>
+ </reflect:instanceFactoryProvider>
+ </java:component>
+
+ <!-- Wire 1 -->
+ <core:wire>
+ <java:wireSource uri="cmp1#rf1" callbackUri="a#b" optimizable="true" conversational="false"
+ xmlns:java="http://tuscany.apache.org/xmlns/marshaller/java/1.0-SNAPSHOT" />
+ <java:wireTarget uri="cmp2#sv2" callbackUri="a#b" optimizable="true"
+ xmlns:java="http://tuscany.apache.org/xmlns/marshaller/java/1.0-SNAPSHOT" />
+ <core:operation name="op2" conversationSequence="1">
+ <core:parameter>java.lang.String</core:parameter>
+ <core:parameter>java.lang.Long</core:parameter>
+ <core:returnType>java.lang.Object</core:returnType>
+ </core:operation>
+ </core:wire>
+
+ <!-- Wire 2 -->
+ <core:wire>
+ <java:wireSource uri="cmp2#rf2" callbackUri="a#b" optimizable="true" conversational="true"
+ xmlns:java="http://tuscany.apache.org/xmlns/marshaller/java/1.0-SNAPSHOT" />
+ <java:wireTarget uri="cmp1#sv1" callbackUri="a#b" optimizable="true"
+ xmlns:java="http://tuscany.apache.org/xmlns/marshaller/java/1.0-SNAPSHOT" />
+ <core:operation name="op1" conversationSequence="2">
+ <core:parameter>java.lang.String</core:parameter>
+ <core:parameter>java.lang.Long</core:parameter>
+ <core:returnType>java.lang.Object</core:returnType>
+ </core:operation>
+ </core:wire>
+
+</core:changeSet> \ No newline at end of file
diff --git a/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/databinding/impl/ipo.xsd b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/databinding/impl/ipo.xsd
new file mode 100644
index 0000000000..92a576fb98
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/databinding/impl/ipo.xsd
@@ -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.
+-->
+<schema targetNamespace="http://www.example.com/IPO"
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:ipo="http://www.example.com/IPO">
+
+ <annotation>
+ <documentation xml:lang="en">
+ International Purchase order schema for Example.com
+ Copyright 2000 Example.com. All rights reserved.
+ </documentation>
+ </annotation>
+
+
+ <element name="purchaseOrder" type="ipo:PurchaseOrderType" />
+
+ <element name="comment" type="string" />
+
+ <complexType name="PurchaseOrderType">
+ <sequence>
+ <element name="shipTo" type="ipo:Address" />
+ <element name="billTo" type="ipo:Address" />
+ <element ref="ipo:comment" minOccurs="0" />
+ <element name="items" type="ipo:Items" />
+ </sequence>
+ <attribute name="orderDate" type="date" />
+ </complexType>
+
+ <complexType name="Items">
+ <sequence>
+ <element name="item" minOccurs="0" maxOccurs="unbounded">
+ <complexType>
+ <sequence>
+ <element name="productName" type="string" />
+ <element name="quantity">
+ <simpleType>
+ <restriction base="positiveInteger">
+ <maxExclusive value="100" />
+ </restriction>
+ </simpleType>
+ </element>
+ <element name="USPrice" type="decimal" />
+ <element ref="ipo:comment" minOccurs="0" />
+ <element name="shipDate" type="date"
+ minOccurs="0" />
+ </sequence>
+ <attribute name="partNum" type="ipo:SKU"
+ use="required" />
+ </complexType>
+ </element>
+ </sequence>
+ </complexType>
+
+ <simpleType name="SKU">
+ <restriction base="string">
+ <pattern value="\d{3}-[A-Z]{2}" />
+ </restriction>
+ </simpleType>
+
+ <complexType name="Address">
+ <sequence>
+ <element name="name" type="string" />
+ <element name="street" type="string" />
+ <element name="city" type="string" />
+ </sequence>
+ </complexType>
+
+ <complexType name="USAddress">
+ <complexContent>
+ <extension base="ipo:Address">
+ <sequence>
+ <element name="state" type="ipo:USState" />
+ <element name="zip" type="positiveInteger" />
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <complexType name="UKAddress">
+ <complexContent>
+ <extension base="ipo:Address">
+ <sequence>
+ <element name="postcode" type="ipo:UKPostcode" />
+ </sequence>
+ <attribute name="exportCode" type="positiveInteger"
+ fixed="1" />
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <!-- other Address derivations for more countries -->
+
+ <simpleType name="USState">
+ <restriction base="string">
+ <enumeration value="AK" />
+ <enumeration value="AL" />
+ <enumeration value="AR" />
+ <enumeration value="CA" />
+ <enumeration value="PA" />
+ <!-- and so on ... -->
+ </restriction>
+ </simpleType>
+
+ <simpleType name="Postcode">
+ <restriction base="string">
+ <length value="7" fixed="true" />
+ </restriction>
+ </simpleType>
+
+
+ <simpleType name="UKPostcode">
+ <restriction base="ipo:Postcode">
+ <pattern value="[A-Z]{2}\d\s\d[A-Z]{2}" />
+ </restriction>
+ </simpleType>
+
+
+
+</schema>
+
diff --git a/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/databinding/impl/order.wsdl b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/databinding/impl/order.wsdl
new file mode 100644
index 0000000000..100890e10b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/databinding/impl/order.wsdl
@@ -0,0 +1,76 @@
+<?xml version="1.0"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<definitions name="StockQuote" targetNamespace="http://example.com/order.wsdl" xmlns:tns="http://example.com/order.wsdl"
+ xmlns:xsd1="http://example.com/order.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns="http://schemas.xmlsoap.org/wsdl/">
+
+ <types>
+ <schema targetNamespace="http://example.com/order.xsd" xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:ipo="http://www.example.com/IPO">
+ <import namespace="http://www.example.com/IPO" schemaLocation="ipo.xsd"/>
+ <element name="checkOrderStatus">
+ <complexType>
+ <sequence>
+ <element name="customerId" type="string" />
+ <element name="order" type="ipo:PurchaseOrderType" />
+ <element name="flag" type="int" />
+ </sequence>
+ </complexType>
+ </element>
+ <element name="checkOrderStatusResponse">
+ <complexType>
+ <sequence>
+ <element name="status" type="string" />
+ </sequence>
+ </complexType>
+ </element>
+ <element name="note" type="string" />
+ </schema>
+ </types>
+
+ <message name="CheckOrderStatusInput1">
+ <part name="body" element="xsd1:checkOrderStatus" />
+ </message>
+
+ <message name="CheckOrderStatusOutput1">
+ <part name="body" element="xsd1:checkOrderStatusResponse" />
+ </message>
+
+ <message name="CheckOrderStatusInput2">
+ <part name="p1" element="xsd1:checkOrderStatus" />
+ <part name="p2" element="xsd1:note" />
+ </message>
+
+ <message name="CheckOrderStatusOutput2">
+ <part name="p1" element="xsd1:checkOrderStatusResponse" />
+ </message>
+
+ <portType name="OrderPortType">
+ <operation name="checkOrderStatus">
+ <input message="tns:CheckOrderStatusInput1" />
+ <output message="tns:CheckOrderStatusOutput1" />
+ </operation>
+ <operation name="checkOrderStatus2">
+ <input message="tns:CheckOrderStatusInput2" />
+ <output message="tns:CheckOrderStatusOutput2" />
+ </operation>
+ </portType>
+
+</definitions> \ No newline at end of file
diff --git a/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/databinding/xml/foo.xml b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/databinding/xml/foo.xml
new file mode 100644
index 0000000000..0ba8ade1e0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/databinding/xml/foo.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<f:foo xmlns:f="http://foo" name="foo">
+ <b:bar xmlns:b="http://bar">bar</b:bar>
+</f:foo> \ No newline at end of file
diff --git a/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/deployer/boot1-include.scdl b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/deployer/boot1-include.scdl
new file mode 100644
index 0000000000..838dbf6a9c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/deployer/boot1-include.scdl
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ name="boot1-include">
+
+ <component name="component2">
+ <system:implementation.system class="org.apache.tuscany.core.mock.component.BasicInterfaceImpl"/>
+ </component>
+
+ <service name="service2" promote = "component2">
+ <interface.java interface="org.apache.tuscany.core.mock.component.BasicInterface"/>
+ </service>
+
+</composite>
diff --git a/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/deployer/boot1.scdl b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/deployer/boot1.scdl
new file mode 100644
index 0000000000..8a71aa5698
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/deployer/boot1.scdl
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ targetNamespace="http://example.com" name="boot1">
+ <service name="service" promote = "component">
+ <interface.java interface="org.apache.tuscany.core.mock.component.BasicInterface"/>
+ </service>
+
+ <component name="component">
+ <system:implementation.system class="org.apache.tuscany.core.mock.component.BasicInterfaceImpl"/>
+ <property name="publicProperty">propval</property>
+ <reference name="publicReference" target="component2"/>
+ </component>
+
+ <include name="boot1-include" scdlLocation="boot1-include.scdl"/>
+</composite>
diff --git a/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/deployer/boot2.scdl b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/deployer/boot2.scdl
new file mode 100644
index 0000000000..465e6c5ac5
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/deployer/boot2.scdl
@@ -0,0 +1,160 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<!--
+ A more complex example closer to a typical bootstrap configuration
+ $Rev$ $Date$
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ name="boot2"
+ autowire="true">
+
+
+ <!-- expose Deployer API as a service -->
+ <service name="deployer" promote="deployerImpl">
+ <interface.java interface="org.apache.tuscany.spi.deployer.Deployer"/>
+ </service>
+
+ <!-- Component that provides the Deployer service -->
+ <component name="deployerImpl">
+ <system:implementation.system class="org.apache.tuscany.core.deployer.DeployerImpl"/>
+ </component>
+
+ <!-- Component that provides the Autowire resolver service -->
+ <component name="autowireResolver">
+ <system:implementation.system class="org.apache.tuscany.core.resolver.DefaultAutowireResolver"/>
+ </component>
+
+ <!-- Work management -->
+ <component name="workContext">
+ <system:implementation.system class="org.apache.tuscany.core.component.WorkContextImpl"/>
+ </component>
+
+ <component name="workScheduler">
+ <system:implementation.system class="org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler"/>
+ </component>
+
+ <component name="workManager">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.work.jsr237.workmanager.ThreadPoolWorkManager"/>
+ </component>
+
+ <!-- Builder and BuilderRegistry -->
+ <component name="builder">
+ <system:implementation.system class="org.apache.tuscany.core.builder.BuilderRegistryImpl"/>
+ </component>
+
+ <!-- Loader and LoaderRegistry -->
+ <component name="loader">
+ <system:implementation.system class="org.apache.tuscany.core.loader.LoaderRegistryImpl"/>
+ </component>
+
+ <!-- Introspector and IntrospectionRegistry -->
+ <component name="interfaceProcessorRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.IntrospectionRegistryImpl"/>
+ </component>
+
+ <!-- Connector infrastructure -->
+ <component name="connector">
+ <system:implementation.system class="org.apache.tuscany.core.builder.ConnectorImpl"/>
+ </component>
+
+ <component name="interceptorBuilderRegistry">
+ <system:implementation.system
+ class="org.apache.tuscany.core.builder.interceptor.InterceptorBuilderRegistryImpl"/>
+ </component>
+
+ <component name="wireAttacherRegistry">
+ <system:implementation.system
+ class="org.apache.tuscany.core.builder.physical.WireAttacherRegistryImpl"/>
+ </component>
+
+ <component name="wirePostProcess">
+ <system:implementation.system class="org.apache.tuscany.core.builder.WirePostProcessorRegistryImpl"/>
+ </component>
+
+ <!-- Resource host registry -->
+ <component name="resourceHostRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.services.host.DelegatingResourceHostRegistry"/>
+ </component>
+
+ <!-- Foundation element loader implementations -->
+ <component name="elementLoader.component">
+ <system:implementation.system class="org.apache.tuscany.core.loader.ComponentLoader"/>
+ </component>
+ <component name="elementLoader.componentType">
+ <system:implementation.system class="org.apache.tuscany.core.loader.ComponentTypeElementLoader"/>
+ </component>
+ <component name="elementLoader.interface.java">
+ <system:implementation.system class="org.apache.tuscany.core.idl.java.InterfaceJavaLoader"/>
+ </component>
+ <component name="elementLoader.property">
+ <system:implementation.system class="org.apache.tuscany.core.loader.PropertyLoader"/>
+ </component>
+ <component name="elementLoader.reference">
+ <system:implementation.system class="org.apache.tuscany.core.loader.ReferenceLoader"/>
+ </component>
+ <component name="elementLoader.service">
+ <system:implementation.system class="org.apache.tuscany.core.loader.ServiceLoader"/>
+ </component>
+
+ <component name="proxyService">
+ <system:implementation.system class="org.apache.tuscany.core.wire.jdk.JDKProxyService"/>
+ </component>
+
+ <!-- Composite implementation type -->
+ <component name="composite.loader">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.composite.CompositeLoader"/>
+ </component>
+
+ <component name="interfaceJava.interfaceProcessorRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl"/>
+ </component>
+
+ <component name="artifactRepository">
+ <system:implementation.system class="org.apache.tuscany.core.services.artifact.LocalMavenRepository"/>
+ <property name="repository">.m2/repository</property>
+ </component>
+
+ <!-- DataBinding registry -->
+ <component name="databinding.registry">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.impl.DataBindingRegistryImpl"/>
+ </component>
+
+ <!-- DataBinding registry -->
+ <component name="databinding.mediator">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.impl.MediatorImpl"/>
+ </component>
+
+ <!-- Transformer registry -->
+ <component name="databinding.transformerRegistry" initLevel="90">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.impl.TransformerRegistryImpl"/>
+ </component>
+
+ <component name="propertyFactory">
+ <system:implementation.system class="org.apache.tuscany.core.property.PropertyObjectFactoryImpl"/>
+ </component>
+
+ <component name="policyBuilderRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.policy.PolicyBuilderRegistryImpl"/>
+ </component>
+
+
+</composite>
diff --git a/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/loader/TestPolicy.scdl b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/loader/TestPolicy.scdl
new file mode 100644
index 0000000000..ee75ea23f0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/loader/TestPolicy.scdl
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<!--
+ Default system configuration for the launcher environment.
+
+ $Rev$ $Date$
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
+ name="org.apache.tuscany.core.policy.testCase">
+ <policySet name="BasicAuthMsgProtSecurity"
+ provides="sec.confidentiality" appliesTo="binding.ws binding.jms"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0">
+ <wsp:PolicyAttachment/>
+ <intentMap provides="sec.confidentiality" default="transport">
+ <qualifier name="transport">
+ <wsp:PolicyAttachment/>
+ <wsp:PolicyAttachment/>
+ </qualifier>
+ <qualifier name="message">
+ <intentMap provides="sec.confidentiality/message"
+ default="all">
+ <qualifier name="all">
+ <wsp:PolicyAttachment/>
+ </qualifier>
+ <qualifier name="body">
+ <wsp:PolicyAttachment/>
+ </qualifier>
+ </intentMap>
+ </qualifier>
+ </intentMap>
+ </policySet>
+</composite> \ No newline at end of file
diff --git a/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/loader/test-include.scdl b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/loader/test-include.scdl
new file mode 100644
index 0000000000..584846504b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/loader/test-include.scdl
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite>
+ This file just needs to exist
+</composite> \ No newline at end of file
diff --git a/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/policy/PolicySet.scdl b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/policy/PolicySet.scdl
new file mode 100644
index 0000000000..0860855d9d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/policy/PolicySet.scdl
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<!--
+ Default system configuration for the launcher environment.
+
+ $Rev$ $Date$
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
+ name="org.apache.tuscany.core.policy.testCase">
+ <policySet name="BasicMsgProtSecurity"
+ provides="sec.confidentiality" appliesTo="binding.ws binding.jms"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0">
+ <wsp:PolicyAttachment/>
+ <intentMap provides="sec.confidentiality" default="transport">
+ <qualifier name="transport">
+ <wsp:PolicyAttachment/>
+ <wsp:PolicyAttachment/>
+ </qualifier>
+ <qualifier name="message">
+ <intentMap provides="sec.confidentiality/message"
+ default="all">
+ <qualifier name="all">
+ <wsp:PolicyAttachment/>
+ </qualifier>
+ <qualifier name="body">
+ <wsp:PolicyAttachment/>
+ </qualifier>
+ </intentMap>
+ </qualifier>
+ </intentMap>
+ </policySet>
+
+ <policySet name="Authentication"
+ provides="sec.authentication" appliesTo="binding.ws binding.jms">
+ <wsp:PolicyAttachment/>
+ <intentMap provides="authentication" default="cert">
+ <qualifier name="cert">
+ <wsp:PolicyAttachment/>
+ <wsp:PolicyAttachment/>
+ </qualifier>
+ <qualifier name="basic">
+ <wsp:PolicyAttachment/>
+ </qualifier>
+ </intentMap>
+ </policySet>
+
+</composite> \ No newline at end of file
diff --git a/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/property/ipo.xml b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/property/ipo.xml
new file mode 100644
index 0000000000..5bef464cf7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/property/ipo.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<ipo:purchaseOrder
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:ipo="http://www.example.com/IPO"
+ xsi:schemaLocation="http://www.example.com/IPO ipo.xsd"
+ orderDate="1999-12-01">
+
+ <shipTo exportCode="1" xsi:type="ipo:UKAddress">
+ <name>Helen Zoe</name>
+ <street>47 Eden Street</street>
+ <city>Cambridge</city>
+ <postcode>CB1 1JR</postcode>
+ </shipTo>
+
+ <billTo xsi:type="ipo:USAddress">
+ <name>Robert Smith</name>
+ <street>8 Oak Avenue</street>
+ <city>Old Town</city>
+ <state>PA</state>
+ <zip>95819</zip>
+ </billTo>
+
+ <items>
+ <item partNum="833-AA">
+ <productName>Lapis necklace</productName>
+ <quantity>1</quantity>
+ <USPrice>99.95</USPrice>
+ <ipo:comment>Want this for the holidays</ipo:comment>
+ <shipDate>1999-12-05</shipDate>
+ </item>
+ </items>
+</ipo:purchaseOrder>
+
diff --git a/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/services/deployment/test.ext b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/services/deployment/test.ext
new file mode 100644
index 0000000000..042f3ce1f3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/services/deployment/test.ext
@@ -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.
+ */
diff --git a/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/services/deployment/test.scdl b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/services/deployment/test.scdl
new file mode 100644
index 0000000000..1e09549194
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/resources/org/apache/tuscany/core/services/deployment/test.scdl
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite>
+ This file just needs to exist
+</composite> \ No newline at end of file
diff --git a/tags/java/tsss-demo/kernel/core/src/test/resources/repository/sample-calculator.jar b/tags/java/tsss-demo/kernel/core/src/test/resources/repository/sample-calculator.jar
new file mode 100644
index 0000000000..0ca3a1b781
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/core/src/test/resources/repository/sample-calculator.jar
Binary files differ
diff --git a/tags/java/tsss-demo/kernel/databinding/.checkstyle b/tags/java/tsss-demo/kernel/databinding/.checkstyle
new file mode 100644
index 0000000000..142759d295
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/databinding/.checkstyle
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<fileset-config file-format-version="1.2.0" simple-config="true">
+ <fileset name="all" enabled="true" check-config-name="Tuscany Checks" local="false">
+ <file-match-pattern match-pattern="." include-pattern="true"/>
+ </fileset>
+</fileset-config>
diff --git a/tags/java/tsss-demo/kernel/databinding/.pmd b/tags/java/tsss-demo/kernel/databinding/.pmd
new file mode 100644
index 0000000000..9606e17e2d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/databinding/.pmd
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<pmd><useProjectRuleSet>true</useProjectRuleSet><rules/><includeDerivedFiles>false</includeDerivedFiles></pmd> \ No newline at end of file
diff --git a/tags/java/tsss-demo/kernel/databinding/.ruleset b/tags/java/tsss-demo/kernel/databinding/.ruleset
new file mode 100644
index 0000000000..ba9b5ce886
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/databinding/.ruleset
@@ -0,0 +1,190 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<ruleset name="pmd-eclipse">
+ <description>PMD Plugin preferences rule set</description>
+
+
+ <rule ref="rulesets/basic.xml/BooleanInstantiation"/>
+ <rule ref="rulesets/basic.xml/CollapsibleIfStatements"/>
+ <rule ref="rulesets/basic.xml/DoubleCheckedLocking"/>
+<!--<rule ref="rulesets/basic.xml/EmptyCatchBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyFinallyBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyIfStmt"/>-->
+ <rule ref="rulesets/basic.xml/EmptyStatementNotInLoop"/>
+<!--<rule ref="rulesets/basic.xml/EmptyStaticInitializer"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptySwitchStatements"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptySynchronizedBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyTryBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyWhileStmt"/>-->
+ <rule ref="rulesets/basic.xml/ForLoopShouldBeWhileLoop"/>
+ <rule ref="rulesets/basic.xml/JumbledIncrementer"/>
+<!--<rule ref="rulesets/basic.xml/OverrideBothEqualsAndHashcode"/>-->
+ <rule ref="rulesets/basic.xml/ReturnFromFinallyBlock"/>
+ <rule ref="rulesets/basic.xml/UnconditionalIfStatement"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryConversionTemporary"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryFinalModifier"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryReturn"/>
+<!--<rule ref="rulesets/basic.xml/UselessOverridingMethod"/>-->
+
+<!--<rule ref="rulesets/braces.xml/ForLoopsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/IfElseStmtsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/IfStmtsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/WhileLoopsMustUseBraces"/>-->
+
+<!--<rule ref="rulesets/clone.xml/CloneMethodMustImplementCloneable"/>-->
+<!--<rule ref="rulesets/clone.xml/CloneThrowsCloneNotSupportedException"/>-->
+<!--<rule ref="rulesets/clone.xml/ProperCloneImplementation"/>-->
+
+<!--<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>-->
+<!--<rule ref="rulesets/codesize.xml/TooManyFields"/>-->
+
+<rule ref="rulesets/controversial.xml/AssignmentInOperand"/>
+<!--<rule ref="rulesets/controversial.xml/AtLeastOneConstructor"/>-->
+<!--<rule ref="rulesets/controversial.xml/CallSuperInConstructor"/>-->
+<!--<rule ref="rulesets/controversial.xml/DontImportSun"/>-->
+<!--<rule ref="rulesets/controversial.xml/NullAssignment"/>-->
+<!--<rule ref="rulesets/controversial.xml/OnlyOneReturn"/>-->
+<!--<rule ref="rulesets/controversial.xml/SingularField"/>-->
+<!--<rule ref="rulesets/controversial.xml/SuspiciousOctalEscape"/>-->
+<!--<rule ref="rulesets/controversial.xml/UnnecessaryConstructor"/>-->
+<rule ref="rulesets/controversial.xml/UnnecessaryParentheses"/>
+<!--<rule ref="rulesets/controversial.xml/UnusedModifier"/>-->
+
+<!--<rule ref="rulesets/coupling.xml/CouplingBetweenObjects"/>-->
+<!--<rule ref="rulesets/coupling.xml/ExcessiveImports"/>-->
+<!--<rule ref="rulesets/coupling.xml/LooseCoupling"/>-->
+
+<!--<rule ref="rulesets/design.xml/AbstractClassWithoutAbstractMethod"/>-->
+<!--<rule ref="rulesets/design.xml/AccessorClassGeneration"/>-->
+<!--<rule ref="rulesets/design.xml/AssignmentToNonFinalStatic"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidDeeplyNestedIfStmts"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidInstanceofChecksInCatchClause"/>-->
+<rule ref="rulesets/design.xml/AvoidProtectedFieldInFinalClass"/>
+<!--<rule ref="rulesets/design.xml/AvoidReassigningParameters"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidSynchronizedAtMethodLevel"/>-->
+<!--<rule ref="rulesets/design.xml/BadComparison"/>-->
+<!--<rule ref="rulesets/design.xml/CloseConnection"/>-->
+<!--<rule ref="rulesets/design.xml/CompareObjectsWithEquals"/>-->
+<!--<rule ref="rulesets/design.xml/ConfusingTernary"/>-->
+<rule ref="rulesets/design.xml/ConstructorCallsOverridableMethod"/>
+<!--<rule ref="rulesets/design.xml/DefaultLabelNotLastInSwitchStmt"/>-->
+<!--<rule ref="rulesets/design.xml/FinalFieldCouldBeStatic"/>-->
+<rule ref="rulesets/design.xml/IdempotentOperations"/>
+<!--<rule ref="rulesets/design.xml/ImmutableField"/>-->
+<!--<rule ref="rulesets/design.xml/InstantiationToGetClass"/>-->
+<!--<rule ref="rulesets/design.xml/MissingBreakInSwitch"/>-->
+<!--<rule ref="rulesets/design.xml/MissingStaticMethodInNonInstantiatableClass"/>-->
+<!--<rule ref="rulesets/design.xml/NonCaseLabelInSwitchStatement"/>-->
+<!--<rule ref="rulesets/design.xml/NonStaticInitializer"/>-->
+<rule ref="rulesets/design.xml/OptimizableToArrayCall"/>
+<rule ref="rulesets/design.xml/PositionLiteralsFirstInComparisons"/>
+<rule ref="rulesets/design.xml/SimplifyBooleanExpressions"/>
+<rule ref="rulesets/design.xml/SimplifyBooleanReturns"/>
+<rule ref="rulesets/design.xml/SimplifyConditional"/>
+<!--<rule ref="rulesets/design.xml/SwitchDensity"/>-->
+<!--<rule ref="rulesets/design.xml/SwitchStmtsShouldHaveDefault"/>-->
+<!--<rule ref="rulesets/design.xml/UnnecessaryLocalBeforeReturn"/>-->
+<!--<rule ref="rulesets/design.xml/UseLocaleWithCaseConversions"/>-->
+<!--<rule ref="rulesets/design.xml/UseNotifyAllInsteadOfNotify"/>-->
+<!--<rule ref="rulesets/design.xml/UseSingleton"/>-->
+
+<!--<rule ref="rulesets/finalizers.xml/EmptyFinalizer"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeOnlyCallsSuperFinalize"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeOverloaded"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeDoesNotCallSuperFinalize"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeShouldBeProtected"/>-->
+<!--<rule ref="rulesets/finalizers.xml/AvoidCallingFinalize"/>-->
+
+<!--<rule ref="rulesets/imports.xml/DuplicateImports"/>-->
+<!--<rule ref="rulesets/imports.xml/DontImportJavaLang"/>-->
+<!--<rule ref="rulesets/imports.xml/UnusedImports"/>-->
+<!--<rule ref="rulesets/imports.xml/ImportFromSamePackage"/>-->
+
+<!--<rule ref="rulesets/javabeans.xml/BeanMembersShouldSerialize"/>-->
+<!--<rule ref="rulesets/javabeans.xml/MissingSerialVersionUID"/>-->
+
+<!--<rule ref="rulesets/junit.xml/JUnitStaticSuite"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitSpelling"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitAssertionsShouldIncludeMessage"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitTestsShouldIncludeAssert"/>-->
+<!--<rule ref="rulesets/junit.xml/TestClassWithoutTestCases"/>-->
+<!--<rule ref="rulesets/junit.xml/UnnecessaryBooleanAssertion"/>-->
+<!--<rule ref="rulesets/junit.xml/UseAssertEqualsInsteadOfAssertTrue"/>-->
+<!--<rule ref="rulesets/junit.xml/UseAssertSameInsteadOfAssertTrue"/>-->
+
+ <!--<rule ref="rulesets/logging-java.xml/AvoidPrintStackTrace"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/MoreThanOneLogger"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LogBlockWithoutIf"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/SystemPrintln"/>-->
+ <!--<rule ref="rulesets/logging-jakarta-commons.xml/UseCorrectExceptionLogging"/>-->
+ <!--<rule ref="rulesets/logging-jakarta-commons.xml/ProperLogger"/>-->
+
+ <!--<rule ref="rulesets/naming.xml/ShortVariable"/>-->
+ <!--<rule ref="rulesets/naming.xml/LongVariable"/>-->
+ <!--<rule ref="rulesets/naming.xml/ShortMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/VariableNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/MethodNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/ClassNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/AbstractNaming"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidDollarSigns"/>-->
+ <!--<rule ref="rulesets/naming.xml/MethodWithSameNameAsEnclosingClass"/>-->
+ <!--<rule ref="rulesets/naming.xml/SuspiciousHashcodeMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/SuspiciousConstantFieldName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingTypeName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidNonConstructorMethodsWithClassName"/>-->
+ <!--<rule ref="rulesets/naming.xml/NoPackage"/>-->
+ <!--<rule ref="rulesets/naming.xml/PackageCase"/>-->
+
+ <!--<rule ref="rulesets/optimizations.xml/LocalVariableCouldBeFinal"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/MethodArgumentCouldBeFinal"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/AvoidInstantiatingObjectsInLoops"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/UseArrayListInsteadOfVector"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/SimplifyStartsWith"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/UseStringBufferForStringAppends"/>-->
+
+ <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingThrowable"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/SignatureDeclareThrowsException"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/ExceptionAsFlowControl"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingNPE"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingRawExceptionTypes"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingNullPointerException"/>-->
+
+ <!--<rule ref="rulesets/strings.xml/AvoidDuplicateLiterals"/>-->
+ <!--<rule ref="rulesets/strings.xml/StringInstantiation"/>-->
+ <!--<rule ref="rulesets/strings.xml/StringToString"/>-->
+ <!--<rule ref="rulesets/strings.xml/AvoidConcatenatingNonLiteralsInStringBuffer"/>-->
+ <!--<rule ref="rulesets/strings.xml/UnnecessaryCaseChange"/>-->
+
+ <!--<rule ref="rulesets/sunsecure.xml/MethodReturnsInternalArray"/>-->
+ <!--<rule ref="rulesets/sunsecure.xml/ArrayIsStoredDirectly"/>-->
+
+ <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/>
+ <rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/>
+ <rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/>
+ <!--<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>-->
+
+</ruleset>
diff --git a/tags/java/tsss-demo/kernel/databinding/LICENSE.txt b/tags/java/tsss-demo/kernel/databinding/LICENSE.txt
new file mode 100644
index 0000000000..0084319535
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/databinding/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, serviceDefinition marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/kernel/databinding/NOTICE.txt b/tags/java/tsss-demo/kernel/databinding/NOTICE.txt
new file mode 100644
index 0000000000..d83ebbe236
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/databinding/NOTICE.txt
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/kernel/databinding/pom.xml b/tags/java/tsss-demo/kernel/databinding/pom.xml
new file mode 100644
index 0000000000..e39f177f01
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/databinding/pom.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>kernel</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-core-databinding</artifactId>
+ <packaging>jar</packaging>
+ <name>Apache Tuscany Core/DataBinding Integration</name>
+ <description>Apache Tuscany Core/DataBinding Integration</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.services.databinding</groupId>
+ <artifactId>databinding-framework</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ <version>1.0.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/loader/DataTypeLoader.java b/tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/loader/DataTypeLoader.java
new file mode 100644
index 0000000000..b44a224838
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/loader/DataTypeLoader.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.core.databinding.loader;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.InvalidValueException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.LoaderUtil;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * The StAX loader for data type
+ */
+public class DataTypeLoader extends LoaderExtension<DataType> {
+ public static final QName DATA_BINDING =
+ new QName("http://tuscany.apache.org/xmlns/sca/databinding/1.0", "databinding");
+
+ @Constructor({"registry"})
+ public DataTypeLoader(@Reference LoaderRegistry registry) {
+ super(registry);
+ }
+
+ @Override
+ public QName getXMLType() {
+ return DATA_BINDING;
+ }
+
+ public DataType load(ModelObject object, XMLStreamReader reader,
+ DeploymentContext deploymentContext) throws XMLStreamException, LoaderException {
+ assert DATA_BINDING.equals(reader.getName());
+ String name = reader.getAttributeValue(null, "name");
+ LoaderUtil.skipToEndElement(reader);
+ if (name == null) {
+ throw new InvalidValueException("The 'name' attrbiute is required");
+ }
+ DataType dataType = new DataType<Class>(name, Object.class, Object.class);
+ return dataType;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessor.java b/tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessor.java
new file mode 100644
index 0000000000..057614d5af
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessor.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.core.databinding.processor;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.datatype.Duration;
+import javax.xml.datatype.XMLGregorianCalendar;
+
+import org.apache.tuscany.api.annotation.DataType;
+import org.apache.tuscany.spi.databinding.DataBindingRegistry;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorExtension;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * The databinding annotation processor for java interfaces
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataBindingJavaInterfaceProcessor extends JavaInterfaceProcessorExtension {
+ private static final Class[] SIMPLE_JAVA_TYPES =
+ {Byte.class, Character.class, Short.class, Integer.class, Long.class, Float.class, Double.class, Date.class,
+ Calendar.class, GregorianCalendar.class, Duration.class, XMLGregorianCalendar.class, BigInteger.class,
+ BigDecimal.class};
+
+ private static final Set<Class> SIMPLE_TYPE_SET = new HashSet<Class>(Arrays.asList(SIMPLE_JAVA_TYPES));
+
+ private DataBindingRegistry dataBindingRegistry;
+
+ public DataBindingJavaInterfaceProcessor(@Reference
+ DataBindingRegistry dataBindingRegistry) {
+ super();
+ this.dataBindingRegistry = dataBindingRegistry;
+ }
+
+ public void visitInterface(Class<?> clazz, Class<?> callbackClass, JavaServiceContract contract)
+ throws InvalidServiceContractException {
+ if (!contract.isRemotable()) {
+ return;
+ }
+ Map<String, Operation<Type>> operations = contract.getOperations();
+ processInterface(clazz, contract, operations);
+ if (callbackClass != null) {
+ Map<String, Operation<Type>> callbackOperations = contract.getCallbackOperations();
+ processInterface(callbackClass, contract, callbackOperations);
+ }
+ }
+
+ private void processInterface(Class<?> clazz, JavaServiceContract contract,
+ Map<String, Operation<Type>> operations) {
+ // IDLMapping interfaceMapping = clazz.getAnnotation(IDLMapping.class);
+ DataType interfaceDataType = clazz.getAnnotation(DataType.class);
+ if (interfaceDataType != null) {
+ contract.setDataBinding(interfaceDataType.name());
+ }
+ for (Method method : clazz.getMethods()) {
+ Operation<?> operation = operations.get(method.getName());
+ DataType operationDataType = method.getAnnotation(DataType.class);
+ if (operationDataType == null) {
+ operationDataType = interfaceDataType;
+ }
+
+ if (operationDataType != null) {
+ operation.setDataBinding(operationDataType.name());
+ // FIXME: [rfeng] Keep data context as metadata?
+ }
+// IDLMapping operationMapping = clazz.getAnnotation(IDLMapping.class);
+// if (operationMapping == null) {
+// operationMapping = interfaceMapping;
+// }
+//
+// if (operationMapping != null) {
+// operation.setDataBinding(operationMapping.dataBinding());
+// operation.setWrapperStyle(operationMapping.wrapperStyle());
+// }
+ // String dataBinding = operation.getDataBinding();
+
+ Annotation[] annotations = null;
+ if (operationDataType != null) {
+ annotations = new Annotation[] {operationDataType};
+ }
+ // FIXME: We need a better way to identify simple java types
+ for (org.apache.tuscany.spi.model.DataType<?> d : operation.getInputType().getLogical()) {
+ dataBindingRegistry.introspectType(d, annotations);
+ }
+ if (operation.getOutputType() != null) {
+ dataBindingRegistry.introspectType(operation.getOutputType(), annotations);
+ }
+ for (org.apache.tuscany.spi.model.DataType<?> d : operation.getFaultTypes()) {
+ dataBindingRegistry.introspectType(d, annotations);
+ }
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/processor/JavaInterfaceIntrospector.java b/tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/processor/JavaInterfaceIntrospector.java
new file mode 100644
index 0000000000..e93eaffebb
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/processor/JavaInterfaceIntrospector.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.core.databinding.processor;
+
+import static org.apache.tuscany.spi.model.Operation.CONVERSATION_END;
+import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.spi.databinding.DataBinding;
+import org.apache.tuscany.spi.idl.InvalidConversationalOperationException;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.OverloadedOperationException;
+import org.apache.tuscany.spi.idl.java.InterfaceJavaIntrospector;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.Conversational;
+import org.osoa.sca.annotations.EndsConversation;
+import org.osoa.sca.annotations.OneWay;
+import org.osoa.sca.annotations.Remotable;
+
+/**
+ * Default implementation of an InterfaceJavaIntrospector.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaInterfaceIntrospector implements InterfaceJavaIntrospector {
+ private static final String UNKNOWN_DATABINDING = null;
+
+ public JavaInterfaceIntrospector() {
+ }
+
+ public <T> JavaServiceContract<T> introspect(Class<T> type) throws InvalidServiceContractException {
+ Class<?> callbackClass = null;
+ Callback callback = type.getAnnotation(Callback.class);
+ if (callback != null && !Void.class.equals(callback.value())) {
+ callbackClass = callback.value();
+ } else if (callback != null && Void.class.equals(callback.value())) {
+ throw new IllegalArgumentException("No callback interface specified on annotation" + type.getName());
+ }
+ return introspect(type, callbackClass);
+ }
+
+ public <I, C> JavaServiceContract<I> introspect(Class<I> type, Class<C> callback)
+ throws InvalidServiceContractException {
+ JavaServiceContract<I> contract = new JavaServiceContract<I>();
+ contract.setInterfaceName(getBaseName(type));
+ contract.setInterfaceClass(type);
+ boolean remotable = type.isAnnotationPresent(Remotable.class);
+ contract.setRemotable(remotable);
+ //Scope interactionScope = type.getAnnotation(Scope.class);
+ boolean conversational = type.isAnnotationPresent(Conversational.class);
+ contract.setConversational(conversational);
+ contract.setOperations(getOperations(type, remotable, conversational));
+
+ if (callback != null) {
+ contract.setCallbackName(getBaseName(callback));
+ contract.setCallbackClass(callback);
+ contract.setCallbackOperations(getOperations(callback, remotable, conversational));
+ }
+ return contract;
+ }
+
+ private <T> Map<String, Operation<Type>> getOperations(Class<T> type, boolean remotable, boolean conversational)
+ throws InvalidServiceContractException {
+ Method[] methods = type.getMethods();
+ Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>(methods.length);
+ for (Method method : methods) {
+ String name = method.getName();
+ if (remotable && operations.containsKey(name)) {
+ throw new OverloadedOperationException(method);
+ }
+
+ Type returnType = method.getGenericReturnType();
+ Type[] paramTypes = method.getGenericParameterTypes();
+ Type[] faultTypes = method.getGenericExceptionTypes();
+ boolean nonBlocking = method.isAnnotationPresent(OneWay.class);
+ int conversationSequence = NO_CONVERSATION;
+ if (method.isAnnotationPresent(EndsConversation.class)) {
+ if (!conversational) {
+ throw new InvalidConversationalOperationException(
+ "Method is marked as end conversation but contract is not conversational",
+ method.getDeclaringClass().getName(),
+ method);
+ }
+ conversationSequence = CONVERSATION_END;
+ } else if (conversational) {
+ conversationSequence = Operation.CONVERSATION_CONTINUE;
+ }
+
+ DataType<Type> returnDataType = new DataType<Type>(UNKNOWN_DATABINDING, returnType, returnType);
+ List<DataType<Type>> paramDataTypes = new ArrayList<DataType<Type>>(paramTypes.length);
+ for (Type paramType : paramTypes) {
+ paramDataTypes.add(new DataType<Type>(UNKNOWN_DATABINDING, paramType, paramType));
+ }
+ List<DataType<Type>> faultDataTypes = new ArrayList<DataType<Type>>(faultTypes.length);
+ for (Type faultType : faultTypes) {
+ faultDataTypes.add(new DataType<Type>(UNKNOWN_DATABINDING, faultType, faultType));
+ }
+
+ DataType<List<DataType<Type>>> inputType =
+ new DataType<List<DataType<Type>>>(DataBinding.IDL_INPUT, Object[].class, paramDataTypes);
+ Operation<Type> operation = new Operation<Type>(name,
+ inputType,
+ returnDataType,
+ faultDataTypes,
+ nonBlocking,
+ UNKNOWN_DATABINDING,
+ conversationSequence);
+ operations.put(name, operation);
+ }
+ return operations;
+ }
+
+ /**
+ * Returns the simple name of a class - i.e. the class name devoid of its package qualifier
+ *
+ * @param implClass the implmentation class
+ */
+ public static String getBaseName(Class<?> implClass) {
+ String baseName = implClass.getName();
+ int lastDot = baseName.lastIndexOf('.');
+ if (lastDot != -1) {
+ baseName = baseName.substring(lastDot + 1);
+ }
+ return baseName;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Exception2ExceptionTransformer.java b/tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Exception2ExceptionTransformer.java
new file mode 100644
index 0000000000..dead9b7ca7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/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.spi.databinding.DataBinding;
+import org.apache.tuscany.spi.databinding.ExceptionHandler;
+import org.apache.tuscany.spi.databinding.Mediator;
+import org.apache.tuscany.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.apache.tuscany.spi.model.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 TransformerExtension<Object[], Object[]> implements
+ PullTransformer<Exception, Exception> {
+
+ 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.spi.databinding.extension.TransformerExtension#getSourceType()
+ */
+ @Override
+ protected Class getSourceType() {
+ return Exception.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.extension.TransformerExtension#getTargetType()
+ */
+ @Override
+ protected Class getTargetType() {
+ return Exception.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.Transformer#getWeight()
+ */
+ public int getWeight() {
+ return 10000;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Exception transform(Exception source, TransformationContext context) {
+ DataType<DataType> sourceType = context.getSourceDataType();
+
+ DataType<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<DataType> targetType) {
+ DataType targetFaultType = (DataType)targetType.getLogical();
+ DataBinding targetDataBinding =
+ mediator.getDataBindingRegistry().getDataBinding(targetFaultType.getDataBinding());
+ if (targetDataBinding == null) {
+ return null;
+ }
+ ExceptionHandler targetHandler = targetDataBinding.getExceptionHandler();
+ return targetHandler;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Input2InputTransformer.java b/tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Input2InputTransformer.java
new file mode 100644
index 0000000000..4ba033a826
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Input2InputTransformer.java
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.databinding.transformers;
+
+import java.util.List;
+
+import org.apache.tuscany.spi.databinding.DataBinding;
+import org.apache.tuscany.spi.databinding.Mediator;
+import org.apache.tuscany.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.WrapperHandler;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.ElementInfo;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.WrapperInfo;
+import org.apache.tuscany.spi.model.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 TransformerExtension<Object[], Object[]> implements
+ PullTransformer<Object[], Object[]> {
+
+ 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.spi.databinding.extension.TransformerExtension#getSourceType()
+ */
+ @Override
+ protected Class getSourceType() {
+ return Object[].class;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.extension.TransformerExtension#getTargetType()
+ */
+ @Override
+ protected Class getTargetType() {
+ return Object[].class;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.Transformer#getWeight()
+ */
+ public int getWeight() {
+ return 10000;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object[] transform(Object[] source, TransformationContext context) {
+ DataType<List<DataType<?>>> sourceType = context.getSourceDataType();
+ Operation<?> sourceOp = (Operation<?>)sourceType.getOperation();
+ boolean sourceWrapped = sourceOp != null && sourceOp.isWrapperStyle();
+
+ WrapperHandler sourceWrapperHandler = null;
+ if (sourceWrapped) {
+ sourceWrapperHandler = getWapperHandler(sourceType.getOperation().getDataBinding(), true);
+ }
+
+ DataType<List<DataType<XMLType>>> targetType = context.getTargetDataType();
+ Operation<?> targetOp = (Operation<?>)targetType.getOperation();
+ boolean targetWrapped = targetOp != null && targetOp.isWrapperStyle();
+ WrapperHandler targetWrapperHandler = null;
+ if (targetWrapped) {
+ targetWrapperHandler = getWapperHandler(targetType.getOperation().getDataBinding(), 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<DataType<XMLType>> argTypes = wrapper.getUnwrappedInputType().getLogical();
+
+ for (int i = 0; i < source.length; i++) {
+ ElementInfo argElement = wrapper.getInputChildElements().get(i);
+ DataType<XMLType> 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<ElementInfo> childElements = sourceOp.getWrapper().getInputChildElements();
+ Object[] target = null;
+
+ targetWrapperHandler = getWapperHandler(targetType.getOperation().getDataBinding(), false);
+ if (targetWrapperHandler != null) {
+ ElementInfo wrapperElement = sourceOp.getWrapper().getInputWrapperElement();
+ // Object targetWrapper =
+ // targetWrapperHandler.create(wrapperElement, context);
+ DataType<XMLType> targetWrapperType =
+ new DataType<XMLType>(targetType.getOperation().getDataBinding(), 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<XMLType> 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 getWapperHandler(String dataBindingId, boolean required) {
+ DataBinding dataBinding = mediator.getDataBindingRegistry().getDataBinding(dataBindingId);
+ WrapperHandler wrapperHandler = dataBinding == null ? null : dataBinding.getWrapperHandler();
+ if (wrapperHandler == null && required) {
+ throw new TransformationException(
+ "No wrapper handler is provided for databinding: " + dataBindingId);
+ }
+ return wrapperHandler;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Output2OutputTransformer.java b/tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Output2OutputTransformer.java
new file mode 100644
index 0000000000..c2a12ffc5f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Output2OutputTransformer.java
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.databinding.transformers;
+
+import java.util.List;
+
+import org.apache.tuscany.spi.databinding.DataBinding;
+import org.apache.tuscany.spi.databinding.Mediator;
+import org.apache.tuscany.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.WrapperHandler;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.ElementInfo;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.WrapperInfo;
+import org.apache.tuscany.spi.model.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 TransformerExtension<Object, Object> implements
+ PullTransformer<Object, Object> {
+
+ 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.spi.databinding.extension.TransformerExtension#getSourceType()
+ */
+ @Override
+ protected Class getSourceType() {
+ return Object.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.extension.TransformerExtension#getTargetType()
+ */
+ @Override
+ protected Class getTargetType() {
+ return Object.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.Transformer#getWeight()
+ */
+ public int getWeight() {
+ return 10;
+ }
+
+ private WrapperHandler getWapperHandler(Operation<?> operation) {
+ String dataBindingId;
+ dataBindingId = operation.getDataBinding();
+ DataBinding dataBinding = mediator.getDataBindingRegistry().getDataBinding(dataBindingId);
+ WrapperHandler wrapperHandler = dataBinding == null ? null : dataBinding.getWrapperHandler();
+ if (wrapperHandler == null) {
+ throw new TransformationException(
+ "No wrapper handler is provided for databinding: " + dataBindingId);
+ }
+ return wrapperHandler;
+ }
+
+ private WrapperHandler getWapperHandler(String dataBindingId) {
+ DataBinding dataBinding = mediator.getDataBindingRegistry().getDataBinding(dataBindingId);
+ return dataBinding == null ? null : dataBinding.getWrapperHandler();
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object transform(Object response, TransformationContext context) {
+ try {
+ DataType<DataType> sourceType = context.getSourceDataType();
+ Operation<?> sourceOp = (Operation<?>)sourceType.getOperation();
+ boolean sourceWrapped = sourceOp != null && sourceOp.isWrapperStyle();
+ WrapperHandler sourceWrapperHandler = null;
+ if (sourceWrapped) {
+ sourceWrapperHandler = getWapperHandler(sourceOp);
+ }
+
+ DataType<DataType> targetType = context.getTargetDataType();
+ Operation<?> targetOp = (Operation<?>)targetType.getOperation();
+ boolean targetWrapped = targetOp != null && targetOp.isWrapperStyle();
+ WrapperHandler targetWrapperHandler = null;
+ if (targetWrapped) {
+ targetWrapperHandler = getWapperHandler(targetOp);
+ }
+
+ if ((!sourceWrapped) && targetWrapped) {
+ // Unwrapped --> Wrapped
+ WrapperInfo wrapper = targetOp.getWrapper();
+ Object targetWrapper =
+ targetWrapperHandler.create(wrapper.getOutputWrapperElement(), context);
+
+ List<ElementInfo> childElements = wrapper.getOutputChildElements();
+ if (childElements.isEmpty()) {
+ // void output
+ return targetWrapper;
+ }
+ ElementInfo argElement = childElements.get(0);
+ DataType<XMLType> 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<ElementInfo> childElements = sourceOp.getWrapper().getOutputChildElements();
+ if (childElements.isEmpty()) {
+ // The void output
+ return null;
+ }
+ targetWrapperHandler = getWapperHandler(targetType.getLogical().getDataBinding());
+ if (targetWrapperHandler != null) {
+ ElementInfo wrapperElement = sourceOp.getWrapper().getInputWrapperElement();
+ // Object targetWrapper =
+ // targetWrapperHandler.create(wrapperElement, context);
+ DataType<XMLType> targetWrapperType =
+ new DataType<XMLType>(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/tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataBindingInteceptor.java b/tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataBindingInteceptor.java
new file mode 100644
index 0000000000..eca40da1eb
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataBindingInteceptor.java
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.databinding.wire;
+
+import java.lang.reflect.InvocationTargetException;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ComponentManager;
+import org.apache.tuscany.spi.databinding.DataBinding;
+import org.apache.tuscany.spi.databinding.ExceptionHandler;
+import org.apache.tuscany.spi.databinding.Mediator;
+import org.apache.tuscany.spi.databinding.TransformationException;
+import org.apache.tuscany.spi.idl.ServiceFaultException;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.util.UriHelper;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * An interceptor to transform data accross databindings on the wire
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataBindingInteceptor implements Interceptor {
+ private Interceptor next;
+
+ private Component composite;
+
+ private Operation<?> sourceOperation;
+
+ private Operation<?> targetOperation;
+
+ private Mediator mediator;
+
+ public DataBindingInteceptor(ComponentManager componentManager,
+ Wire wire,
+ Operation<?> sourceOperation,
+ Operation<?> targetOperation) {
+ super();
+ this.sourceOperation = sourceOperation;
+ this.targetOperation = targetOperation;
+ URI uri = wire.getSourceUri();
+ URI sourceUri = UriHelper.getDefragmentedName(uri);
+ this.composite = componentManager.getComponent(sourceUri);
+
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.wire.Interceptor#getNext()
+ */
+ public Interceptor getNext() {
+ return next;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.wire.Interceptor#invoke(org.apache.tuscany.spi.wire.Message)
+ */
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.tuscany.spi.wire.Interceptor#invoke(org.apache.tuscany.spi.wire.Message)
+ */
+ public Message invoke(Message msg) {
+ Object input = transform(msg.getBody(), sourceOperation.getInputType(), targetOperation.getInputType());
+ 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<T>>?
+ DataType<DataType> targetType =
+ new DataType<DataType>(DataBinding.IDL_OUTPUT, Object.class, targetOperation.getOutputType());
+
+ targetType.setOperation(targetOperation.getOutputType().getOperation());
+ DataType<DataType> sourceType =
+ new DataType<DataType>(DataBinding.IDL_OUTPUT, Object.class, sourceOperation.getOutputType());
+ sourceType.setOperation(sourceOperation.getOutputType().getOperation());
+
+ 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 ServiceFaultException) {
+ if (((ServiceFaultException)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.setBodyWithFault(newResult);
+ }
+ }
+
+ } else {
+ assert !(result instanceof Throwable) : "Expected messages that are not throwable " + result;
+
+ Object newResult = transform(result, targetType, sourceType);
+ if (newResult != result) {
+ resultMsg.setBody(newResult);
+ }
+ }
+
+ return resultMsg;
+ }
+
+ private Object transform(Object source, DataType sourceType, DataType targetType) {
+ if (sourceType == targetType || (sourceType != null && sourceType.equals(targetType))) {
+ return source;
+ }
+ Map<Class<?>, Object> metadata = new HashMap<Class<?>, Object>();
+ metadata.put(Component.class, composite);
+ 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.getDataBindingRegistry().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<Class<?>, Object> metadata = new HashMap<Class<?>, Object>();
+ metadata.put(Component.class, composite);
+
+ DataType<DataType<?>> eSourceDataType =
+ new DataType<DataType<?>>("idl:fault", sourceExType.getPhysical(), sourceType);
+ DataType<DataType<?>> eTargetDataType =
+ new DataType<DataType<?>>("idl:fault", targetExType.getPhysical(), targetType);
+
+ return mediator.mediate(source, eSourceDataType, eTargetDataType, metadata);
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.wire.Interceptor#isOptimizable()
+ */
+ public boolean isOptimizable() {
+ return false;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.wire.Interceptor#setNext(org.apache.tuscany.spi.wire.Interceptor)
+ */
+ public void setNext(Interceptor next) {
+ this.next = next;
+ }
+
+ /**
+ * @param mediator the mediator to set
+ */
+ public void setMediator(Mediator mediator) {
+ this.mediator = mediator;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataBindingWirePostProcessor.java b/tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataBindingWirePostProcessor.java
new file mode 100644
index 0000000000..df3e17d2fc
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataBindingWirePostProcessor.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.core.databinding.wire;
+
+import java.util.Map;
+
+import org.apache.tuscany.spi.component.ComponentManager;
+import org.apache.tuscany.spi.databinding.Mediator;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+import org.apache.tuscany.spi.wire.WirePostProcessorExtension;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * 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 DataBindingWirePostProcessor extends WirePostProcessorExtension {
+ private Mediator mediator;
+ private ComponentManager componentManager;
+
+ @Constructor({"componentManager", "mediator"})
+ public DataBindingWirePostProcessor(@Reference ComponentManager componentManager,
+ @Reference Mediator mediator) {
+ super();
+ this.componentManager = componentManager;
+ this.mediator = mediator;
+ }
+
+ public void process(Wire wire) {
+ ServiceContract<?> sourceContract = wire.getSourceContract();
+ ServiceContract<?> targetContract = wire.getTargetContract();
+ if (targetContract == null) {
+ targetContract = sourceContract;
+ }
+ if (sourceContract == targetContract) {
+ return;
+ }
+ Map<Operation<?>, InvocationChain> chains = wire.getInvocationChains();
+ for (Map.Entry<Operation<?>, InvocationChain> entry : chains.entrySet()) {
+ String opName = entry.getKey().getName();
+ Operation<?> sourceOperation = sourceContract.getOperation(opName);
+ Operation<?> targetOperation = targetContract.getOperation(opName);
+ String sourceDataBinding = sourceOperation.getDataBinding();
+ String targetDataBinding = targetOperation.getDataBinding();
+ if (sourceDataBinding == null && targetDataBinding == null) {
+ continue;
+ }
+ if (sourceDataBinding == null || targetDataBinding == null
+ || !sourceDataBinding.equals(targetDataBinding)) {
+ // Add the interceptor to the source side because multiple
+ // references can be wired
+ // to the same service
+ DataBindingInteceptor interceptor =
+ new DataBindingInteceptor(componentManager, wire, sourceOperation, targetOperation);
+ interceptor.setMediator(mediator);
+ entry.getValue().addInterceptor(0, interceptor);
+ }
+ }
+
+ // Object targetAddress = UriHelper.getBaseName(source.getUri());
+ Map<Operation<?>, InvocationChain> callbackChains = wire.getCallbackInvocationChains();
+ if (callbackChains == null) {
+ // callback chains could be null
+ return;
+ }
+
+ for (Map.Entry<Operation<?>, InvocationChain> entry : callbackChains.entrySet()) {
+ String opName = entry.getKey().getName();
+ Operation<?> sourceOperation = sourceContract.getCallbackOperations().get(opName);
+ Operation<?> targetOperation = targetContract.getCallbackOperations().get(opName);
+ String sourceDataBinding = sourceOperation.getDataBinding();
+ String targetDataBinding = targetOperation.getDataBinding();
+ if (sourceDataBinding == null && targetDataBinding == null) {
+ continue;
+ }
+ if (sourceDataBinding == null || targetDataBinding == null || !sourceDataBinding.equals(targetDataBinding)) {
+ // Add the interceptor to the source side because multiple
+ // references can be wired
+ // to the same service
+ DataBindingInteceptor interceptor =
+ new DataBindingInteceptor(componentManager, wire, sourceOperation, targetOperation);
+ interceptor.setMediator(mediator);
+ entry.getValue().addInterceptor(0, interceptor);
+ }
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/databinding/src/main/resources/org/apache/tuscany/core/databinding.scdl b/tags/java/tsss-demo/kernel/databinding/src/main/resources/org/apache/tuscany/core/databinding.scdl
new file mode 100644
index 0000000000..b5b12fd75a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/databinding/src/main/resources/org/apache/tuscany/core/databinding.scdl
@@ -0,0 +1,185 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ name="org.apache.tuscany.core.DataBinding" autowire="true">
+
+ <component name="databinding.wirePostProcessor" initLevel="50">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.wire.DataBindingWirePostProcessor" />
+ </component>
+
+ <component name="databinding.javaInterfaceProcessor">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.processor.DataBindingJavaInterfaceProcessor" />
+ </component>
+
+ <!-- [rfeng] HACK: Make sure the passByValue interceptor is added before the databinding interceptor -->
+ <!--
+ <component name="databinding.passByValueWirePostProcessor" initLevel="80">
+ <system:implementation.system class="org.apache.tuscany.databinding.impl.PassByValueWirePostProcessor" />
+ </component>
+ -->
+
+ <!-- DataBinding registry -->
+ <component name="databinding.registry">
+ <system:implementation.system class="org.apache.tuscany.databinding.impl.DataBindingRegistryImpl" />
+ </component>
+
+ <!-- DataBinding registry -->
+ <component name="databinding.mediator">
+ <system:implementation.system class="org.apache.tuscany.databinding.impl.MediatorImpl" />
+ </component>
+
+ <!-- Transformer registry -->
+ <component name="databinding.transformerRegistry" initLevel="90">
+ <system:implementation.system class="org.apache.tuscany.databinding.impl.TransformerRegistryImpl" />
+ </component>
+
+ <component name="dataType.loader">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.loader.DataTypeLoader" />
+ </component>
+
+ <component name="databinding.dom">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.DOMDataBinding" />
+ </component>
+
+ <component name="databinding.xmlString">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.XMLStringDataBinding" />
+ </component>
+
+ <!-- Group databindings -->
+ <component name="databinding.group.xml">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.XMLGroupDataBinding" />
+ </component>
+
+ <!-- Comment out the stax databinding as it's covered in the databinding.group.xml -->
+ <!--
+ <component name="databinding.stax">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.StAXDataBinding" />
+ </component>
+ -->
+ <component name="databinding.javabeans">
+ <system:implementation.system class="org.apache.tuscany.databinding.javabeans.JavaBeansDataBinding" />
+ </component>
+
+ <!-- Transformers -->
+
+ <component name="transformer.Input2InputTransformer">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.transformers.Input2InputTransformer" />
+ </component>
+
+ <component name="transformer.Exception2ExceptionTransformer">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.transformers.Exception2ExceptionTransformer" />
+ </component>
+
+ <component name="transformer.Output2OutputTransformer">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.transformers.Output2OutputTransformer" />
+ </component>
+
+ <component name="transformer.Group2GroupTransformer">
+ <system:implementation.system class="org.apache.tuscany.databinding.impl.Group2GroupTransformer" />
+ </component>
+
+ <component name="transformer.InputSource2Node">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.InputSource2Node" />
+ </component>
+
+ <component name="transformer.InputSource2SAX">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.InputSource2SAX" />
+ </component>
+
+ <component name="transformer.InputStream2Node">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.InputStream2Node" />
+ </component>
+
+ <component name="transformer.InputStream2SAX">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.InputStream2SAX" />
+ </component>
+
+ <component name="transformer.DOMNode2JavaBean">
+ <system:implementation.system class="org.apache.tuscany.databinding.javabeans.DOMNode2JavaBeanTransformer" />
+ </component>
+
+ <component name="transformer.Node2OutputStream">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.Node2OutputStream" />
+ </component>
+
+ <component name="transformer.Node2String">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.Node2String" />
+ </component>
+
+ <component name="transformer.Node2Writer">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.Node2Writer" />
+ </component>
+
+ <component name="transformer.Node2XMLStreamReader">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.Node2XMLStreamReader" />
+ </component>
+
+ <component name="transformer.JavaBean2DOMNode">
+ <system:implementation.system class="org.apache.tuscany.databinding.javabeans.JavaBean2DOMNodeTransformer" />
+ </component>
+
+ <component name="transformer.Reader2Node">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.Reader2Node" />
+ </component>
+
+ <component name="transformer.Reader2SAX">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.Reader2SAX" />
+ </component>
+
+ <component name="transformer.SAX2DOMPipe">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.SAX2DOMPipe" />
+ </component>
+
+ <component name="transformer.Source2ResultTransformer">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.Source2ResultTransformer" />
+ </component>
+
+ <component name="transformer.StreamDataPipe">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.StreamDataPipe" />
+ </component>
+
+ <component name="transformer.String2Node">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.String2Node" />
+ </component>
+
+ <component name="transformer.String2SAX">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.String2SAX" />
+ </component>
+
+ <component name="transformer.String2XMLStreamReader">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.String2XMLStreamReader" />
+ </component>
+
+ <component name="transformer.Writer2ReaderDataPipe">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.Writer2ReaderDataPipe" />
+ </component>
+
+ <component name="transformer.XMLStreamReader2Node">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.XMLStreamReader2Node" />
+ </component>
+
+ <component name="transformer.XMLStreamReader2SAX">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.XMLStreamReader2SAX" />
+ </component>
+
+ <component name="transformer.XMLStreamReader2String">
+ <system:implementation.system class="org.apache.tuscany.databinding.xml.XMLStreamReader2String" />
+ </component>
+</composite> \ No newline at end of file
diff --git a/tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/loader/DataBindingLoaderTestCase.java b/tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/loader/DataBindingLoaderTestCase.java
new file mode 100644
index 0000000000..ccc06c3d9b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/loader/DataBindingLoaderTestCase.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.core.databinding.loader;
+
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.databinding.loader.DataTypeLoader;
+import org.apache.tuscany.spi.loader.InvalidValueException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.easymock.EasyMock;
+
+/**
+ * Testcase for DataBindingLoader
+ */
+public class DataBindingLoaderTestCase extends TestCase {
+ private XMLStreamReader reader;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public final void testLoad() throws LoaderException, XMLStreamException {
+ reader = EasyMock.createMock(XMLStreamReader.class);
+ // EasyMock.expect(reader.getEventType()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.hasNext()).andReturn(true).anyTimes();
+ EasyMock.expect(reader.getName()).andReturn(DataTypeLoader.DATA_BINDING);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn("ABC");
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(reader);
+
+ ModelObject mo = new DataTypeLoader(null).load(null, reader, null);
+ Assert.assertTrue(mo instanceof DataType);
+ Assert.assertEquals("ABC", ((DataType<?>)mo).getDataBinding());
+ EasyMock.verify(reader);
+
+ EasyMock.reset(reader);
+
+ // EasyMock.expect(reader.getEventType()).andReturn(XMLStreamConstants.START_ELEMENT);
+ EasyMock.expect(reader.hasNext()).andReturn(true).anyTimes();
+ EasyMock.expect(reader.getName()).andReturn(DataTypeLoader.DATA_BINDING);
+ EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn(null);
+ EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+ EasyMock.replay(reader);
+ try {
+ mo = new DataTypeLoader(null).load(null, reader, null);
+ Assert.fail("InvalidValueException should have been thrown");
+ } catch (InvalidValueException e) {
+ Assert.assertTrue(true);
+ }
+ EasyMock.verify(reader);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java b/tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java
new file mode 100644
index 0000000000..5c3a9c6e07
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.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.core.databinding.processor;
+
+import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION;
+
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.api.annotation.DataType;
+import org.apache.tuscany.core.databinding.processor.DataBindingJavaInterfaceProcessor;
+import org.apache.tuscany.databinding.impl.DataBindingRegistryImpl;
+import org.apache.tuscany.spi.databinding.DataBindingRegistry;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+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 InvalidServiceContractException {
+ DataBindingRegistry registry = new DataBindingRegistryImpl();
+ DataBindingJavaInterfaceProcessor processor = new DataBindingJavaInterfaceProcessor(registry);
+ JavaServiceContract<?> contract = new JavaServiceContract(MockInterface.class);
+ Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>();
+ Operation<Type> operation = new Operation<Type>("call", null, null, null, false, null, NO_CONVERSATION);
+ Operation<Type> operation1 = new Operation<Type>("call1", null, null, null, false, null, NO_CONVERSATION);
+ operations.put("call", operation);
+ operations.put("call1", operation1);
+ contract.setOperations(operations);
+ contract.setRemotable(true);
+ processor.visitInterface(MockInterface.class, null, 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());
+ }
+
+ @DataType(name = "org.w3c.dom.Node")
+ @Remotable
+ public static interface MockInterface {
+ Node call(Node msg);
+
+ @DataType(name = "xml:string")
+ String call1(String msg);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/transformers/IDLTransformerTestCase.java b/tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/transformers/IDLTransformerTestCase.java
new file mode 100644
index 0000000000..ef233065ba
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/transformers/IDLTransformerTestCase.java
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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.core.databinding.transformers.Input2InputTransformer;
+import org.apache.tuscany.core.databinding.transformers.Output2OutputTransformer;
+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.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.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.ElementInfo;
+import org.apache.tuscany.spi.model.TypeInfo;
+import org.apache.tuscany.spi.model.WrapperInfo;
+import org.apache.tuscany.spi.model.XMLType;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class IDLTransformerTestCase extends TestCase {
+ private static final String IPO_XML =
+ "<?xml version=\"1.0\"?>" + "<order1"
+ + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ + " xmlns:ipo=\"http://www.example.com/IPO\""
+ + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\""
+ + " orderDate=\"1999-12-01\">"
+ + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">"
+ + " <name>Helen Zoe</name>"
+ + " <street>47 Eden Street</street>"
+ + " <city>Cambridge</city>"
+ + " <postcode>CB1 1JR</postcode>"
+ + " </shipTo>"
+ + " <billTo xsi:type=\"ipo:USAddress\">"
+ + " <name>Robert Smith</name>"
+ + " <street>8 Oak Avenue</street>"
+ + " <city>Old Town</city>"
+ + " <state>PA</state>"
+ + " <zip>95819</zip>"
+ + " </billTo>"
+ + " <items>"
+ + " <item partNum=\"833-AA\">"
+ + " <productName>Lapis necklace</productName>"
+ + " <quantity>1</quantity>"
+ + " <USPrice>99.95</USPrice>"
+ + " <ipo:comment>Want this for the holidays</ipo:comment>"
+ + " <shipDate>1999-12-05</shipDate>"
+ + " </item>"
+ + " </items>"
+ + "</order1>";
+
+ 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<DataType<XMLType>> types0 = new ArrayList<DataType<XMLType>>();
+ DataType<XMLType> wrapperType =
+ new DataType<XMLType>(null, Object.class, new XMLType(new QName(URI_ORDER_XSD, "checkOrderStatus"), null));
+ types0.add(wrapperType);
+ DataType<List<DataType<XMLType>>> inputType0 =
+ new DataType<List<DataType<XMLType>>>(IDL_INPUT, Object[].class, types0);
+
+ List<DataType<XMLType>> types1 = new ArrayList<DataType<XMLType>>();
+ DataType<XMLType> customerIdType =
+ new DataType<XMLType>(null, Object.class, new XMLType(new QName(URI_ORDER_XSD, "customerId"), null));
+ DataType<XMLType> orderType =
+ new DataType<XMLType>(null, Object.class, new XMLType(new QName(URI_ORDER_XSD, "order"), null));
+ DataType<XMLType> flagType =
+ new DataType<XMLType>(null, Object.class, new XMLType(new QName(URI_ORDER_XSD, "flag"), null));
+ types1.add(customerIdType);
+ types1.add(orderType);
+ types1.add(flagType);
+
+ DataType<XMLType> statusType =
+ new DataType<XMLType>(null, Object.class, new XMLType(new QName(URI_ORDER_XSD, "status"), null));
+ DataType<XMLType> responseType =
+ new DataType<XMLType>(null, Object.class, new XMLType(new QName(URI_ORDER_XSD, "checkOrderStatusResponse"),
+ null));
+
+ org.apache.tuscany.spi.model.Operation<XMLType> op =
+ new org.apache.tuscany.spi.model.Operation<XMLType>("checkOrderStatus", inputType0, responseType, null);
+ 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<ElementInfo> inputElements = new ArrayList<ElementInfo>();
+ 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<ElementInfo> outputElements = new ArrayList<ElementInfo>();
+ 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();
+ List<DataType<Class>> types = new ArrayList<DataType<Class>>();
+ types.add(new DataType<Class>(Object.class.getName(), String.class, String.class));
+ types.add(new DataType<Class>("java.lang.String", String.class, String.class));
+ types.add(new DataType<Class>(Object.class.getName(), int.class, int.class));
+ DataType<List<DataType<Class>>> inputType1 =
+ new DataType<List<DataType<Class>>>(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<DataType> sourceType = new DataType<DataType>(IDL_OUTPUT, Object.class, op.getOutputType());
+ sourceType.setOperation(op.getOutputType().getOperation());
+
+ context1.setSourceDataType(sourceType);
+ DataType<DataType> targetType =
+ new DataType<DataType>(IDL_OUTPUT, Object.class, new DataType<Class>("java.lang.Object", String.class,
+ String.class));
+ context1.setTargetDataType(targetType);
+
+ Document factory = DOMHelper.newDocument();
+ Element responseElement =
+ factory.createElementNS("http://example.com/order.wsdl", "p:checkOrderStatusResponse");
+ Element status = factory.createElement("status");
+ responseElement.appendChild(status);
+ status.appendChild(factory.createTextNode("shipped"));
+ Output2OutputTransformer t2 = new Output2OutputTransformer();
+ t2.setMediator(m);
+ Object st = t2.transform(responseElement, context1);
+ assertEquals("shipped", st);
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/wire/DataBindingInterceptorTestCase.java b/tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/wire/DataBindingInterceptorTestCase.java
new file mode 100644
index 0000000000..92cb1427c6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/wire/DataBindingInterceptorTestCase.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.core.databinding.wire;
+
+import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.databinding.wire.DataBindingInteceptor;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ComponentManager;
+import org.apache.tuscany.spi.databinding.DataBinding;
+import org.apache.tuscany.spi.databinding.Mediator;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.Wire;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DataBindingInterceptorTestCase extends TestCase {
+
+ @SuppressWarnings("unchecked")
+ public final void testInvoke() {
+ DataType<Class> type1 = new DataType<Class>("xml:string", String.class, String.class);
+ List<DataType<Class>> types1 = new ArrayList<DataType<Class>>();
+ types1.add(type1);
+ DataType<List<DataType<Class>>> inputType1 =
+ new DataType<List<DataType<Class>>>("xml:string", Object[].class, types1);
+
+ DataType<Class> type2 = new DataType<Class>("foo", Foo.class, Foo.class);
+ List<DataType<Class>> types2 = new ArrayList<DataType<Class>>();
+ types2.add(type2);
+ DataType<List<DataType<Class>>> inputType2 = new DataType<List<DataType<Class>>>("foo", Object[].class, types2);
+
+ Operation<Class> operation1 =
+ new Operation<Class>("call", inputType1, type1, null, false, "xml:string", NO_CONVERSATION);
+ Operation<Class> operation2 =
+ new Operation<Class>("call", inputType2, type2, null, false, "org.w3c.dom.Node", NO_CONVERSATION);
+
+ DataType<DataType> outputType1 =
+ new DataType<DataType>(DataBinding.IDL_OUTPUT, Object.class, operation1.getOutputType());
+ DataType<DataType> outputType2 =
+ new DataType<DataType>(DataBinding.IDL_OUTPUT, Object.class, operation2.getOutputType());
+
+ Component component = EasyMock.createMock(Component.class);
+ ComponentManager componentManager = createMock(ComponentManager.class);
+ expect(componentManager.getComponent(EasyMock.isA(URI.class))).andReturn(component).anyTimes();
+ Wire wire = EasyMock.createMock(Wire.class);
+ expect(wire.getSourceUri()).andReturn(URI.create("/componentA/ref1"));
+ expect(wire.getTargetUri()).andReturn(URI.create("/componentB/svc1"));
+ EasyMock.replay(wire, componentManager, component);
+
+ DataBindingInteceptor interceptor = new DataBindingInteceptor(componentManager, wire, operation1, operation2);
+ Mediator mediator = createMock(Mediator.class);
+ Object[] source = new Object[] {"<foo>bar</foo>"};
+ Foo foo = new Foo();
+ foo.bar = "bar";
+ Object[] target = new Object[] {foo};
+ expect(mediator.mediate(EasyMock.same(source), EasyMock.same(inputType1), EasyMock.same(inputType2), EasyMock
+ .isA(Map.class))).andReturn(target);
+ // expect(mediator.mediate(target[0], type2,
+ // type1)).andReturn(source[0]);
+ expect(mediator.mediate(EasyMock.same(target[0]), EasyMock.eq(outputType2), EasyMock.eq(outputType1), EasyMock
+ .isA(Map.class))).andReturn(source[0]);
+ replay(mediator);
+ interceptor.setMediator(mediator);
+ Message msg = createMock(Message.class);
+ msg.setBody(EasyMock.anyObject());
+ expectLastCall().anyTimes();
+ expect(msg.getBody()).andReturn(source).once().andReturn(target[0]).once().andReturn(source[0]);
+ expect(msg.isFault()).andReturn(false).once();
+ replay(msg);
+ Interceptor next = createMock(Interceptor.class);
+ expect(next.invoke(msg)).andReturn(msg);
+ replay(next);
+ interceptor.setNext(next);
+ interceptor.invoke(msg);
+ String result = (String)msg.getBody();
+ Assert.assertEquals(source[0], result);
+ EasyMock.verify(mediator, msg, next);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ private static class Foo {
+ private String bar;
+
+ public String getBar() {
+ return bar;
+ }
+
+ public void setBar(String bar) {
+ this.bar = bar;
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/wire/DataBindingWirePostProcessorOptimizationTestCase.java b/tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/wire/DataBindingWirePostProcessorOptimizationTestCase.java
new file mode 100644
index 0000000000..d4a89382db
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/wire/DataBindingWirePostProcessorOptimizationTestCase.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.core.databinding.wire;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.databinding.wire.DataBindingWirePostProcessor;
+import org.apache.tuscany.databinding.impl.MediatorImpl;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ComponentManager;
+import org.apache.tuscany.spi.databinding.Mediator;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.util.UriHelper;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+import org.easymock.EasyMock;
+
+/**
+ * Verifies that data binding interceptor is not added to invocation chains when the data binding types are not set on
+ * service contracts
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataBindingWirePostProcessorOptimizationTestCase extends TestCase {
+ private DataBindingWirePostProcessor processor;
+ private InvocationChain chain;
+ private Wire wire;
+
+ public void testNoInterceptorInterposedOutboundToInbound() {
+ processor.process(wire);
+ EasyMock.verify(chain);
+ EasyMock.verify(wire);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ URI sourceUri = URI.create("/componentA/#ref1");
+ URI targetUri = URI.create("/componentB/#svc1");
+
+ // FIXME: [rfeng] We should use Mocks here
+ Mediator mediator = new MediatorImpl();
+ ComponentManager componentManager = createMock(ComponentManager.class);
+ Component component = createMock(Component.class);
+ expect(componentManager.getComponent(UriHelper.getDefragmentedName(sourceUri))).andReturn(component);
+ expect(componentManager.getComponent(UriHelper.getDefragmentedName(targetUri))).andReturn(component);
+
+ replay(component, componentManager);
+ processor = new DataBindingWirePostProcessor(componentManager, mediator);
+
+ ServiceContract<Type> contract = new JavaServiceContract(null);
+ Operation<Type> operation = new Operation<Type>("test", null, null, null);
+ operation.setServiceContract(contract);
+ Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>();
+ operations.put("test", operation);
+ contract.setOperations(operations);
+ contract.setCallbackOperations(operations);
+
+ chain = createMock(InvocationChain.class);
+ replay(chain);
+ Map<Operation<?>, InvocationChain> chains = new HashMap<Operation<?>, InvocationChain>();
+ chains.put(operation, chain);
+
+ wire = EasyMock.createMock(Wire.class);
+ expect(wire.getBindingType()).andReturn(Wire.LOCAL_BINDING).anyTimes();
+ expect(wire.getSourceContract()).andReturn(contract).anyTimes();
+ expect(wire.getTargetContract()).andReturn(contract).anyTimes();
+ expect(wire.getInvocationChains()).andReturn(chains).anyTimes();
+ expect(wire.getSourceUri()).andReturn(sourceUri).anyTimes();
+ expect(wire.getTargetUri()).andReturn(targetUri).anyTimes();
+ expect(wire.getCallbackInvocationChains()).andReturn(chains).anyTimes();
+ replay(wire);
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/wire/DataBindingWirePostProcessorTestCase.java b/tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/wire/DataBindingWirePostProcessorTestCase.java
new file mode 100644
index 0000000000..fcc877805e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/databinding/src/test/java/org/apache/tuscany/core/databinding/wire/DataBindingWirePostProcessorTestCase.java
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 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 static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.databinding.processor.JavaInterfaceIntrospector;
+import org.apache.tuscany.core.databinding.wire.DataBindingWirePostProcessor;
+import org.apache.tuscany.databinding.xml.DOMDataBinding;
+import org.apache.tuscany.databinding.xml.StAXDataBinding;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ComponentManager;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.databinding.Mediator;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.util.UriHelper;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Wire;
+import org.easymock.EasyMock;
+import org.osoa.sca.Constants;
+import org.osoa.sca.annotations.Remotable;
+import org.w3c.dom.Node;
+
+import com.ibm.rmi.corba.IsA;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DataBindingWirePostProcessorTestCase extends TestCase {
+ private static final QName BINDING_WS = new QName(Constants.SCA_NS, "binding.ws");
+ private DataBindingWirePostProcessor processor;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /**
+ * Component.Reference --> Component.Service
+ */
+ public void testProcess1() throws Exception {
+ URI sourceUri = URI.create("/composite1/component1/#reference1");
+ URI targetUri = URI.create("/composite1/component2/#service1");
+
+ Mediator mediator = createMock(Mediator.class);
+ ComponentManager componentManager = createMock(ComponentManager.class);
+ Component component1 = createMock(Component.class);
+ // expect(component1.getReference("reference1")).andReturn(null);
+ Component component2 = createMock(Component.class);
+ // expect(component2.getService("service1")).andReturn(null);
+ expect(componentManager.getComponent(UriHelper.getDefragmentedName(sourceUri))).andReturn(component1).anyTimes();
+ expect(componentManager.getComponent(UriHelper.getDefragmentedName(targetUri))).andReturn(component2).anyTimes();
+ replay(mediator, componentManager, component1, component2);
+ DataBindingWirePostProcessor processor = new DataBindingWirePostProcessor(componentManager, mediator);
+
+ Wire wire = createWire(sourceUri, targetUri, Wire.LOCAL_BINDING);
+ processor.process(wire);
+
+ verify(mediator, componentManager, component1, component2);
+ }
+
+ /**
+ * Component.Reference --> Composite.Reference
+ */
+ public void testProcess2() throws Exception {
+ ReferenceBinding referenceBinding = createMock(ReferenceBinding.class);
+ Component composite = createMock(Component.class);
+ expect(referenceBinding.getUri()).andReturn(URI.create("/compositeA/#ref1"));
+
+ URI sourceUri = URI.create("/composite1/component1/#reference1");
+ URI targetUri = URI.create("/composite1/#reference1");
+ Mediator mediator = createMock(Mediator.class);
+ ComponentManager componentManager = createMock(ComponentManager.class);
+ Component component1 = createMock(Component.class);
+ expect(component1.getReference("reference1")).andReturn(null);
+ Component component2 = createMock(Component.class);
+ expect(component2.getReference("reference1")).andReturn(null);
+ expect(componentManager.getComponent(UriHelper.getDefragmentedName(sourceUri))).andReturn(component1).anyTimes();
+ expect(componentManager.getComponent(UriHelper.getDefragmentedName(targetUri))).andReturn(component2).anyTimes();
+ replay(mediator, componentManager, component1, component2);
+ DataBindingWirePostProcessor processor = new DataBindingWirePostProcessor(componentManager, mediator);
+
+ Wire wire = createWire(sourceUri, targetUri, BINDING_WS);
+ processor.process(wire);
+ }
+
+ /**
+ * Composite.Service --> Component Service
+ */
+ public void testProcess3() throws Exception {
+ URI sourceUri = URI.create("/composite1/#service1");
+ URI targetUri = URI.create("/composite1/component1/#service1");
+
+ Mediator mediator = createMock(Mediator.class);
+ ComponentManager componentManager = createMock(ComponentManager.class);
+ Component component1 = createMock(Component.class);
+ expect(component1.getService("service1")).andReturn(null);
+ Component component2 = createMock(Component.class);
+ expect(component2.getService("service1")).andReturn(null);
+ expect(componentManager.getComponent(UriHelper.getDefragmentedName(sourceUri))).andReturn(component1).anyTimes();
+ expect(componentManager.getComponent(UriHelper.getDefragmentedName(targetUri))).andReturn(component2).anyTimes();
+ replay(mediator, componentManager, component1, component2);
+ DataBindingWirePostProcessor processor = new DataBindingWirePostProcessor(componentManager, mediator);
+
+ Wire wire = createWire(sourceUri, targetUri, BINDING_WS);
+ processor.process(wire);
+ }
+
+ private Wire createWire(URI sourceUri, URI targetUri, QName bindingType) throws InvalidServiceContractException {
+ ServiceContract<?> contract1 = new JavaInterfaceIntrospector().introspect(TestInterface1.class);
+ contract1.setDataBinding(DOMDataBinding.NAME);
+ ServiceContract<?> contract2 = new JavaInterfaceIntrospector().introspect(TestInterface2.class);
+ contract2.setDataBinding(StAXDataBinding.NAME);
+ Map<Operation<?>, InvocationChain> chains = new HashMap<Operation<?>, InvocationChain>();
+ for (Operation<?> op : contract1.getOperations().values()) {
+ InvocationChain chain = createMock(InvocationChain.class);
+ chain.addInterceptor(EasyMock.anyInt(), EasyMock.isA(Interceptor.class));
+ replay(chain);
+ chains.put(op, chain);
+ }
+ Map<Operation<?>, InvocationChain> callbackChains = new HashMap<Operation<?>, InvocationChain>();
+ for (Operation<?> op : contract1.getCallbackOperations().values()) {
+ InvocationChain chain = createMock(InvocationChain.class);
+ chain.addInterceptor(EasyMock.anyInt(), EasyMock.isA(Interceptor.class));
+ replay(chain);
+ callbackChains.put(op, chain);
+ }
+ Wire wire = EasyMock.createMock(Wire.class);
+ expect(wire.getBindingType()).andReturn(bindingType).anyTimes();
+ expect(wire.getSourceContract()).andReturn(contract1).anyTimes();
+ expect(wire.getTargetContract()).andReturn(contract2).anyTimes();
+ expect(wire.getInvocationChains()).andReturn(chains);
+ expect(wire.getSourceUri()).andReturn(sourceUri).anyTimes();
+ expect(wire.getTargetUri()).andReturn(targetUri).anyTimes();
+ expect(wire.getCallbackInvocationChains()).andReturn(callbackChains).anyTimes();
+ replay(wire);
+ return wire;
+ }
+
+ @Remotable
+ private static interface TestInterface1 {
+ String test1(String str);
+
+ Node test2(Node node);
+
+ void test3(int i, String s) throws MyException;
+ }
+
+ @Remotable
+ private static interface TestInterface2 {
+ String test1(String str);
+
+ XMLStreamReader test2(XMLStreamReader reader);
+
+ void test3(int i, String s) throws MyException;
+ }
+
+ private static class MyException extends Exception {
+ private static final long serialVersionUID = 7203411584939696390L;
+
+ public MyException() {
+ super();
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public MyException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * @param message
+ */
+ public MyException(String message) {
+ super(message);
+ }
+
+ /**
+ * @param cause
+ */
+ public MyException(Throwable cause) {
+ super(cause);
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/host-api/.checkstyle b/tags/java/tsss-demo/kernel/host-api/.checkstyle
new file mode 100644
index 0000000000..3e57539570
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/.checkstyle
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<fileset-config file-format-version="1.2.0" simple-config="true">
+ <fileset name="all" enabled="true" check-config-name="Tuscany Checks" local="false">
+ <file-match-pattern match-pattern="." include-pattern="true"/>
+ </fileset>
+</fileset-config>
diff --git a/tags/java/tsss-demo/kernel/host-api/.pmd b/tags/java/tsss-demo/kernel/host-api/.pmd
new file mode 100644
index 0000000000..ffc4fe2bbb
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/.pmd
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<pmd><useProjectRuleSet>true</useProjectRuleSet><rules/></pmd>
diff --git a/tags/java/tsss-demo/kernel/host-api/.ruleset b/tags/java/tsss-demo/kernel/host-api/.ruleset
new file mode 100644
index 0000000000..3886f07f2d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/.ruleset
@@ -0,0 +1,190 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<ruleset name="pmd-eclipse">
+ <description>PMD Plugin preferences rule set</description>
+
+
+ <rule ref="rulesets/basic.xml/BooleanInstantiation"/>
+ <rule ref="rulesets/basic.xml/CollapsibleIfStatements"/>
+ <rule ref="rulesets/basic.xml/DoubleCheckedLocking"/>
+<!--<rule ref="rulesets/basic.xml/EmptyCatchBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyFinallyBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyIfStmt"/>-->
+ <rule ref="rulesets/basic.xml/EmptyStatementNotInLoop"/>
+<!--<rule ref="rulesets/basic.xml/EmptyStaticInitializer"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptySwitchStatements"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptySynchronizedBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyTryBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyWhileStmt"/>-->
+ <rule ref="rulesets/basic.xml/ForLoopShouldBeWhileLoop"/>
+ <rule ref="rulesets/basic.xml/JumbledIncrementer"/>
+<!--<rule ref="rulesets/basic.xml/OverrideBothEqualsAndHashcode"/>-->
+ <rule ref="rulesets/basic.xml/ReturnFromFinallyBlock"/>
+ <rule ref="rulesets/basic.xml/UnconditionalIfStatement"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryConversionTemporary"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryFinalModifier"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryReturn"/>
+<!--<rule ref="rulesets/basic.xml/UselessOverridingMethod"/>-->
+
+<!--<rule ref="rulesets/braces.xml/ForLoopsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/IfElseStmtsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/IfStmtsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/WhileLoopsMustUseBraces"/>-->
+
+<!--<rule ref="rulesets/clone.xml/CloneMethodMustImplementCloneable"/>-->
+<!--<rule ref="rulesets/clone.xml/CloneThrowsCloneNotSupportedException"/>-->
+<!--<rule ref="rulesets/clone.xml/ProperCloneImplementation"/>-->
+
+<!--<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>-->
+<!--<rule ref="rulesets/codesize.xml/TooManyFields"/>-->
+
+<rule ref="rulesets/controversial.xml/AssignmentInOperand"/>
+<!--<rule ref="rulesets/controversial.xml/AtLeastOneConstructor"/>-->
+<!--<rule ref="rulesets/controversial.xml/CallSuperInConstructor"/>-->
+<!--<rule ref="rulesets/controversial.xml/DontImportSun"/>-->
+<!--<rule ref="rulesets/controversial.xml/NullAssignment"/>-->
+<!--<rule ref="rulesets/controversial.xml/OnlyOneReturn"/>-->
+<!--<rule ref="rulesets/controversial.xml/SingularField"/>-->
+<!--<rule ref="rulesets/controversial.xml/SuspiciousOctalEscape"/>-->
+<!--<rule ref="rulesets/controversial.xml/UnnecessaryConstructor"/>-->
+<rule ref="rulesets/controversial.xml/UnnecessaryParentheses"/>
+<!--<rule ref="rulesets/controversial.xml/UnusedModifier"/>-->
+
+<!--<rule ref="rulesets/coupling.xml/CouplingBetweenObjects"/>-->
+<!--<rule ref="rulesets/coupling.xml/ExcessiveImports"/>-->
+<!--<rule ref="rulesets/coupling.xml/LooseCoupling"/>-->
+
+<!--<rule ref="rulesets/design.xml/AbstractClassWithoutAbstractMethod"/>-->
+<!--<rule ref="rulesets/design.xml/AccessorClassGeneration"/>-->
+<!--<rule ref="rulesets/design.xml/AssignmentToNonFinalStatic"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidDeeplyNestedIfStmts"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidInstanceofChecksInCatchClause"/>-->
+<rule ref="rulesets/design.xml/AvoidProtectedFieldInFinalClass"/>
+<!--<rule ref="rulesets/design.xml/AvoidReassigningParameters"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidSynchronizedAtMethodLevel"/>-->
+<!--<rule ref="rulesets/design.xml/BadComparison"/>-->
+<!--<rule ref="rulesets/design.xml/CloseConnection"/>-->
+<!--<rule ref="rulesets/design.xml/CompareObjectsWithEquals"/>-->
+<!--<rule ref="rulesets/design.xml/ConfusingTernary"/>-->
+<rule ref="rulesets/design.xml/ConstructorCallsOverridableMethod"/>
+<!--<rule ref="rulesets/design.xml/DefaultLabelNotLastInSwitchStmt"/>-->
+<!--<rule ref="rulesets/design.xml/FinalFieldCouldBeStatic"/>-->
+<rule ref="rulesets/design.xml/IdempotentOperations"/>
+<!--<rule ref="rulesets/design.xml/ImmutableField"/>-->
+<!--<rule ref="rulesets/design.xml/InstantiationToGetClass"/>-->
+<!--<rule ref="rulesets/design.xml/MissingBreakInSwitch"/>-->
+<!--<rule ref="rulesets/design.xml/MissingStaticMethodInNonInstantiatableClass"/>-->
+<!--<rule ref="rulesets/design.xml/NonCaseLabelInSwitchStatement"/>-->
+<!--<rule ref="rulesets/design.xml/NonStaticInitializer"/>-->
+<rule ref="rulesets/design.xml/OptimizableToArrayCall"/>
+<rule ref="rulesets/design.xml/PositionLiteralsFirstInComparisons"/>
+<rule ref="rulesets/design.xml/SimplifyBooleanExpressions"/>
+<rule ref="rulesets/design.xml/SimplifyBooleanReturns"/>
+<rule ref="rulesets/design.xml/SimplifyConditional"/>
+<!--<rule ref="rulesets/design.xml/SwitchDensity"/>-->
+<!--<rule ref="rulesets/design.xml/SwitchStmtsShouldHaveDefault"/>-->
+<rule ref="rulesets/design.xml/UnnecessaryLocalBeforeReturn"/>
+<!--<rule ref="rulesets/design.xml/UseLocaleWithCaseConversions"/>-->
+<!--<rule ref="rulesets/design.xml/UseNotifyAllInsteadOfNotify"/>-->
+<!--<rule ref="rulesets/design.xml/UseSingleton"/>-->
+
+<!--<rule ref="rulesets/finalizers.xml/EmptyFinalizer"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeOnlyCallsSuperFinalize"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeOverloaded"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeDoesNotCallSuperFinalize"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeShouldBeProtected"/>-->
+<!--<rule ref="rulesets/finalizers.xml/AvoidCallingFinalize"/>-->
+
+<!--<rule ref="rulesets/imports.xml/DuplicateImports"/>-->
+<!--<rule ref="rulesets/imports.xml/DontImportJavaLang"/>-->
+<!--<rule ref="rulesets/imports.xml/UnusedImports"/>-->
+<!--<rule ref="rulesets/imports.xml/ImportFromSamePackage"/>-->
+
+<!--<rule ref="rulesets/javabeans.xml/BeanMembersShouldSerialize"/>-->
+<!--<rule ref="rulesets/javabeans.xml/MissingSerialVersionUID"/>-->
+
+<!--<rule ref="rulesets/junit.xml/JUnitStaticSuite"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitSpelling"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitAssertionsShouldIncludeMessage"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitTestsShouldIncludeAssert"/>-->
+<!--<rule ref="rulesets/junit.xml/TestClassWithoutTestCases"/>-->
+<!--<rule ref="rulesets/junit.xml/UnnecessaryBooleanAssertion"/>-->
+<!--<rule ref="rulesets/junit.xml/UseAssertEqualsInsteadOfAssertTrue"/>-->
+<!--<rule ref="rulesets/junit.xml/UseAssertSameInsteadOfAssertTrue"/>-->
+
+ <!--<rule ref="rulesets/logging-java.xml/AvoidPrintStackTrace"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/MoreThanOneLogger"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LogBlockWithoutIf"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/SystemPrintln"/>-->
+ <!--<rule ref="rulesets/logging-jakarta-commons.xml/UseCorrectExceptionLogging"/>-->
+ <!--<rule ref="rulesets/logging-jakarta-commons.xml/ProperLogger"/>-->
+
+ <!--<rule ref="rulesets/naming.xml/ShortVariable"/>-->
+ <!--<rule ref="rulesets/naming.xml/LongVariable"/>-->
+ <!--<rule ref="rulesets/naming.xml/ShortMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/VariableNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/MethodNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/ClassNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/AbstractNaming"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidDollarSigns"/>-->
+ <!--<rule ref="rulesets/naming.xml/MethodWithSameNameAsEnclosingClass"/>-->
+ <!--<rule ref="rulesets/naming.xml/SuspiciousHashcodeMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/SuspiciousConstantFieldName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingTypeName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidNonConstructorMethodsWithClassName"/>-->
+ <!--<rule ref="rulesets/naming.xml/NoPackage"/>-->
+ <!--<rule ref="rulesets/naming.xml/PackageCase"/>-->
+
+ <!--<rule ref="rulesets/optimizations.xml/LocalVariableCouldBeFinal"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/MethodArgumentCouldBeFinal"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/AvoidInstantiatingObjectsInLoops"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/UseArrayListInsteadOfVector"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/SimplifyStartsWith"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/UseStringBufferForStringAppends"/>-->
+
+ <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingThrowable"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/SignatureDeclareThrowsException"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/ExceptionAsFlowControl"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingNPE"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingRawExceptionTypes"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingNullPointerException"/>-->
+
+ <!--<rule ref="rulesets/strings.xml/AvoidDuplicateLiterals"/>-->
+ <!--<rule ref="rulesets/strings.xml/StringInstantiation"/>-->
+ <!--<rule ref="rulesets/strings.xml/StringToString"/>-->
+ <!--<rule ref="rulesets/strings.xml/AvoidConcatenatingNonLiteralsInStringBuffer"/>-->
+ <!--<rule ref="rulesets/strings.xml/UnnecessaryCaseChange"/>-->
+
+ <!--<rule ref="rulesets/sunsecure.xml/MethodReturnsInternalArray"/>-->
+ <!--<rule ref="rulesets/sunsecure.xml/ArrayIsStoredDirectly"/>-->
+
+ <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/>
+ <rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/>
+ <rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/>
+ <!--<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>-->
+
+</ruleset>
diff --git a/tags/java/tsss-demo/kernel/host-api/LICENSE.txt b/tags/java/tsss-demo/kernel/host-api/LICENSE.txt
new file mode 100644
index 0000000000..0084319535
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, serviceDefinition marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/kernel/host-api/NOTICE.txt b/tags/java/tsss-demo/kernel/host-api/NOTICE.txt
new file mode 100644
index 0000000000..d83ebbe236
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/NOTICE.txt
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/kernel/host-api/pom.xml b/tags/java/tsss-demo/kernel/host-api/pom.xml
new file mode 100644
index 0000000000..2b7b4c520c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/pom.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>kernel</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-host-api</artifactId>
+ <name>Apache Tuscany Host API</name>
+ <description>Tuscany Host Programming Interfaces.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-api</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/AbstractRuntimeInfo.java b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/AbstractRuntimeInfo.java
new file mode 100644
index 0000000000..513d02232a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/AbstractRuntimeInfo.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.host;
+
+import java.io.File;
+import java.net.URL;
+import java.net.URI;
+
+/**
+ * Abstract runtime info implementation.
+ *
+ * @version $Revision$ $Date$
+ */
+public abstract class AbstractRuntimeInfo implements RuntimeInfo {
+
+ /**
+ * This SCA Domain this runtime belongs to.
+ */
+ private final URI domain;
+
+ /**
+ * Application root directory.
+ */
+ private final File applicationRootDirectory;
+
+ /**
+ * Base URL.
+ */
+ private final URL baseUrl;
+
+ /**
+ * Online indicator.
+ */
+ private final boolean online;
+
+ /**
+ * Runtime Id.
+ */
+ private String runtimeId;
+
+ /**
+ * Initializes the runtime info instance.
+ *
+ * @param domain the SCA Domain that this runtime belongs to
+ * @param applicationRootDirectory Application root directory.
+ * @param baseUrl Base Url.
+ * @param online Onlne indicator.
+ * @param runtimeId Runtime Id.
+ */
+ public AbstractRuntimeInfo(final URI domain,
+ final File applicationRootDirectory,
+ final URL baseUrl,
+ final boolean online,
+ final String runtimeId) {
+ this.domain = domain;
+ this.applicationRootDirectory = applicationRootDirectory;
+ this.baseUrl = baseUrl;
+ this.online = online;
+ this.runtimeId = runtimeId;
+ }
+
+ /**
+ * Returns the SCA domain associated with this runtime.
+ * A null domain indicates that this is a standalone runtime with a self-contained assembly.
+ *
+ * @return the SCA domain associated with this runtime; may be null
+ */
+ public URI getDomain() {
+ return domain;
+ }
+
+ /**
+ * Returns the unique runtime is in the SCA domain.
+ *
+ * @return the SCA domain associated with this runtime; may be null
+ */
+ public String getRuntimeId() {
+ return runtimeId;
+ }
+
+ /**
+ * Return the root directory used to resolve application file paths.
+ *
+ * @return the directory used to resolve application file paths.
+ */
+ public final File getApplicationRootDirectory() {
+ return applicationRootDirectory;
+ }
+
+ /**
+ * Gets the base URL for the runtime.
+ *
+ * @return The base URL for the runtime.
+ */
+ public final URL getBaseURL() {
+ return baseUrl;
+ }
+
+ /**
+ * Returns whether the runtime considers itself "online" or connected to the internet.
+ * This can be used by services to enable access to remote resources.
+ *
+ * @return true if the runtime is online.
+ */
+ public final boolean isOnline() {
+ return online;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/MonitorFactory.java b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/MonitorFactory.java
new file mode 100644
index 0000000000..6dc0f53a04
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/MonitorFactory.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.host;
+
+import java.util.Map;
+
+import org.apache.tuscany.host.monitor.FormatterRegistry;
+
+/**
+ * A MonitorFactory creates implementations of components' monitor interfaces that interface with a its monitoring
+ * scheme. For example, a implementation may create versions that emit appropriate logging events or which send
+ * notifications to a management API.
+ * <p/>
+ * MonitorFactory implementations must provide a no-arg constructor and implement the {@link #initialize} method to
+ * perform configuration of instances created using that constructor. Additional constructors may be defined; typically
+ * their implementations delegate to {@link #initialize}.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface MonitorFactory extends FormatterRegistry {
+ /**
+ * Initializes MonitorFactory instances with implementation-specific configuration properties.
+ *
+ * @param configProperties a map of named configuration properties. May be null.
+ * @throws IllegalArgumentException if the instance can't be configured using the supplied properties
+ */
+ void initialize(Map<String, Object> configProperties);
+
+ /**
+ * Return a monitor for a component's monitor interface.
+ *
+ * @param monitorInterface the component's monitoring interface
+ * @return an implementation of the monitoring interface; will not be null
+ */
+ <T> T getMonitor(Class<T> monitorInterface);
+}
diff --git a/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/RuntimeInfo.java b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/RuntimeInfo.java
new file mode 100644
index 0000000000..e275abbe95
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/RuntimeInfo.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.host;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URL;
+
+/**
+ * Interface that provides information on the runtime environment.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface RuntimeInfo {
+
+ /**
+ * Returns the SCA domain associated with this runtime.
+ * A null domain indicates that this is a standalone runtime with a self-contained assembly.
+ *
+ * @return the SCA domain associated with this runtime; may be null
+ */
+ URI getDomain();
+
+ /**
+ * Returns the unique runtime is in the SCA domain.
+ *
+ * @return the SCA domain associated with this runtime; may be null
+ */
+ String getRuntimeId();
+
+ /**
+ * Return the root directory used to resolve application file paths.
+ *
+ * @return the directory used to resolve application file paths.
+ */
+ File getApplicationRootDirectory();
+
+ /**
+ * Gets the base URL for the runtime.
+ *
+ * @return The base URL for the runtime.
+ */
+ URL getBaseURL();
+
+ /**
+ * Returns whether the runtime considers itself "online" or connected to the internet.
+ * This can be used by services to enable access to remote resources.
+ *
+ * @return true if the runtime is online.
+ */
+ boolean isOnline();
+}
diff --git a/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/AssemblyService.java b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/AssemblyService.java
new file mode 100644
index 0000000000..d4525e2ad0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/AssemblyService.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.host.deployment;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+/**
+ * Service interface for managing the logical assembly for a Tuscany runtime.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface AssemblyService {
+ /**
+ * Apply a set of changes to the SCA Domain's logical assembly.
+ *
+ * @param changeSet the location of a resource containing a set of changes
+ * @throws DeploymentException if there was a problem making the changes
+ * @throws IOException if there was a problem accessing the resource
+ */
+ void applyChanges(URL changeSet) throws DeploymentException, IOException;
+
+ /**
+ * Apply a set of changes to the SCA Domain's logical assembly.
+ *
+ * @param changeSet a stream for reading a resource containing a set of changes; the stream will not be closed
+ * but no guarantee is made on the position the stream is left in
+ * @param contentType the type of changeSet on the stream; must be a valid Content-Type value
+ * as specified by <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC2045</a>
+ * and must not be null
+ * @throws DeploymentException if there was a problem making the changes
+ * @throws IOException if there was a problem reading the stream
+ */
+ void applyChanges(InputStream changeSet, String contentType) throws DeploymentException, IOException;
+
+ /**
+ * Includes the SCDL in the logical domain.
+ *
+ * @param scdl SCDL to be included.
+ * @throws DeploymentException If unable to deploy.
+ */
+ void include(InputStream scdl) throws DeploymentException;
+}
diff --git a/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/ContentTypes.java b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/ContentTypes.java
new file mode 100644
index 0000000000..a1f0b26b40
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/ContentTypes.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.host.deployment;
+
+/**
+ * Definitions of common Content-Type values.
+ *
+ * @version $Rev$ $Date$
+ */
+public final class ContentTypes {
+ /**
+ * An Assembly changeSet represented as XML.
+ */
+ public static final String CHANGESET_XML = "application/x-apache.tuscany.changeSet+xml";
+
+ private ContentTypes() {
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/ContributionService.java b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/ContributionService.java
new file mode 100644
index 0000000000..ee8ff958c2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/ContributionService.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.host.deployment;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+
+
+/**
+ * Service interface that manages artifacts contributed to a Tuscany runtime.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ContributionService {
+ /**
+ * Contribute an artifact to the SCA Domain. The type of the contribution is determined by the Content-Type of the
+ * resource or, if that is undefined, by some implementation-specific means (such as mapping an extension in the
+ * URL's path).
+ *
+ * @param contribution the location of the resource containing the artifact
+ * @param storeInRepository flag that identifies if you want to copy the contribution to the repository
+ * @return a URI that uniquely identifies this contribution within the SCA Domain
+ * @throws DeploymentException if there was a problem with the contribution
+ * @throws IOException if there was a problem reading the resource
+ */
+ URI contribute(URL contribution, boolean storeInRepository) throws DeploymentException, IOException;
+
+ /**
+ * Contribute an artifact to the SCA Domain.
+ *
+ * @param source an identifier for the source of this contribution
+ * @param contribution a stream containing the resource being contributed; the stream will not be closed but the
+ * read position after the call is undefined
+ * @param storeInRepository flag that identifies if you want to copy the contribution to the repository
+ * @return a URI that uniquely identifies this contribution within the SCA Domain
+ * @throws DeploymentException if there was a problem with the contribution
+ * @throws IOException if there was a problem reading the stream
+ */
+ URI contribute(URI source, InputStream contribution, boolean storeInRepository)
+ throws DeploymentException, IOException;
+
+ /**
+ * Remove a contribution from the SCA domain
+ * @param contribution The URI of the contribution
+ * @throws DeploymentException if there was a problem with the contribution
+ */
+ void remove(URI contribution) throws DeploymentException;
+
+ /**
+ * Resolve an artifact by QName within the contribution
+ *
+ * @param <T> The java type of the artifact such as javax.wsdl.Definition
+ * @param contribution The URI of the contribution
+ * @param definitionType The java type of the artifact
+ * @param namespace The namespace of the artifact
+ * @param name The name of the artifact
+ * @return The resolved artifact
+ */
+ <T> T resolve(URI contribution, Class<T> definitionType, String namespace, String name);
+
+ /**
+ * Resolve the reference to an artifact by the location URI within the given contribution.
+ * Some typical use cases are:
+ * <ul>
+ * <li>Reference a XML schema using
+ * {http://www.w3.org/2001/XMLSchema-instance}schemaLocation or
+ * <li>Reference a list of WSDLs using
+ * {http://www.w3.org/2004/08/wsdl-instance}wsdlLocation
+ * </ul>
+ * @param contribution The URI of the contribution
+ * @param namespace The namespace of the artifact. This is for validation purpose. If the namespace is null,
+ * then no check will be performed.
+ * @param uri The location URI
+ * @param baseURI The URI of the base artifact where the reference is declared
+ * @return The URL of the resolved artifact
+ */
+ URL resolve(URI contribution, String namespace, URI uri, URI baseURI);
+}
diff --git a/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/DeploymentException.java b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/DeploymentException.java
new file mode 100644
index 0000000000..e5e0e97c79
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/DeploymentException.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.host.deployment;
+
+import org.apache.tuscany.api.TuscanyException;
+
+/**
+ * Base class for exceptions raised during deployment.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DeploymentException extends TuscanyException {
+ protected DeploymentException() {
+ }
+
+ protected DeploymentException(String message) {
+ super(message);
+ }
+
+ protected DeploymentException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ protected DeploymentException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ protected DeploymentException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+
+ public DeploymentException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/UnsupportedContentTypeException.java b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/UnsupportedContentTypeException.java
new file mode 100644
index 0000000000..579465e3d1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/deployment/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.host.deployment;
+
+/**
+ * Exception thrown to indicate that a Content-Type is not supported by this SCA Domain.
+ * The Content-Type value supplied will be returned as the message text for this exception.
+ *
+ * @version $Rev$ $Date$
+ */
+public class UnsupportedContentTypeException extends DeploymentException {
+ private static final long serialVersionUID = -1831797280021355672L;
+
+ /**
+ * Constructor specifying the Content-Type value that is not supported.
+ *
+ * @param contentType the type that is not supported
+ */
+ public UnsupportedContentTypeException(String contentType) {
+ super(contentType);
+ }
+
+ /**
+ * Constructor specifying the Content-Type value that is not supported
+ * and an identifier to use with this exception (typically the resource being processed).
+ *
+ * @param contentType the type that is not supported
+ * @param identifier an identifier for this exception
+ */
+ public UnsupportedContentTypeException(String contentType, String identifier) {
+ super(contentType, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/management/ManagementService.java b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/management/ManagementService.java
new file mode 100644
index 0000000000..1b62d3bbed
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/management/ManagementService.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.host.management;
+
+/**
+ *
+ * @version $Revision$ $Date$
+ */
+public interface ManagementService<T> {
+
+ /**
+ * Registers the object for management.
+ *
+ * @param name Name under which the object is registered.
+ * @param managedObject Managed object to be registered.
+ */
+ void registerComponent(String name, T managedObject);
+
+}
diff --git a/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/monitor/ExceptionFormatter.java b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/monitor/ExceptionFormatter.java
new file mode 100644
index 0000000000..4c1e04ecb9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/monitor/ExceptionFormatter.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.host.monitor;
+
+import java.io.PrintWriter;
+
+/**
+ * Formats exception data during a monitor event
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ExceptionFormatter {
+
+ boolean canFormat(Class<?> type);
+
+ PrintWriter write(PrintWriter writer, Throwable exception);
+
+}
diff --git a/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/monitor/FormatterRegistry.java b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/monitor/FormatterRegistry.java
new file mode 100644
index 0000000000..277abb63a7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/monitor/FormatterRegistry.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.host.monitor;
+
+/**
+ * A registry for exception formatters
+ *
+ * @version $Rev$ $Date$
+ */
+public interface FormatterRegistry {
+
+ /**
+ * Registers the given formatter
+ *
+ * @param formatter the formatter to register
+ */
+ void register(ExceptionFormatter formatter);
+
+ /**
+ * De-registers the given formatter
+ *
+ * @param formatter the formatter to de-register
+ */
+ void unregister(ExceptionFormatter formatter);
+
+}
diff --git a/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/package-info.java b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/package-info.java
new file mode 100644
index 0000000000..e5f0575b60
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Overview of Apache Tuscany API for hosts that are embedding the kernel.
+ */
+package org.apache.tuscany.host; \ No newline at end of file
diff --git a/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/rmi/RMIHost.java b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/rmi/RMIHost.java
new file mode 100644
index 0000000000..3dc68f430d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/rmi/RMIHost.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.host.rmi;
+
+import java.rmi.Remote;
+
+/* RMI Service hosting interface to be implemented by host environments that allows SCA Components
+ * to register RMI Services to handle inbound service requests over RMI to SCA Components
+ */
+
+public interface RMIHost {
+ int RMI_DEFAULT_PORT = 1299;
+
+ // registers an RMI service with the given name and port
+ void registerService(String serviceName, int port, Remote serviceObject) throws RMIHostException,
+ RMIHostRuntimeException;
+
+ // registers an RMI service with the given name and default port (1099)
+ void registerService(String serviceName, Remote serviceObject) throws RMIHostException,
+ RMIHostRuntimeException;
+
+ // unregister a service registered under the given service name and port number
+ void unregisterService(String serviceName, int port) throws RMIHostException,
+ RMIHostRuntimeException;
+
+ // unregister a service registered under the given service name and defalut port number (1099)
+ void unregisterService(String serviceName) throws RMIHostException,
+ RMIHostRuntimeException;
+
+ //find a remote service hosted on the given host, port and service name
+ Remote findService(String host, String port, String svcName) throws RMIHostException,
+ RMIHostRuntimeException;
+}
diff --git a/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/rmi/RMIHostAdmin.java b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/rmi/RMIHostAdmin.java
new file mode 100644
index 0000000000..dedfff1cdd
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/rmi/RMIHostAdmin.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.host.rmi;
+
+import java.rmi.registry.Registry;
+import java.util.List;
+
+/* RMI Service hosting Admin Interface to be implemented by host environments that allows SCA Components
+ * to register RMI Services to handle inbound service requests over RMI to SCA Components. This interface
+ * can be used by admin functions to obtain information on RMI registries started and running in the host
+ * environment
+ */
+
+public interface RMIHostAdmin {
+ //gets all RMI registries running on the host. Each element of the list is an object of type
+ //java.rmi.registry
+ List getAllRegistries() throws RMIHostRuntimeException;
+
+ //gets a registry that is running at a particular port
+ Registry getRegistry(int port) throws RMIHostRuntimeException;
+
+ //more methods to be added
+}
diff --git a/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/rmi/RMIHostException.java b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/rmi/RMIHostException.java
new file mode 100644
index 0000000000..5d7733927d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/rmi/RMIHostException.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.host.rmi;
+
+import org.apache.tuscany.api.TuscanyException;
+
+/**
+ * This exception will relate to situations where the end applicaition's input is the cause of the exception
+ *
+ * @version $Rev$ $Date$
+ */
+public class RMIHostException extends TuscanyException {
+ private static final long serialVersionUID = 8031031440259175970L;
+
+ public RMIHostException() {
+ }
+
+ public RMIHostException(String message) {
+ super(message);
+ }
+
+ public RMIHostException(Throwable e) {
+ super(e);
+ }
+
+ public RMIHostException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/rmi/RMIHostRuntimeException.java b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/rmi/RMIHostRuntimeException.java
new file mode 100644
index 0000000000..35b207b5d2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/rmi/RMIHostRuntimeException.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.host.rmi;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * This exception relates to cases where there is a problem with the
+ * Host runtime
+ *
+ */
+public class RMIHostRuntimeException extends TuscanyRuntimeException {
+ private static final long serialVersionUID = -1L;
+
+ public RMIHostRuntimeException() {
+ }
+
+ public RMIHostRuntimeException(String message) {
+ super(message);
+ }
+
+ public RMIHostRuntimeException(Throwable e) {
+ super(e);
+ }
+
+ public RMIHostRuntimeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/runtime/InitializationException.java b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/runtime/InitializationException.java
new file mode 100644
index 0000000000..20b518609e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/runtime/InitializationException.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.host.runtime;
+
+import org.apache.tuscany.api.TuscanyException;
+
+/**
+ * Denotes an error starting the runtime
+ *
+ * @version $Rev$ $Date$
+ */
+public class InitializationException extends TuscanyException {
+
+ public InitializationException(String message) {
+ super(message);
+ }
+
+ public InitializationException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/runtime/ShutdownException.java b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/runtime/ShutdownException.java
new file mode 100644
index 0000000000..769c928471
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/runtime/ShutdownException.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.host.runtime;
+
+import org.apache.tuscany.api.TuscanyException;
+
+/**
+ * Denotes an error during runtime shutdown
+ *
+ * @version $Rev$ $Date$
+ */
+public class ShutdownException extends TuscanyException {
+
+ public ShutdownException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/runtime/TuscanyRuntime.java b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/runtime/TuscanyRuntime.java
new file mode 100644
index 0000000000..315c02ccf7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/runtime/TuscanyRuntime.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.host.runtime;
+
+import java.net.URL;
+import java.net.URI;
+
+import org.osoa.sca.ComponentContext;
+
+import org.apache.tuscany.host.MonitorFactory;
+import org.apache.tuscany.host.RuntimeInfo;
+import org.apache.tuscany.host.management.ManagementService;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface TuscanyRuntime<I extends RuntimeInfo> {
+ /**
+ * Returns the location of the SCDL used to boot this runtime.
+ *
+ * @return the location of the SCDL used to boot this runtime
+ */
+ URL getSystemScdl();
+
+ /**
+ * Sets the location of the SCDL used to boot this runtime.
+ *
+ * @param systemScdl the location of the SCDL used to boot this runtime
+ */
+ void setSystemScdl(URL systemScdl);
+
+ /**
+ * Returns the host ClassLoader that is parent to all Tuscany classloaders.
+ *
+ * @return the host's ClassLoader
+ */
+ ClassLoader getHostClassLoader();
+
+ /**
+ * Sets the host ClassLoader; this will be a parent for all Tuscany classloaders.
+ *
+ * @param classLoader the host's ClassLoader
+ */
+ void setHostClassLoader(ClassLoader classLoader);
+
+ /**
+ * Returns the info this runtime will make available to service components.
+ *
+ * @return the info this runtime will make available to service components
+ */
+ I getRuntimeInfo();
+
+ /**
+ * Sets the info this runtime should make available to service components.
+ *
+ * @param runtimeInfo the information this runtime should make available to service components
+ */
+ void setRuntimeInfo(I runtimeInfo);
+
+ /**
+ * Returns the MonitorFactory that this runtime is using.
+ *
+ * @return the MonitorFactory that this runtime is using
+ */
+ MonitorFactory getMonitorFactory();
+
+ /**
+ * Sets the MonitorFactory that this runtime should use.
+ *
+ * @param monitorFactory the MonitorFactory that this runtime should use
+ */
+ void setMonitorFactory(MonitorFactory monitorFactory);
+
+ /**
+ * Sets the ManagementService that this runtime should use.
+ *
+ * @param managementService the ManagementService that this runtime should use
+ */
+ void setManagementService(ManagementService<?> managementService);
+
+ /**
+ * Returns the ManagementService that this runtime is using.
+ *
+ * @return the ManagementService that this runtime is using
+ */
+ ManagementService<?> getManagementService();
+
+ /**
+ * Initialize a runtime.
+ *
+ * @throws InitializationException if there is an error initializing the runtime
+ */
+ void initialize() throws InitializationException;
+
+ /**
+ * Destroy the runtime. Any further invocations should result in an error.
+ *
+ * @throws ShutdownException if there is an error destroying the runtime
+ */
+ void destroy() throws ShutdownException;
+
+ /**
+ * Returns the ComponentContext for the designated component.
+ *
+ * @param componentId the id of the component whose context should be returned
+ * @return the ComponentContext for the designated component
+ */
+ ComponentContext getComponentContext(URI componentId);
+}
diff --git a/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/servlet/ServletRequestInjector.java b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/servlet/ServletRequestInjector.java
new file mode 100644
index 0000000000..e4b11aee90
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/src/main/java/org/apache/tuscany/host/servlet/ServletRequestInjector.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.host.servlet;
+
+import java.io.IOException;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+/**
+ * Interface to a system component that dispatches servlet requests to the Tuscany runtime
+ */
+public interface ServletRequestInjector {
+
+ /**
+ * Dispatch servlet requests to the Tuscany runtime
+ *
+ * @param req the ServletRequest object that contains the request the client made of the servlet
+ * @param res the ServletResponse object that contains the response the servlet returns to the client
+ * @throws ServletException if the request cannot be handled
+ * @throws IOException if an input or output error occurs while handling the request
+ */
+ void service(ServletRequest req, ServletResponse res) throws ServletException, IOException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/host-api/src/test/java/org/apache/tuscany/host/rmi/RMIHostExceptionTestCase.java b/tags/java/tsss-demo/kernel/host-api/src/test/java/org/apache/tuscany/host/rmi/RMIHostExceptionTestCase.java
new file mode 100644
index 0000000000..0e62dbb3e1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/src/test/java/org/apache/tuscany/host/rmi/RMIHostExceptionTestCase.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.host.rmi;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class RMIHostExceptionTestCase extends TestCase {
+ private static final Throwable CAUSE = new Throwable("Cause");
+ private static final String MESSAGE = "Message";
+
+ public void testNoArgConstructor() {
+ Exception ex = new RMIHostException();
+ assertNull(ex.getMessage());
+ assertNull(ex.getCause());
+ }
+
+ public void testMessageConstructor() {
+ Exception ex = new RMIHostException(MESSAGE);
+ assertEquals(MESSAGE, ex.getMessage());
+ assertNull(ex.getCause());
+ }
+
+ public void testThrowableConstructor() {
+ Exception ex = new RMIHostException(CAUSE);
+ assertEquals(CAUSE.getClass().getName() + ": " + CAUSE.getMessage(), ex.getMessage());
+ assertEquals(CAUSE, ex.getCause());
+ }
+
+ public void testMessageThrowableConstructor() {
+ Exception ex = new RMIHostException(MESSAGE, CAUSE);
+ assertEquals(MESSAGE, ex.getMessage());
+ assertEquals(CAUSE, ex.getCause());
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/host-api/src/test/java/org/apache/tuscany/host/rmi/RMIHostRuntimeExceptionTestCase.java b/tags/java/tsss-demo/kernel/host-api/src/test/java/org/apache/tuscany/host/rmi/RMIHostRuntimeExceptionTestCase.java
new file mode 100644
index 0000000000..5071a68132
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/host-api/src/test/java/org/apache/tuscany/host/rmi/RMIHostRuntimeExceptionTestCase.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.host.rmi;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class RMIHostRuntimeExceptionTestCase extends TestCase {
+ private static final Throwable CAUSE = new Throwable("Cause");
+ private static final String MESSAGE = "Message";
+
+ public void testNoArgConstructor() {
+ Exception ex = new RMIHostRuntimeException();
+ assertNull(ex.getMessage());
+ assertNull(ex.getCause());
+ }
+
+ public void testMessageConstructor() {
+ Exception ex = new RMIHostRuntimeException(MESSAGE);
+ assertSame(MESSAGE, ex.getMessage());
+ assertNull(ex.getCause());
+ }
+
+ public void testThrowableConstructor() {
+ Exception ex = new RMIHostRuntimeException(CAUSE);
+ assertEquals(CAUSE.getClass().getName() + ": " + CAUSE.getMessage(), ex.getMessage());
+ assertSame(CAUSE, ex.getCause());
+ }
+
+ public void testMessageThrowableConstructor() {
+ Exception ex = new RMIHostRuntimeException(MESSAGE, CAUSE);
+ assertSame(MESSAGE, ex.getMessage());
+ assertSame(CAUSE, ex.getCause());
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/overview.html b/tags/java/tsss-demo/kernel/overview.html
new file mode 100644
index 0000000000..39e9f84069
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/overview.html
@@ -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.
+-->
+<html>
+<body>
+<p>This document is the API documentation for the Apache Tuscany SCA Kernel.</p>
+<p>The API is broken into three main sections each aimed at different user communities:</p>
+<ul>
+ <li>api documentation for users writing components to run in Apache Tuscany</li>
+ <li>host documentation for users looking to embed Apache Tuscany in a runtime environment</li>
+ <li>spi documentation for users who wish to add extension functionality</li>
+</ul>
+</body>
+</html>
diff --git a/tags/java/tsss-demo/kernel/pom.xml b/tags/java/tsss-demo/kernel/pom.xml
new file mode 100644
index 0000000000..7a37c5ee0e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/pom.xml
@@ -0,0 +1,209 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany</groupId>
+ <artifactId>sca</artifactId>
+ <version>1.0-incubating</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>kernel</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ <packaging>pom</packaging>
+ <name>Apache Tuscany SCA Kernel Sub-Project</name>
+ <description>Apache Tuscany Kernel project providing an embeddable SCA runtime.</description>
+
+ <properties>
+ <!-- version the SCA API that we implement -->
+ <scaSpecVersion>1.0</scaSpecVersion>
+ </properties>
+
+ <!-- definition of repositories where the parent pom can be found -->
+ <repositories>
+ <repository>
+ <id>apache.incubator</id>
+ <name>Apache Incubator Repository</name>
+ <url>http://people.apache.org/repo/m2-incubating-repository/</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+
+ <!-- dependencies used by the kernel -->
+ <dependencyManagement>
+ <dependencies>
+ <!-- org.osoa.sca API -->
+ <dependency>
+ <groupId>org.osoa</groupId>
+ <artifactId>sca-api-r${scaSpecVersion}</artifactId>
+ <version>1.0-incubating</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <!-- javax.servlet API -->
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- java.xml.stream API -->
+ <dependency>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ <version>1.0.1</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <!-- StAX implementation -->
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ <version>3.2.0</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <!-- junit version -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- EasyMock version -->
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>2.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ <version>2.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.2</version>
+ <configuration>
+ <links>
+ <link>http://java.sun.com/j2se/1.5.0/docs/api</link>
+ </links>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+ <profiles>
+ <profile>
+ <!-- default profile that just builds the jar files -->
+ <id>default</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <modules>
+ <module>api</module>
+ <module>host-api</module>
+ <module>spi</module>
+ <module>core</module>
+ </modules>
+ <build>
+ <defaultGoal>install</defaultGoal>
+ </build>
+ </profile>
+
+ <profile>
+ <!-- release profile that prepares artifacts for release -->
+ <id>release</id>
+ <modules>
+ <module>api</module>
+ <module>host-api</module>
+ <module>spi</module>
+ <module>core</module>
+ </modules>
+ <build>
+ <defaultGoal>verify</defaultGoal>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-gpg-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>sign</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ <profile>
+ <!-- javadoc profile for generating online javadoc -->
+ <id>javadoc</id>
+ <modules>
+ <module>api</module>
+ <module>host-api</module>
+ <module>spi</module>
+ </modules>
+ <build>
+ <defaultGoal>org.apache.maven.plugins:maven-javadoc-plugin:javadoc</defaultGoal>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ <overview>${basedir}/overview.html</overview>
+ <aggregate>true</aggregate>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
diff --git a/tags/java/tsss-demo/kernel/spi/.checkstyle b/tags/java/tsss-demo/kernel/spi/.checkstyle
new file mode 100644
index 0000000000..3e57539570
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/.checkstyle
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<fileset-config file-format-version="1.2.0" simple-config="true">
+ <fileset name="all" enabled="true" check-config-name="Tuscany Checks" local="false">
+ <file-match-pattern match-pattern="." include-pattern="true"/>
+ </fileset>
+</fileset-config>
diff --git a/tags/java/tsss-demo/kernel/spi/.pmd b/tags/java/tsss-demo/kernel/spi/.pmd
new file mode 100644
index 0000000000..ffc4fe2bbb
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/.pmd
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<pmd><useProjectRuleSet>true</useProjectRuleSet><rules/></pmd>
diff --git a/tags/java/tsss-demo/kernel/spi/.ruleset b/tags/java/tsss-demo/kernel/spi/.ruleset
new file mode 100644
index 0000000000..3886f07f2d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/.ruleset
@@ -0,0 +1,190 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<ruleset name="pmd-eclipse">
+ <description>PMD Plugin preferences rule set</description>
+
+
+ <rule ref="rulesets/basic.xml/BooleanInstantiation"/>
+ <rule ref="rulesets/basic.xml/CollapsibleIfStatements"/>
+ <rule ref="rulesets/basic.xml/DoubleCheckedLocking"/>
+<!--<rule ref="rulesets/basic.xml/EmptyCatchBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyFinallyBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyIfStmt"/>-->
+ <rule ref="rulesets/basic.xml/EmptyStatementNotInLoop"/>
+<!--<rule ref="rulesets/basic.xml/EmptyStaticInitializer"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptySwitchStatements"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptySynchronizedBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyTryBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyWhileStmt"/>-->
+ <rule ref="rulesets/basic.xml/ForLoopShouldBeWhileLoop"/>
+ <rule ref="rulesets/basic.xml/JumbledIncrementer"/>
+<!--<rule ref="rulesets/basic.xml/OverrideBothEqualsAndHashcode"/>-->
+ <rule ref="rulesets/basic.xml/ReturnFromFinallyBlock"/>
+ <rule ref="rulesets/basic.xml/UnconditionalIfStatement"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryConversionTemporary"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryFinalModifier"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryReturn"/>
+<!--<rule ref="rulesets/basic.xml/UselessOverridingMethod"/>-->
+
+<!--<rule ref="rulesets/braces.xml/ForLoopsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/IfElseStmtsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/IfStmtsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/WhileLoopsMustUseBraces"/>-->
+
+<!--<rule ref="rulesets/clone.xml/CloneMethodMustImplementCloneable"/>-->
+<!--<rule ref="rulesets/clone.xml/CloneThrowsCloneNotSupportedException"/>-->
+<!--<rule ref="rulesets/clone.xml/ProperCloneImplementation"/>-->
+
+<!--<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>-->
+<!--<rule ref="rulesets/codesize.xml/TooManyFields"/>-->
+
+<rule ref="rulesets/controversial.xml/AssignmentInOperand"/>
+<!--<rule ref="rulesets/controversial.xml/AtLeastOneConstructor"/>-->
+<!--<rule ref="rulesets/controversial.xml/CallSuperInConstructor"/>-->
+<!--<rule ref="rulesets/controversial.xml/DontImportSun"/>-->
+<!--<rule ref="rulesets/controversial.xml/NullAssignment"/>-->
+<!--<rule ref="rulesets/controversial.xml/OnlyOneReturn"/>-->
+<!--<rule ref="rulesets/controversial.xml/SingularField"/>-->
+<!--<rule ref="rulesets/controversial.xml/SuspiciousOctalEscape"/>-->
+<!--<rule ref="rulesets/controversial.xml/UnnecessaryConstructor"/>-->
+<rule ref="rulesets/controversial.xml/UnnecessaryParentheses"/>
+<!--<rule ref="rulesets/controversial.xml/UnusedModifier"/>-->
+
+<!--<rule ref="rulesets/coupling.xml/CouplingBetweenObjects"/>-->
+<!--<rule ref="rulesets/coupling.xml/ExcessiveImports"/>-->
+<!--<rule ref="rulesets/coupling.xml/LooseCoupling"/>-->
+
+<!--<rule ref="rulesets/design.xml/AbstractClassWithoutAbstractMethod"/>-->
+<!--<rule ref="rulesets/design.xml/AccessorClassGeneration"/>-->
+<!--<rule ref="rulesets/design.xml/AssignmentToNonFinalStatic"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidDeeplyNestedIfStmts"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidInstanceofChecksInCatchClause"/>-->
+<rule ref="rulesets/design.xml/AvoidProtectedFieldInFinalClass"/>
+<!--<rule ref="rulesets/design.xml/AvoidReassigningParameters"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidSynchronizedAtMethodLevel"/>-->
+<!--<rule ref="rulesets/design.xml/BadComparison"/>-->
+<!--<rule ref="rulesets/design.xml/CloseConnection"/>-->
+<!--<rule ref="rulesets/design.xml/CompareObjectsWithEquals"/>-->
+<!--<rule ref="rulesets/design.xml/ConfusingTernary"/>-->
+<rule ref="rulesets/design.xml/ConstructorCallsOverridableMethod"/>
+<!--<rule ref="rulesets/design.xml/DefaultLabelNotLastInSwitchStmt"/>-->
+<!--<rule ref="rulesets/design.xml/FinalFieldCouldBeStatic"/>-->
+<rule ref="rulesets/design.xml/IdempotentOperations"/>
+<!--<rule ref="rulesets/design.xml/ImmutableField"/>-->
+<!--<rule ref="rulesets/design.xml/InstantiationToGetClass"/>-->
+<!--<rule ref="rulesets/design.xml/MissingBreakInSwitch"/>-->
+<!--<rule ref="rulesets/design.xml/MissingStaticMethodInNonInstantiatableClass"/>-->
+<!--<rule ref="rulesets/design.xml/NonCaseLabelInSwitchStatement"/>-->
+<!--<rule ref="rulesets/design.xml/NonStaticInitializer"/>-->
+<rule ref="rulesets/design.xml/OptimizableToArrayCall"/>
+<rule ref="rulesets/design.xml/PositionLiteralsFirstInComparisons"/>
+<rule ref="rulesets/design.xml/SimplifyBooleanExpressions"/>
+<rule ref="rulesets/design.xml/SimplifyBooleanReturns"/>
+<rule ref="rulesets/design.xml/SimplifyConditional"/>
+<!--<rule ref="rulesets/design.xml/SwitchDensity"/>-->
+<!--<rule ref="rulesets/design.xml/SwitchStmtsShouldHaveDefault"/>-->
+<rule ref="rulesets/design.xml/UnnecessaryLocalBeforeReturn"/>
+<!--<rule ref="rulesets/design.xml/UseLocaleWithCaseConversions"/>-->
+<!--<rule ref="rulesets/design.xml/UseNotifyAllInsteadOfNotify"/>-->
+<!--<rule ref="rulesets/design.xml/UseSingleton"/>-->
+
+<!--<rule ref="rulesets/finalizers.xml/EmptyFinalizer"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeOnlyCallsSuperFinalize"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeOverloaded"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeDoesNotCallSuperFinalize"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeShouldBeProtected"/>-->
+<!--<rule ref="rulesets/finalizers.xml/AvoidCallingFinalize"/>-->
+
+<!--<rule ref="rulesets/imports.xml/DuplicateImports"/>-->
+<!--<rule ref="rulesets/imports.xml/DontImportJavaLang"/>-->
+<!--<rule ref="rulesets/imports.xml/UnusedImports"/>-->
+<!--<rule ref="rulesets/imports.xml/ImportFromSamePackage"/>-->
+
+<!--<rule ref="rulesets/javabeans.xml/BeanMembersShouldSerialize"/>-->
+<!--<rule ref="rulesets/javabeans.xml/MissingSerialVersionUID"/>-->
+
+<!--<rule ref="rulesets/junit.xml/JUnitStaticSuite"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitSpelling"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitAssertionsShouldIncludeMessage"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitTestsShouldIncludeAssert"/>-->
+<!--<rule ref="rulesets/junit.xml/TestClassWithoutTestCases"/>-->
+<!--<rule ref="rulesets/junit.xml/UnnecessaryBooleanAssertion"/>-->
+<!--<rule ref="rulesets/junit.xml/UseAssertEqualsInsteadOfAssertTrue"/>-->
+<!--<rule ref="rulesets/junit.xml/UseAssertSameInsteadOfAssertTrue"/>-->
+
+ <!--<rule ref="rulesets/logging-java.xml/AvoidPrintStackTrace"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/MoreThanOneLogger"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LogBlockWithoutIf"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/SystemPrintln"/>-->
+ <!--<rule ref="rulesets/logging-jakarta-commons.xml/UseCorrectExceptionLogging"/>-->
+ <!--<rule ref="rulesets/logging-jakarta-commons.xml/ProperLogger"/>-->
+
+ <!--<rule ref="rulesets/naming.xml/ShortVariable"/>-->
+ <!--<rule ref="rulesets/naming.xml/LongVariable"/>-->
+ <!--<rule ref="rulesets/naming.xml/ShortMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/VariableNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/MethodNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/ClassNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/AbstractNaming"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidDollarSigns"/>-->
+ <!--<rule ref="rulesets/naming.xml/MethodWithSameNameAsEnclosingClass"/>-->
+ <!--<rule ref="rulesets/naming.xml/SuspiciousHashcodeMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/SuspiciousConstantFieldName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingTypeName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidNonConstructorMethodsWithClassName"/>-->
+ <!--<rule ref="rulesets/naming.xml/NoPackage"/>-->
+ <!--<rule ref="rulesets/naming.xml/PackageCase"/>-->
+
+ <!--<rule ref="rulesets/optimizations.xml/LocalVariableCouldBeFinal"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/MethodArgumentCouldBeFinal"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/AvoidInstantiatingObjectsInLoops"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/UseArrayListInsteadOfVector"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/SimplifyStartsWith"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/UseStringBufferForStringAppends"/>-->
+
+ <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingThrowable"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/SignatureDeclareThrowsException"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/ExceptionAsFlowControl"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingNPE"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingRawExceptionTypes"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingNullPointerException"/>-->
+
+ <!--<rule ref="rulesets/strings.xml/AvoidDuplicateLiterals"/>-->
+ <!--<rule ref="rulesets/strings.xml/StringInstantiation"/>-->
+ <!--<rule ref="rulesets/strings.xml/StringToString"/>-->
+ <!--<rule ref="rulesets/strings.xml/AvoidConcatenatingNonLiteralsInStringBuffer"/>-->
+ <!--<rule ref="rulesets/strings.xml/UnnecessaryCaseChange"/>-->
+
+ <!--<rule ref="rulesets/sunsecure.xml/MethodReturnsInternalArray"/>-->
+ <!--<rule ref="rulesets/sunsecure.xml/ArrayIsStoredDirectly"/>-->
+
+ <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/>
+ <rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/>
+ <rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/>
+ <!--<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>-->
+
+</ruleset>
diff --git a/tags/java/tsss-demo/kernel/spi/LICENSE.txt b/tags/java/tsss-demo/kernel/spi/LICENSE.txt
new file mode 100644
index 0000000000..0084319535
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, serviceDefinition marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/kernel/spi/NOTICE.txt b/tags/java/tsss-demo/kernel/spi/NOTICE.txt
new file mode 100644
index 0000000000..d83ebbe236
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/NOTICE.txt
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/kernel/spi/pom.xml b/tags/java/tsss-demo/kernel/spi/pom.xml
new file mode 100644
index 0000000000..e622672898
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/pom.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>kernel</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-spi</artifactId>
+ <name>Apache Tuscany SCA SPI</name>
+ <description>Tuscany Service Provider Interfaces.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-host-api</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ </dependency>
+
+ </dependencies>
+</project>
diff --git a/tags/java/tsss-demo/kernel/spi/src/doc/Context Model.emx b/tags/java/tsss-demo/kernel/spi/src/doc/Context Model.emx
new file mode 100644
index 0000000000..0445ea5a6b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/doc/Context Model.emx
@@ -0,0 +1,673 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<!--xtools2_universal_type_manager-->
+<uml:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:notation="http://www.ibm.com/xtools/1.5.0/Notation" xmlns:uml="http://www.eclipse.org/uml2/1.0.0/UML" xmlns:umlnotation="http://www.ibm.com/xtools/1.5.0/Umlnotation" xmi:id="_al1S8NovEdqRBPR5WyT36A" name="Context Model" appliedProfile="_al1S9NovEdqRBPR5WyT36A _al1S99ovEdqRBPR5WyT36A _al1S-tovEdqRBPR5WyT36A _al1S_dovEdqRBPR5WyT36A _al1TANovEdqRBPR5WyT36A">
+ <eAnnotations xmi:id="_al1S8dovEdqRBPR5WyT36A" source="uml2.diagrams" references="_al1S8tovEdqRBPR5WyT36A">
+ <contents xmi:type="notation:Diagram" xmi:id="_al1S8tovEdqRBPR5WyT36A" type="Class" name="Main">
+ <children xmi:id="_ePDcYdovEdqRBPR5WyT36A" sourceEdges="_Fd3lQdowEdqRBPR5WyT36A _R5Rjwdo1EdqRBPR5WyT36A _pdfmkNo2EdqRBPR5WyT36A" targetEdges="_hmIF4dovEdqRBPR5WyT36A _mu9A4dovEdqRBPR5WyT36A _pe3jwNovEdqRBPR5WyT36A" element="_ePDcYNovEdqRBPR5WyT36A">
+ <children xmi:id="_ePJjANovEdqRBPR5WyT36A" type="ImageCompartment" element="_ePDcYNovEdqRBPR5WyT36A">
+ <layoutConstraint xmi:type="notation:Size" xmi:id="_ePJjAdovEdqRBPR5WyT36A" width="530" height="530"/>
+ </children>
+ <children xmi:id="_ePJjAtovEdqRBPR5WyT36A" type="Stereotype" element="_ePDcYNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_ePJjA9ovEdqRBPR5WyT36A" type="Kind" element="_ePDcYNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_ePJjBNovEdqRBPR5WyT36A" type="Name" element="_ePDcYNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_ePJjBdovEdqRBPR5WyT36A" type="AttributeCompartment" element="_ePDcYNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_ePJjBtovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_ePJjB9ovEdqRBPR5WyT36A" type="OperationCompartment" element="_ePDcYNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_ePJjCNovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_ePJjCdovEdqRBPR5WyT36A" visible="false" type="SignalCompartment" element="_ePDcYNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_ePJjCtovEdqRBPR5WyT36A"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLClassifierStyle" xmi:id="_ePDcYtovEdqRBPR5WyT36A" showStereotype="Label" useClassifierShape="true"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_ePDcY9ovEdqRBPR5WyT36A" x="6693" y="3545"/>
+ </children>
+ <children xmi:id="_fs1pANovEdqRBPR5WyT36A" sourceEdges="_hmIF4dovEdqRBPR5WyT36A _pe3jwNovEdqRBPR5WyT36A" targetEdges="_xInjYdovEdqRBPR5WyT36A" element="_fsviYNovEdqRBPR5WyT36A">
+ <children xmi:id="_fs1pA9ovEdqRBPR5WyT36A" type="ImageCompartment" element="_fsviYNovEdqRBPR5WyT36A">
+ <layoutConstraint xmi:type="notation:Size" xmi:id="_fs1pBNovEdqRBPR5WyT36A" width="530" height="530"/>
+ </children>
+ <children xmi:id="_fs1pBdovEdqRBPR5WyT36A" type="Stereotype" element="_fsviYNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_fs1pBtovEdqRBPR5WyT36A" type="Kind" element="_fsviYNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_fs1pB9ovEdqRBPR5WyT36A" type="Name" element="_fsviYNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_fs1pCNovEdqRBPR5WyT36A" type="AttributeCompartment" element="_fsviYNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_fs1pCdovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_fs1pCtovEdqRBPR5WyT36A" type="OperationCompartment" element="_fsviYNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_fs1pC9ovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_fs1pDNovEdqRBPR5WyT36A" visible="false" type="SignalCompartment" element="_fsviYNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_fs1pDdovEdqRBPR5WyT36A"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLClassifierStyle" xmi:id="_fs1pAdovEdqRBPR5WyT36A" showStereotype="Label" useClassifierShape="true"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_fs1pAtovEdqRBPR5WyT36A" x="2226" y="8268"/>
+ </children>
+ <children xmi:id="_ikr_4NovEdqRBPR5WyT36A" sourceEdges="_mu9A4dovEdqRBPR5WyT36A" element="_ikl5QNovEdqRBPR5WyT36A">
+ <children xmi:id="_ikr_49ovEdqRBPR5WyT36A" type="ImageCompartment" element="_ikl5QNovEdqRBPR5WyT36A">
+ <layoutConstraint xmi:type="notation:Size" xmi:id="_ikr_5NovEdqRBPR5WyT36A" width="530" height="530"/>
+ </children>
+ <children xmi:id="_ikr_5dovEdqRBPR5WyT36A" type="Stereotype" element="_ikl5QNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_ikr_5tovEdqRBPR5WyT36A" type="Kind" element="_ikl5QNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_ikr_59ovEdqRBPR5WyT36A" type="Name" element="_ikl5QNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_ikr_6NovEdqRBPR5WyT36A" type="AttributeCompartment" element="_ikl5QNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_ikr_6dovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_ikr_6tovEdqRBPR5WyT36A" type="OperationCompartment" element="_ikl5QNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_ikr_69ovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_ikr_7NovEdqRBPR5WyT36A" visible="false" type="SignalCompartment" element="_ikl5QNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_ikr_7dovEdqRBPR5WyT36A"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLClassifierStyle" xmi:id="_ikr_4dovEdqRBPR5WyT36A" showStereotype="Label" useClassifierShape="true"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_ikr_4tovEdqRBPR5WyT36A" x="9222" y="8268"/>
+ </children>
+ <children xmi:id="_tZF9odovEdqRBPR5WyT36A" sourceEdges="_xInjYdovEdqRBPR5WyT36A _BkUg0dowEdqRBPR5WyT36A" element="_tZF9oNovEdqRBPR5WyT36A">
+ <children xmi:id="_tZF9pNovEdqRBPR5WyT36A" type="ImageCompartment" element="_tZF9oNovEdqRBPR5WyT36A">
+ <layoutConstraint xmi:type="notation:Size" xmi:id="_tZF9pdovEdqRBPR5WyT36A" width="530" height="530"/>
+ </children>
+ <children xmi:id="_tZF9ptovEdqRBPR5WyT36A" type="Stereotype" element="_tZF9oNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_tZF9p9ovEdqRBPR5WyT36A" type="Kind" element="_tZF9oNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_tZF9qNovEdqRBPR5WyT36A" type="Name" element="_tZF9oNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_tZF9qdovEdqRBPR5WyT36A" type="AttributeCompartment" element="_tZF9oNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_tZF9qtovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_tZF9q9ovEdqRBPR5WyT36A" type="OperationCompartment" element="_tZF9oNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_tZF9rNovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_tZF9rdovEdqRBPR5WyT36A" visible="false" type="SignalCompartment" element="_tZF9oNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_tZF9rtovEdqRBPR5WyT36A"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLClassifierStyle" xmi:id="_tZF9otovEdqRBPR5WyT36A" showStereotype="Label" useClassifierShape="true"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_tZF9o9ovEdqRBPR5WyT36A" x="2226" y="12084"/>
+ </children>
+ <children xmi:id="_z_m-oNovEdqRBPR5WyT36A" sourceEdges="_cN4xsdo2EdqRBPR5WyT36A" targetEdges="_3Ic-4NovEdqRBPR5WyT36A _9XeF4tovEdqRBPR5WyT36A _Fd3lQdowEdqRBPR5WyT36A" element="_z_g4ANovEdqRBPR5WyT36A">
+ <children xmi:id="_z_m-o9ovEdqRBPR5WyT36A" type="ImageCompartment" element="_z_g4ANovEdqRBPR5WyT36A">
+ <layoutConstraint xmi:type="notation:Size" xmi:id="_z_m-pNovEdqRBPR5WyT36A" width="530" height="530"/>
+ </children>
+ <children xmi:id="_z_m-pdovEdqRBPR5WyT36A" type="Stereotype" element="_z_g4ANovEdqRBPR5WyT36A"/>
+ <children xmi:id="_z_m-ptovEdqRBPR5WyT36A" type="Kind" element="_z_g4ANovEdqRBPR5WyT36A"/>
+ <children xmi:id="_z_m-p9ovEdqRBPR5WyT36A" type="Name" element="_z_g4ANovEdqRBPR5WyT36A"/>
+ <children xmi:id="_z_m-qNovEdqRBPR5WyT36A" type="AttributeCompartment" element="_z_g4ANovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_z_m-qdovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_z_m-qtovEdqRBPR5WyT36A" type="OperationCompartment" element="_z_g4ANovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_z_m-q9ovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_z_m-rNovEdqRBPR5WyT36A" visible="false" type="SignalCompartment" element="_z_g4ANovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_z_m-rdovEdqRBPR5WyT36A"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLClassifierStyle" xmi:id="_z_m-odovEdqRBPR5WyT36A" showStereotype="Label" useClassifierShape="true"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_z_m-otovEdqRBPR5WyT36A" x="17172" y="6996"/>
+ </children>
+ <children xmi:id="_1y-ZsNovEdqRBPR5WyT36A" sourceEdges="_3Ic-4NovEdqRBPR5WyT36A _9-BEUNo2EdqRBPR5WyT36A" targetEdges="_BkUg0dowEdqRBPR5WyT36A" element="_1yyMcNovEdqRBPR5WyT36A">
+ <children xmi:id="_1y-Zs9ovEdqRBPR5WyT36A" type="ImageCompartment" element="_1yyMcNovEdqRBPR5WyT36A">
+ <layoutConstraint xmi:type="notation:Size" xmi:id="_1y-ZtNovEdqRBPR5WyT36A" width="1320" height="1320"/>
+ </children>
+ <children xmi:id="_1y-ZtdovEdqRBPR5WyT36A" type="Stereotype" element="_1yyMcNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_1y-ZttovEdqRBPR5WyT36A" type="Name" element="_1yyMcNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_1y-Zt9ovEdqRBPR5WyT36A" type="AttributeCompartment" element="_1yyMcNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_1y-ZuNovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_1y-ZudovEdqRBPR5WyT36A" type="OperationCompartment" element="_1yyMcNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_1y-ZutovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_1y-Zu9ovEdqRBPR5WyT36A" visible="false" type="SignalCompartment" element="_1yyMcNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_1y-ZvNovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_1y-ZvdovEdqRBPR5WyT36A" visible="false" type="StructureCompartment" element="_1yyMcNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLShapeCompartmentStyle" xmi:id="_1y-ZvtovEdqRBPR5WyT36A"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLShapeStyle" xmi:id="_1y-ZsdovEdqRBPR5WyT36A" showStereotype="Label"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_1y-ZstovEdqRBPR5WyT36A" x="13992" y="12084"/>
+ </children>
+ <children xmi:id="_4WSrANovEdqRBPR5WyT36A" sourceEdges="_9XeF4tovEdqRBPR5WyT36A _9PaR4No2EdqRBPR5WyT36A" element="_4WMkYNovEdqRBPR5WyT36A">
+ <children xmi:id="_4WSrA9ovEdqRBPR5WyT36A" type="ImageCompartment" element="_4WMkYNovEdqRBPR5WyT36A">
+ <layoutConstraint xmi:type="notation:Size" xmi:id="_4WSrBNovEdqRBPR5WyT36A" width="1320" height="1320"/>
+ </children>
+ <children xmi:id="_4WSrBdovEdqRBPR5WyT36A" type="Stereotype" element="_4WMkYNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_4WSrBtovEdqRBPR5WyT36A" type="Name" element="_4WMkYNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_4WSrB9ovEdqRBPR5WyT36A" type="AttributeCompartment" element="_4WMkYNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_4WSrCNovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_4WSrCdovEdqRBPR5WyT36A" type="OperationCompartment" element="_4WMkYNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_4WSrCtovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_4WSrC9ovEdqRBPR5WyT36A" visible="false" type="SignalCompartment" element="_4WMkYNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_4WSrDNovEdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_4WSrDdovEdqRBPR5WyT36A" visible="false" type="StructureCompartment" element="_4WMkYNovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLShapeCompartmentStyle" xmi:id="_4WSrDtovEdqRBPR5WyT36A"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLShapeStyle" xmi:id="_4WSrAdovEdqRBPR5WyT36A" showStereotype="Label"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_4WSrAtovEdqRBPR5WyT36A" x="19716" y="12084"/>
+ </children>
+ <children xmi:id="_o2m3oNo0EdqRBPR5WyT36A" targetEdges="_9PaR4No2EdqRBPR5WyT36A _9-BEUNo2EdqRBPR5WyT36A" element="_o2gxANo0EdqRBPR5WyT36A">
+ <children xmi:id="_o2m3o9o0EdqRBPR5WyT36A" type="ImageCompartment" element="_o2gxANo0EdqRBPR5WyT36A">
+ <layoutConstraint xmi:type="notation:Size" xmi:id="_o2m3pNo0EdqRBPR5WyT36A" width="530" height="530"/>
+ </children>
+ <children xmi:id="_o2m3pdo0EdqRBPR5WyT36A" type="Stereotype" element="_o2gxANo0EdqRBPR5WyT36A"/>
+ <children xmi:id="_o2m3pto0EdqRBPR5WyT36A" type="Kind" element="_o2gxANo0EdqRBPR5WyT36A"/>
+ <children xmi:id="_o2m3p9o0EdqRBPR5WyT36A" type="Name" element="_o2gxANo0EdqRBPR5WyT36A"/>
+ <children xmi:id="_o2m3qNo0EdqRBPR5WyT36A" type="AttributeCompartment" element="_o2gxANo0EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_o2m3qdo0EdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_o2m3qto0EdqRBPR5WyT36A" type="OperationCompartment" element="_o2gxANo0EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_o2m3q9o0EdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_o2m3rNo0EdqRBPR5WyT36A" visible="false" type="SignalCompartment" element="_o2gxANo0EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_o2m3rdo0EdqRBPR5WyT36A"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLClassifierStyle" xmi:id="_o2m3odo0EdqRBPR5WyT36A" showStereotype="Label" useClassifierShape="true"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_o2m3oto0EdqRBPR5WyT36A" x="23532" y="6996"/>
+ </children>
+ <children xmi:id="_M0FLkNo1EdqRBPR5WyT36A" targetEdges="_R5Rjwdo1EdqRBPR5WyT36A _V7zlEdo1EdqRBPR5WyT36A" element="_Mz_E8No1EdqRBPR5WyT36A">
+ <children xmi:id="_M0FLk9o1EdqRBPR5WyT36A" type="ImageCompartment" element="_Mz_E8No1EdqRBPR5WyT36A">
+ <layoutConstraint xmi:type="notation:Size" xmi:id="_M0FLlNo1EdqRBPR5WyT36A" width="530" height="530"/>
+ </children>
+ <children xmi:id="_M0FLldo1EdqRBPR5WyT36A" type="Stereotype" element="_Mz_E8No1EdqRBPR5WyT36A"/>
+ <children xmi:id="_M0FLlto1EdqRBPR5WyT36A" type="Kind" element="_Mz_E8No1EdqRBPR5WyT36A"/>
+ <children xmi:id="_M0FLl9o1EdqRBPR5WyT36A" type="Name" element="_Mz_E8No1EdqRBPR5WyT36A"/>
+ <children xmi:id="_M0FLmNo1EdqRBPR5WyT36A" type="AttributeCompartment" element="_Mz_E8No1EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_M0FLmdo1EdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_M0FLmto1EdqRBPR5WyT36A" type="OperationCompartment" element="_Mz_E8No1EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_M0FLm9o1EdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_M0FLnNo1EdqRBPR5WyT36A" visible="false" type="SignalCompartment" element="_Mz_E8No1EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_M0FLndo1EdqRBPR5WyT36A"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLClassifierStyle" xmi:id="_M0FLkdo1EdqRBPR5WyT36A" showStereotype="Label" useClassifierShape="true"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_M0FLkto1EdqRBPR5WyT36A" x="6678" y="318"/>
+ </children>
+ <children xmi:id="_TJHbANo1EdqRBPR5WyT36A" sourceEdges="_V7zlEdo1EdqRBPR5WyT36A" targetEdges="_cN4xsdo2EdqRBPR5WyT36A" element="_TI7NwNo1EdqRBPR5WyT36A">
+ <children xmi:id="_TJHbA9o1EdqRBPR5WyT36A" type="ImageCompartment" element="_TI7NwNo1EdqRBPR5WyT36A">
+ <layoutConstraint xmi:type="notation:Size" xmi:id="_TJHbBNo1EdqRBPR5WyT36A" width="530" height="530"/>
+ </children>
+ <children xmi:id="_TJHbBdo1EdqRBPR5WyT36A" type="Stereotype" element="_TI7NwNo1EdqRBPR5WyT36A"/>
+ <children xmi:id="_TJHbBto1EdqRBPR5WyT36A" type="Kind" element="_TI7NwNo1EdqRBPR5WyT36A"/>
+ <children xmi:id="_TJHbB9o1EdqRBPR5WyT36A" type="Name" element="_TI7NwNo1EdqRBPR5WyT36A"/>
+ <children xmi:id="_TJHbCNo1EdqRBPR5WyT36A" type="AttributeCompartment" element="_TI7NwNo1EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_TJHbCdo1EdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_TJHbCto1EdqRBPR5WyT36A" type="OperationCompartment" element="_TI7NwNo1EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_TJHbC9o1EdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_TJHbDNo1EdqRBPR5WyT36A" visible="false" type="SignalCompartment" element="_TI7NwNo1EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_TJHbDdo1EdqRBPR5WyT36A"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLClassifierStyle" xmi:id="_TJHbAdo1EdqRBPR5WyT36A" showStereotype="Label" useClassifierShape="true"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_TJHbAto1EdqRBPR5WyT36A" x="16854" y="318"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLDiagramStyle" xmi:id="_al1S89ovEdqRBPR5WyT36A"/>
+ <edges xmi:id="_hmIF4dovEdqRBPR5WyT36A" element="_hmIF4NovEdqRBPR5WyT36A" source="_fs1pANovEdqRBPR5WyT36A" target="_ePDcYdovEdqRBPR5WyT36A">
+ <children xmi:id="_hmIF5NovEdqRBPR5WyT36A" type="NameLabel" element="_hmIF4NovEdqRBPR5WyT36A">
+ <children xmi:id="_hmIF5tovEdqRBPR5WyT36A" type="Stereotype" element="_hmIF4NovEdqRBPR5WyT36A"/>
+ <children xmi:id="_hmIF59ovEdqRBPR5WyT36A" type="Name" element="_hmIF4NovEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_hmIF5dovEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_hmIF4tovEdqRBPR5WyT36A" routing="Tree" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_hmIF49ovEdqRBPR5WyT36A" points="[26, -31, -110, 148]$[140, -148, 4, 31]"/>
+ </edges>
+ <edges xmi:id="_mu9A4dovEdqRBPR5WyT36A" element="_mu9A4NovEdqRBPR5WyT36A" source="_ikr_4NovEdqRBPR5WyT36A" target="_ePDcYdovEdqRBPR5WyT36A">
+ <children xmi:id="_mu9A5NovEdqRBPR5WyT36A" type="NameLabel" element="_mu9A4NovEdqRBPR5WyT36A">
+ <children xmi:id="_mu9A5tovEdqRBPR5WyT36A" type="Stereotype" element="_mu9A4NovEdqRBPR5WyT36A"/>
+ <children xmi:id="_mu9A59ovEdqRBPR5WyT36A" type="Name" element="_mu9A4NovEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_mu9A5dovEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_mu9A4tovEdqRBPR5WyT36A" routing="Tree" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_mu9A49ovEdqRBPR5WyT36A" points="[-185, -820, 2937, 3916]$[-185, -3042, 2937, 1694]$[-3255, -3042, -133, 1694]$[-3255, -3916, -133, 820]"/>
+ </edges>
+ <edges xmi:id="_pe3jwNovEdqRBPR5WyT36A" element="_peM1YNovEdqRBPR5WyT36A" source="_fs1pANovEdqRBPR5WyT36A" target="_ePDcYdovEdqRBPR5WyT36A">
+ <children xmi:id="_pe3jw9ovEdqRBPR5WyT36A" type="NameLabel" element="_peM1YNovEdqRBPR5WyT36A">
+ <children xmi:id="_pe3jxdovEdqRBPR5WyT36A" type="Stereotype" element="_peM1YNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_pe3jxtovEdqRBPR5WyT36A" type="Name" element="_peM1YNovEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pe3jxNovEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_pe3jx9ovEdqRBPR5WyT36A" type="ToMultiplicityLabel" element="_peM1YtovEdqRBPR5WyT36A">
+ <children xmi:id="_pe3jydovEdqRBPR5WyT36A" type="ToMultiplicity" element="_peM1YtovEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pe3jyNovEdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_pe3jytovEdqRBPR5WyT36A" type="ToRoleLabel" element="_peM1YtovEdqRBPR5WyT36A">
+ <children xmi:id="_pe3jzNovEdqRBPR5WyT36A" type="ToRole" element="_peM1YtovEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pe3jy9ovEdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_pe3jzdovEdqRBPR5WyT36A" type="FromMultiplicityLabel" element="_peM1YdovEdqRBPR5WyT36A">
+ <children xmi:id="_pe3jz9ovEdqRBPR5WyT36A" type="FromMultiplicity" element="_peM1YdovEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pe3jztovEdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_pe3j0NovEdqRBPR5WyT36A" type="FromRoleLabel" element="_peM1YdovEdqRBPR5WyT36A">
+ <children xmi:id="_pe3j0tovEdqRBPR5WyT36A" type="FromRole" element="_peM1YdovEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pe3j0dovEdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_pe3j09ovEdqRBPR5WyT36A" type="ToQualifierLabel" element="_peM1YtovEdqRBPR5WyT36A">
+ <children xmi:id="_pe3j1dovEdqRBPR5WyT36A" type="QualifierCompartment" element="_peM1YtovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_pe3j1tovEdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pe3j1NovEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_pe3j19ovEdqRBPR5WyT36A" type="FromQualifierLabel" element="_peM1YdovEdqRBPR5WyT36A">
+ <children xmi:id="_pe3j2dovEdqRBPR5WyT36A" type="QualifierCompartment" element="_peM1YdovEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_pe3j2tovEdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pe3j2NovEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_pe3jwdovEdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_pe3jwtovEdqRBPR5WyT36A" points="[-317, -820, -3916, 3916]$[-1931, -4762, -5530, -26]$[2382, -4762, -1217, -26]"/>
+ </edges>
+ <edges xmi:id="_xInjYdovEdqRBPR5WyT36A" element="_xInjYNovEdqRBPR5WyT36A" source="_tZF9odovEdqRBPR5WyT36A" target="_fs1pANovEdqRBPR5WyT36A">
+ <children xmi:id="_xInjZNovEdqRBPR5WyT36A" type="NameLabel" element="_xInjYNovEdqRBPR5WyT36A">
+ <children xmi:id="_xInjZtovEdqRBPR5WyT36A" type="Stereotype" element="_xInjYNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_xInjZ9ovEdqRBPR5WyT36A" type="Name" element="_xInjYNovEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_xInjZdovEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_xInjYtovEdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_xInjY9ovEdqRBPR5WyT36A" points="[-4, -31, 1, 113]$[-4, -115, 1, 29]"/>
+ </edges>
+ <edges xmi:id="_3Ic-4NovEdqRBPR5WyT36A" element="_3IW4QNovEdqRBPR5WyT36A" source="_1y-ZsNovEdqRBPR5WyT36A" target="_z_m-oNovEdqRBPR5WyT36A">
+ <children xmi:id="_3Ic-49ovEdqRBPR5WyT36A" type="NameLabel" element="_3IW4QNovEdqRBPR5WyT36A">
+ <children xmi:id="_3Ic-5dovEdqRBPR5WyT36A" type="Stereotype" element="_3IW4QNovEdqRBPR5WyT36A"/>
+ <children xmi:id="_3Ic-5tovEdqRBPR5WyT36A" type="Name" element="_3IW4QNovEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_3Ic-5NovEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_3Ic-4dovEdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_3Ic-4tovEdqRBPR5WyT36A" points="[6, -24, -37, 154]$[-22, -170, -65, 8]"/>
+ </edges>
+ <edges xmi:id="_9XeF4tovEdqRBPR5WyT36A" element="_9XeF4NovEdqRBPR5WyT36A" source="_4WSrANovEdqRBPR5WyT36A" target="_z_m-oNovEdqRBPR5WyT36A">
+ <children xmi:id="_9XeF5dovEdqRBPR5WyT36A" type="NameLabel" element="_9XeF4NovEdqRBPR5WyT36A">
+ <children xmi:id="_9XeF59ovEdqRBPR5WyT36A" type="Stereotype" element="_9XeF4NovEdqRBPR5WyT36A"/>
+ <children xmi:id="_9XeF6NovEdqRBPR5WyT36A" type="Name" element="_9XeF4NovEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9XeF5tovEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_9XeF49ovEdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_9XeF5NovEdqRBPR5WyT36A" points="[-23, -23, 162, 151]$[-121, -170, 64, 4]"/>
+ </edges>
+ <edges xmi:id="_BkUg0dowEdqRBPR5WyT36A" element="_Bj8GUNowEdqRBPR5WyT36A" source="_tZF9odovEdqRBPR5WyT36A" target="_1y-ZsNovEdqRBPR5WyT36A">
+ <children xmi:id="_BkancNowEdqRBPR5WyT36A" type="NameLabel" element="_Bj8GUNowEdqRBPR5WyT36A">
+ <children xmi:id="_BkanctowEdqRBPR5WyT36A" type="Stereotype" element="_Bj8GUNowEdqRBPR5WyT36A"/>
+ <children xmi:id="_Bkanc9owEdqRBPR5WyT36A" type="Name" element="_Bj8GUNowEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_BkancdowEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_BkandNowEdqRBPR5WyT36A" type="ToMultiplicityLabel" element="_Bj8GUtowEdqRBPR5WyT36A">
+ <children xmi:id="_BkandtowEdqRBPR5WyT36A" type="ToMultiplicity" element="_Bj8GUtowEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_BkanddowEdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_Bkand9owEdqRBPR5WyT36A" type="ToRoleLabel" element="_Bj8GUtowEdqRBPR5WyT36A">
+ <children xmi:id="_BkanedowEdqRBPR5WyT36A" type="ToRole" element="_Bj8GUtowEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_BkaneNowEdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_BkanetowEdqRBPR5WyT36A" type="FromMultiplicityLabel" element="_Bj8GUdowEdqRBPR5WyT36A">
+ <children xmi:id="_BkanfNowEdqRBPR5WyT36A" type="FromMultiplicity" element="_Bj8GUdowEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_Bkane9owEdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_BkanfdowEdqRBPR5WyT36A" type="FromRoleLabel" element="_Bj8GUdowEdqRBPR5WyT36A">
+ <children xmi:id="_Bkanf9owEdqRBPR5WyT36A" type="FromRole" element="_Bj8GUdowEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_BkanftowEdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_BkangNowEdqRBPR5WyT36A" type="ToQualifierLabel" element="_Bj8GUtowEdqRBPR5WyT36A">
+ <children xmi:id="_BkangtowEdqRBPR5WyT36A" type="QualifierCompartment" element="_Bj8GUtowEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_Bkang9owEdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_BkangdowEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_BkanhNowEdqRBPR5WyT36A" type="FromQualifierLabel" element="_Bj8GUdowEdqRBPR5WyT36A">
+ <children xmi:id="_BkanhtowEdqRBPR5WyT36A" type="QualifierCompartment" element="_Bj8GUdowEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_Bkanh9owEdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_BkanhdowEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_BkUg0towEdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_BkUg09owEdqRBPR5WyT36A" points="[83, -24, -490, 123]$[486, -151, -87, -4]"/>
+ </edges>
+ <edges xmi:id="_Fd3lQdowEdqRBPR5WyT36A" element="_FdlRYNowEdqRBPR5WyT36A" source="_ePDcYdovEdqRBPR5WyT36A" target="_z_m-oNovEdqRBPR5WyT36A">
+ <children xmi:id="_Fd3lRNowEdqRBPR5WyT36A" type="NameLabel" element="_FdlRYNowEdqRBPR5WyT36A">
+ <children xmi:id="_Fd3lRtowEdqRBPR5WyT36A" type="Stereotype" element="_FdlRYNowEdqRBPR5WyT36A"/>
+ <children xmi:id="_Fd3lR9owEdqRBPR5WyT36A" type="Name" element="_FdlRYNowEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_Fd3lRdowEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_Fd3lSNowEdqRBPR5WyT36A" type="ToMultiplicityLabel" element="_FdlRYtowEdqRBPR5WyT36A">
+ <children xmi:id="_Fd3lStowEdqRBPR5WyT36A" type="ToMultiplicity" element="_FdlRYtowEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_Fd3lSdowEdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_Fd3lS9owEdqRBPR5WyT36A" type="ToRoleLabel" element="_FdlRYtowEdqRBPR5WyT36A">
+ <children xmi:id="_Fd3lTdowEdqRBPR5WyT36A" type="ToRole" element="_FdlRYtowEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_Fd3lTNowEdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_Fd3lTtowEdqRBPR5WyT36A" type="FromMultiplicityLabel" element="_FdlRYdowEdqRBPR5WyT36A">
+ <children xmi:id="_Fd3lUNowEdqRBPR5WyT36A" type="FromMultiplicity" element="_FdlRYdowEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_Fd3lT9owEdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_Fd3lUdowEdqRBPR5WyT36A" type="FromRoleLabel" element="_FdlRYdowEdqRBPR5WyT36A">
+ <children xmi:id="_Fd3lU9owEdqRBPR5WyT36A" type="FromRole" element="_FdlRYdowEdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_Fd3lUtowEdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_Fd3lVNowEdqRBPR5WyT36A" type="ToQualifierLabel" element="_FdlRYtowEdqRBPR5WyT36A">
+ <children xmi:id="_Fd3lVtowEdqRBPR5WyT36A" type="QualifierCompartment" element="_FdlRYtowEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_Fd3lV9owEdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_Fd3lVdowEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_Fd3lWNowEdqRBPR5WyT36A" type="FromQualifierLabel" element="_FdlRYdowEdqRBPR5WyT36A">
+ <children xmi:id="_Fd3lWtowEdqRBPR5WyT36A" type="QualifierCompartment" element="_FdlRYdowEdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_Fd3lW9owEdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_Fd3lWdowEdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_Fd3lQtowEdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_Fd3lQ9owEdqRBPR5WyT36A" points="[46, -11, -369, -9]$[351, -11, -64, -9]"/>
+ </edges>
+ <edges xmi:id="_R5Rjwdo1EdqRBPR5WyT36A" element="_R5RjwNo1EdqRBPR5WyT36A" source="_ePDcYdovEdqRBPR5WyT36A" target="_M0FLkNo1EdqRBPR5WyT36A">
+ <children xmi:id="_R5RjxNo1EdqRBPR5WyT36A" type="NameLabel" element="_R5RjwNo1EdqRBPR5WyT36A">
+ <children xmi:id="_R5Rjxto1EdqRBPR5WyT36A" type="Stereotype" element="_R5RjwNo1EdqRBPR5WyT36A"/>
+ <children xmi:id="_R5Rjx9o1EdqRBPR5WyT36A" type="Name" element="_R5RjwNo1EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_R5Rjxdo1EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_R5Rjwto1EdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_R5Rjw9o1EdqRBPR5WyT36A" points="[-2, -31, -2, 91]$[-2, -91, -2, 31]"/>
+ </edges>
+ <edges xmi:id="_V7zlEdo1EdqRBPR5WyT36A" element="_V7zlENo1EdqRBPR5WyT36A" source="_TJHbANo1EdqRBPR5WyT36A" target="_M0FLkNo1EdqRBPR5WyT36A">
+ <children xmi:id="_V7zlFNo1EdqRBPR5WyT36A" type="NameLabel" element="_V7zlENo1EdqRBPR5WyT36A">
+ <children xmi:id="_V7zlFto1EdqRBPR5WyT36A" type="Stereotype" element="_V7zlENo1EdqRBPR5WyT36A"/>
+ <children xmi:id="_V7zlF9o1EdqRBPR5WyT36A" type="Name" element="_V7zlENo1EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_V7zlFdo1EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_V7zlEto1EdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_V7zlE9o1EdqRBPR5WyT36A" points="[-73, 0, 339, 0]$[-457, 0, -45, 0]"/>
+ </edges>
+ <edges xmi:id="_cN4xsdo2EdqRBPR5WyT36A" targetEdges="_pdfmkNo2EdqRBPR5WyT36A" element="_cNskcNo2EdqRBPR5WyT36A" source="_z_m-oNovEdqRBPR5WyT36A" target="_TJHbANo1EdqRBPR5WyT36A">
+ <children xmi:id="_cN4xtNo2EdqRBPR5WyT36A" type="NameLabel" element="_cNskcNo2EdqRBPR5WyT36A">
+ <children xmi:id="_cN4xtto2EdqRBPR5WyT36A" type="Stereotype" element="_cNskcNo2EdqRBPR5WyT36A"/>
+ <children xmi:id="_cN4xt9o2EdqRBPR5WyT36A" type="Name" element="_cNskcNo2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_cN4xtdo2EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_cN4xuNo2EdqRBPR5WyT36A" type="ToMultiplicityLabel" element="_cNskcto2EdqRBPR5WyT36A">
+ <children xmi:id="_cN4xuto2EdqRBPR5WyT36A" type="ToMultiplicity" element="_cNskcto2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_cN4xudo2EdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_cN4xu9o2EdqRBPR5WyT36A" type="ToRoleLabel" element="_cNskcto2EdqRBPR5WyT36A">
+ <children xmi:id="_cN4xvdo2EdqRBPR5WyT36A" type="ToRole" element="_cNskcto2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_cN4xvNo2EdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_cN_fYNo2EdqRBPR5WyT36A" type="FromMultiplicityLabel" element="_cNskcdo2EdqRBPR5WyT36A">
+ <children xmi:id="_cN_fYto2EdqRBPR5WyT36A" type="FromMultiplicity" element="_cNskcdo2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_cN_fYdo2EdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_cN_fY9o2EdqRBPR5WyT36A" type="FromRoleLabel" element="_cNskcdo2EdqRBPR5WyT36A">
+ <children xmi:id="_cN_fZdo2EdqRBPR5WyT36A" type="FromRole" element="_cNskcdo2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_cN_fZNo2EdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_cN_fZto2EdqRBPR5WyT36A" type="ToQualifierLabel" element="_cNskcto2EdqRBPR5WyT36A">
+ <children xmi:id="_cN_faNo2EdqRBPR5WyT36A" type="QualifierCompartment" element="_cNskcto2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_cN_fado2EdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_cN_fZ9o2EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_cN_fato2EdqRBPR5WyT36A" type="FromQualifierLabel" element="_cNskcdo2EdqRBPR5WyT36A">
+ <children xmi:id="_cN_fbNo2EdqRBPR5WyT36A" type="QualifierCompartment" element="_cNskcdo2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_cN_fbdo2EdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_cN_fa9o2EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_cN4xsto2EdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_cN4xs9o2EdqRBPR5WyT36A" points="[-2, -29, 1, 91]$[26, -89, 29, 31]"/>
+ </edges>
+ <edges xmi:id="_pdfmkNo2EdqRBPR5WyT36A" element="_pdHMENo2EdqRBPR5WyT36A" source="_ePDcYdovEdqRBPR5WyT36A" target="_cN4xsdo2EdqRBPR5WyT36A">
+ <children xmi:id="_pdfml9o2EdqRBPR5WyT36A" type="ToMultiplicityLabel" element="_pdTZUdo2EdqRBPR5WyT36A">
+ <children xmi:id="_pdfmmdo2EdqRBPR5WyT36A" type="ToMultiplicity" element="_pdTZUdo2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pdfmmNo2EdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_pdfmmto2EdqRBPR5WyT36A" type="ToRoleLabel" element="_pdTZUdo2EdqRBPR5WyT36A">
+ <children xmi:id="_pdfmnNo2EdqRBPR5WyT36A" type="ToRole" element="_pdTZUdo2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pdfmm9o2EdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_pdfmndo2EdqRBPR5WyT36A" type="FromMultiplicityLabel" element="_pdTZUNo2EdqRBPR5WyT36A">
+ <children xmi:id="_pdfmn9o2EdqRBPR5WyT36A" type="FromMultiplicity" element="_pdTZUNo2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pdfmnto2EdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_pdfmoNo2EdqRBPR5WyT36A" type="FromRoleLabel" element="_pdTZUNo2EdqRBPR5WyT36A">
+ <children xmi:id="_pdfmoto2EdqRBPR5WyT36A" type="FromRole" element="_pdTZUNo2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pdfmodo2EdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_pdfmo9o2EdqRBPR5WyT36A" type="ToQualifierLabel" element="_pdTZUdo2EdqRBPR5WyT36A">
+ <children xmi:id="_pdfmpdo2EdqRBPR5WyT36A" type="QualifierCompartment" element="_pdTZUdo2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_pdfmpto2EdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pdfmpNo2EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_pdfmp9o2EdqRBPR5WyT36A" type="FromQualifierLabel" element="_pdTZUNo2EdqRBPR5WyT36A">
+ <children xmi:id="_pdfmqdo2EdqRBPR5WyT36A" type="QualifierCompartment" element="_pdTZUNo2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_pdfmqto2EdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_pdfmqNo2EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_pdfmq9o2EdqRBPR5WyT36A" element="_pdHMENo2EdqRBPR5WyT36A">
+ <children xmi:id="_pdfmrto2EdqRBPR5WyT36A" type="ImageCompartment" element="_pdHMENo2EdqRBPR5WyT36A">
+ <layoutConstraint xmi:type="notation:Size" xmi:id="_pdfmr9o2EdqRBPR5WyT36A" width="1320" height="1320"/>
+ </children>
+ <children xmi:id="_pdfmsNo2EdqRBPR5WyT36A" type="Stereotype" element="_pdHMENo2EdqRBPR5WyT36A"/>
+ <children xmi:id="_pdfmsdo2EdqRBPR5WyT36A" type="Name" element="_pdHMENo2EdqRBPR5WyT36A"/>
+ <children xmi:id="_pdfmsto2EdqRBPR5WyT36A" type="AttributeCompartment" element="_pdHMENo2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_pdfms9o2EdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_pdfmtNo2EdqRBPR5WyT36A" type="OperationCompartment" element="_pdHMENo2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_pdfmtdo2EdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_pdfmtto2EdqRBPR5WyT36A" visible="false" type="SignalCompartment" element="_pdHMENo2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_pdfmt9o2EdqRBPR5WyT36A"/>
+ </children>
+ <children xmi:id="_pdfmuNo2EdqRBPR5WyT36A" visible="false" type="StructureCompartment" element="_pdHMENo2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLShapeCompartmentStyle" xmi:id="_pdfmudo2EdqRBPR5WyT36A"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLShapeStyle" xmi:id="_pdfmrNo2EdqRBPR5WyT36A" showStereotype="Label"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_pdfmrdo2EdqRBPR5WyT36A" y="1323"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_pdfmkdo2EdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_pdfmkto2EdqRBPR5WyT36A" points="[46, 3, -366, 94]$[412, -91, 0, 0]"/>
+ <targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_pdrz0No2EdqRBPR5WyT36A" id="100"/>
+ </edges>
+ <edges xmi:id="_9PaR4No2EdqRBPR5WyT36A" element="_9PH-ANo2EdqRBPR5WyT36A" source="_4WSrANovEdqRBPR5WyT36A" target="_o2m3oNo0EdqRBPR5WyT36A">
+ <children xmi:id="_9PaR49o2EdqRBPR5WyT36A" type="NameLabel" element="_9PH-ANo2EdqRBPR5WyT36A">
+ <children xmi:id="_9PaR5do2EdqRBPR5WyT36A" type="Stereotype" element="_9PH-ANo2EdqRBPR5WyT36A"/>
+ <children xmi:id="_9PaR5to2EdqRBPR5WyT36A" type="Name" element="_9PH-ANo2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9PaR5No2EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_9PaR59o2EdqRBPR5WyT36A" type="ToMultiplicityLabel" element="_9PH-Ato2EdqRBPR5WyT36A">
+ <children xmi:id="_9PaR6do2EdqRBPR5WyT36A" type="ToMultiplicity" element="_9PH-Ato2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9PaR6No2EdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_9PaR6to2EdqRBPR5WyT36A" type="ToRoleLabel" element="_9PH-Ato2EdqRBPR5WyT36A">
+ <children xmi:id="_9PaR7No2EdqRBPR5WyT36A" type="ToRole" element="_9PH-Ato2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9PaR69o2EdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_9PaR7do2EdqRBPR5WyT36A" type="FromMultiplicityLabel" element="_9PH-Ado2EdqRBPR5WyT36A">
+ <children xmi:id="_9PaR79o2EdqRBPR5WyT36A" type="FromMultiplicity" element="_9PH-Ado2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9PaR7to2EdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_9PaR8No2EdqRBPR5WyT36A" type="FromRoleLabel" element="_9PH-Ado2EdqRBPR5WyT36A">
+ <children xmi:id="_9PaR8to2EdqRBPR5WyT36A" type="FromRole" element="_9PH-Ado2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9PaR8do2EdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_9PgYgNo2EdqRBPR5WyT36A" type="ToQualifierLabel" element="_9PH-Ato2EdqRBPR5WyT36A">
+ <children xmi:id="_9PgYgto2EdqRBPR5WyT36A" type="QualifierCompartment" element="_9PH-Ato2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_9PgYg9o2EdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9PgYgdo2EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_9PgYhNo2EdqRBPR5WyT36A" type="FromQualifierLabel" element="_9PH-Ado2EdqRBPR5WyT36A">
+ <children xmi:id="_9PgYhto2EdqRBPR5WyT36A" type="QualifierCompartment" element="_9PH-Ado2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_9PgYh9o2EdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9PgYhdo2EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_9PaR4do2EdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_9PaR4to2EdqRBPR5WyT36A" points="[12, -24, -94, 162]$[80, -155, -26, 31]"/>
+ </edges>
+ <edges xmi:id="_9-BEUNo2EdqRBPR5WyT36A" element="_99uwcNo2EdqRBPR5WyT36A" source="_1y-ZsNovEdqRBPR5WyT36A" target="_o2m3oNo0EdqRBPR5WyT36A">
+ <children xmi:id="_9-BEU9o2EdqRBPR5WyT36A" type="NameLabel" element="_99uwcNo2EdqRBPR5WyT36A">
+ <children xmi:id="_9-HK8No2EdqRBPR5WyT36A" type="Stereotype" element="_99uwcNo2EdqRBPR5WyT36A"/>
+ <children xmi:id="_9-HK8do2EdqRBPR5WyT36A" type="Name" element="_99uwcNo2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9-BEVNo2EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_9-HK8to2EdqRBPR5WyT36A" type="ToMultiplicityLabel" element="_99uwcto2EdqRBPR5WyT36A">
+ <children xmi:id="_9-HK9No2EdqRBPR5WyT36A" type="ToMultiplicity" element="_99uwcto2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9-HK89o2EdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_9-HK9do2EdqRBPR5WyT36A" type="ToRoleLabel" element="_99uwcto2EdqRBPR5WyT36A">
+ <children xmi:id="_9-HK99o2EdqRBPR5WyT36A" type="ToRole" element="_99uwcto2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9-HK9to2EdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_9-HK-No2EdqRBPR5WyT36A" type="FromMultiplicityLabel" element="_99uwcdo2EdqRBPR5WyT36A">
+ <children xmi:id="_9-HK-to2EdqRBPR5WyT36A" type="FromMultiplicity" element="_99uwcdo2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9-HK-do2EdqRBPR5WyT36A" y="397"/>
+ </children>
+ <children xmi:id="_9-HK-9o2EdqRBPR5WyT36A" type="FromRoleLabel" element="_99uwcdo2EdqRBPR5WyT36A">
+ <children xmi:id="_9-HK_do2EdqRBPR5WyT36A" type="FromRole" element="_99uwcdo2EdqRBPR5WyT36A"/>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9-HK_No2EdqRBPR5WyT36A" y="-397"/>
+ </children>
+ <children xmi:id="_9-HK_to2EdqRBPR5WyT36A" type="ToQualifierLabel" element="_99uwcto2EdqRBPR5WyT36A">
+ <children xmi:id="_9-HLANo2EdqRBPR5WyT36A" type="QualifierCompartment" element="_99uwcto2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_9-HLAdo2EdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9-HK_9o2EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <children xmi:id="_9-HLAto2EdqRBPR5WyT36A" type="FromQualifierLabel" element="_99uwcdo2EdqRBPR5WyT36A">
+ <children xmi:id="_9-HLBNo2EdqRBPR5WyT36A" type="QualifierCompartment" element="_99uwcdo2EdqRBPR5WyT36A">
+ <styles xmi:type="umlnotation:UMLListCompartmentStyle" xmi:id="_9-HLBdo2EdqRBPR5WyT36A"/>
+ </children>
+ <layoutConstraint xmi:type="notation:Location" xmi:id="_9-HLA9o2EdqRBPR5WyT36A" y="-185"/>
+ </children>
+ <styles xmi:type="umlnotation:UMLConnectorStyle" xmi:id="_9-BEUdo2EdqRBPR5WyT36A" showStereotype="Text"/>
+ <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_9-BEUto2EdqRBPR5WyT36A" points="[49, -24, -290, 162]$[404, -163, 65, 23]"/>
+ </edges>
+ </contents>
+ </eAnnotations>
+ <packageImport xmi:type="uml:ProfileApplication" xmi:id="_al1S9NovEdqRBPR5WyT36A">
+ <eAnnotations xmi:id="_al1S9dovEdqRBPR5WyT36A" source="attributes">
+ <details xmi:id="_al1S9tovEdqRBPR5WyT36A" key="version" value="0"/>
+ </eAnnotations>
+ <importedPackage xmi:type="uml:Profile" href="pathmap://UML2_PROFILES/Basic.profile.uml2#_6mFRgK86Edih9-GG5afQ0g"/>
+ <importedProfile href="pathmap://UML2_PROFILES/Basic.profile.uml2#_6mFRgK86Edih9-GG5afQ0g"/>
+ </packageImport>
+ <packageImport xmi:type="uml:ProfileApplication" xmi:id="_al1S99ovEdqRBPR5WyT36A">
+ <eAnnotations xmi:id="_al1S-NovEdqRBPR5WyT36A" source="attributes">
+ <details xmi:id="_al1S-dovEdqRBPR5WyT36A" key="version" value="0"/>
+ </eAnnotations>
+ <importedPackage xmi:type="uml:Profile" href="pathmap://UML2_PROFILES/Intermediate.profile.uml2#_Cz7csK87Edih9-GG5afQ0g"/>
+ <importedProfile href="pathmap://UML2_PROFILES/Intermediate.profile.uml2#_Cz7csK87Edih9-GG5afQ0g"/>
+ </packageImport>
+ <packageImport xmi:type="uml:ProfileApplication" xmi:id="_al1S-tovEdqRBPR5WyT36A">
+ <eAnnotations xmi:id="_al1S-9ovEdqRBPR5WyT36A" source="attributes">
+ <details xmi:id="_al1S_NovEdqRBPR5WyT36A" key="version" value="0"/>
+ </eAnnotations>
+ <importedPackage xmi:type="uml:Profile" href="pathmap://UML2_PROFILES/Complete.profile.uml2#_M7pTkK87Edih9-GG5afQ0g"/>
+ <importedProfile href="pathmap://UML2_PROFILES/Complete.profile.uml2#_M7pTkK87Edih9-GG5afQ0g"/>
+ </packageImport>
+ <packageImport xmi:type="uml:ProfileApplication" xmi:id="_al1S_dovEdqRBPR5WyT36A">
+ <eAnnotations xmi:id="_al1S_tovEdqRBPR5WyT36A" source="attributes">
+ <details xmi:id="_al1S_9ovEdqRBPR5WyT36A" key="version" value="0"/>
+ </eAnnotations>
+ <importedPackage xmi:type="uml:Profile" href="pathmap://UML2_MSL_PROFILES/Default.epx#_a_S3wNWLEdiy4IqP8whjFA?Default"/>
+ <importedProfile href="pathmap://UML2_MSL_PROFILES/Default.epx#_a_S3wNWLEdiy4IqP8whjFA?Default"/>
+ </packageImport>
+ <packageImport xmi:type="uml:ProfileApplication" xmi:id="_al1TANovEdqRBPR5WyT36A">
+ <eAnnotations xmi:id="_al1TAdovEdqRBPR5WyT36A" source="attributes">
+ <details xmi:id="_al1TAtovEdqRBPR5WyT36A" key="version" value="0"/>
+ </eAnnotations>
+ <importedPackage xmi:type="uml:Profile" href="pathmap://UML2_MSL_PROFILES/Deployment.epx#_vjbuwOvHEdiDX5bji0iVSA?Deployment"/>
+ <importedProfile href="pathmap://UML2_MSL_PROFILES/Deployment.epx#_vjbuwOvHEdiDX5bji0iVSA?Deployment"/>
+ </packageImport>
+ <packageImport xmi:id="_al1TA9ovEdqRBPR5WyT36A">
+ <importedPackage xmi:type="uml:Model" href="pathmap://UML2_LIBRARIES/UML2PrimitiveTypes.library.uml2#_EfRZoK86EdieaYgxtVWN8Q"/>
+ </packageImport>
+ <ownedMember xmi:type="uml:Interface" xmi:id="_ePDcYNovEdqRBPR5WyT36A" name="Context">
+ <generalization xmi:id="_R5RjwNo1EdqRBPR5WyT36A" general="_Mz_E8No1EdqRBPR5WyT36A"/>
+ <ownedAttribute xmi:id="_FdlRYdowEdqRBPR5WyT36A" name="scopecontext" visibility="private" type="_z_g4ANovEdqRBPR5WyT36A" association="_FdlRYNowEdqRBPR5WyT36A">
+ <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_FdlRZNowEdqRBPR5WyT36A" value="1"/>
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_FdlRY9owEdqRBPR5WyT36A"/>
+ </ownedAttribute>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Interface" xmi:id="_fsviYNovEdqRBPR5WyT36A" name="CompositeContext">
+ <generalization xmi:id="_hmIF4NovEdqRBPR5WyT36A" general="_ePDcYNovEdqRBPR5WyT36A"/>
+ <ownedAttribute xmi:id="_peM1YdovEdqRBPR5WyT36A" name="context" visibility="private" type="_ePDcYNovEdqRBPR5WyT36A" association="_peM1YNovEdqRBPR5WyT36A" aggregation="composite">
+ <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_peM1ZNovEdqRBPR5WyT36A" value="-1"/>
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_peM1Y9ovEdqRBPR5WyT36A"/>
+ </ownedAttribute>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Interface" xmi:id="_ikl5QNovEdqRBPR5WyT36A" name="AtomicContext">
+ <generalization xmi:id="_mu9A4NovEdqRBPR5WyT36A" general="_ePDcYNovEdqRBPR5WyT36A"/>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Association" xmi:id="_peM1YNovEdqRBPR5WyT36A" memberEnd="_peM1YdovEdqRBPR5WyT36A _peM1YtovEdqRBPR5WyT36A">
+ <ownedEnd xmi:id="_peM1YtovEdqRBPR5WyT36A" visibility="private" type="_fsviYNovEdqRBPR5WyT36A" association="_peM1YNovEdqRBPR5WyT36A"/>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Interface" xmi:id="_tZF9oNovEdqRBPR5WyT36A" name="DeploymentContext">
+ <generalization xmi:id="_xInjYNovEdqRBPR5WyT36A" general="_fsviYNovEdqRBPR5WyT36A"/>
+ <ownedAttribute xmi:id="_Bj8GUdowEdqRBPR5WyT36A" name="modulescopecontext" visibility="private" type="_1yyMcNovEdqRBPR5WyT36A" association="_Bj8GUNowEdqRBPR5WyT36A">
+ <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_Bj8GVNowEdqRBPR5WyT36A" value="1"/>
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_Bj8GU9owEdqRBPR5WyT36A"/>
+ </ownedAttribute>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Interface" xmi:id="_z_g4ANovEdqRBPR5WyT36A" name="ScopeContext">
+ <ownedAttribute xmi:id="_cNskcdo2EdqRBPR5WyT36A" name="instancewrapper" visibility="private" type="_TI7NwNo1EdqRBPR5WyT36A" association="_cNskcNo2EdqRBPR5WyT36A">
+ <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_cNskdNo2EdqRBPR5WyT36A" value="1"/>
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_cNskc9o2EdqRBPR5WyT36A"/>
+ </ownedAttribute>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Class" xmi:id="_1yyMcNovEdqRBPR5WyT36A" name="ModuleScopeContext" clientDependency="_3IW4QNovEdqRBPR5WyT36A">
+ <implementation xmi:id="_3IW4QNovEdqRBPR5WyT36A" client="_1yyMcNovEdqRBPR5WyT36A" supplier="_z_g4ANovEdqRBPR5WyT36A" realizingClassifier="_z_g4ANovEdqRBPR5WyT36A" contract="_z_g4ANovEdqRBPR5WyT36A">
+ <mapping xmi:id="_3IW4QdovEdqRBPR5WyT36A"/>
+ </implementation>
+ <ownedAttribute xmi:id="_99uwcdo2EdqRBPR5WyT36A" name="scoperegistry" visibility="private" type="_o2gxANo0EdqRBPR5WyT36A" association="_99uwcNo2EdqRBPR5WyT36A">
+ <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_99uwdNo2EdqRBPR5WyT36A" value="1"/>
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_99uwc9o2EdqRBPR5WyT36A"/>
+ </ownedAttribute>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Class" xmi:id="_4WMkYNovEdqRBPR5WyT36A" name="HTTPSessionScopeContext" clientDependency="_9XeF4NovEdqRBPR5WyT36A">
+ <implementation xmi:id="_9XeF4NovEdqRBPR5WyT36A" client="_4WMkYNovEdqRBPR5WyT36A" supplier="_z_g4ANovEdqRBPR5WyT36A" realizingClassifier="_z_g4ANovEdqRBPR5WyT36A" contract="_z_g4ANovEdqRBPR5WyT36A">
+ <mapping xmi:id="_9XeF4dovEdqRBPR5WyT36A"/>
+ </implementation>
+ <ownedAttribute xmi:id="_9PH-Ado2EdqRBPR5WyT36A" name="scoperegistry" visibility="private" type="_o2gxANo0EdqRBPR5WyT36A" association="_9PH-ANo2EdqRBPR5WyT36A">
+ <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_9PH-BNo2EdqRBPR5WyT36A" value="1"/>
+ <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_9PH-A9o2EdqRBPR5WyT36A"/>
+ </ownedAttribute>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Association" xmi:id="_Bj8GUNowEdqRBPR5WyT36A" memberEnd="_Bj8GUdowEdqRBPR5WyT36A _Bj8GUtowEdqRBPR5WyT36A">
+ <ownedEnd xmi:id="_Bj8GUtowEdqRBPR5WyT36A" visibility="private" type="_tZF9oNovEdqRBPR5WyT36A" association="_Bj8GUNowEdqRBPR5WyT36A"/>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Association" xmi:id="_FdlRYNowEdqRBPR5WyT36A" memberEnd="_FdlRYdowEdqRBPR5WyT36A _FdlRYtowEdqRBPR5WyT36A">
+ <ownedEnd xmi:id="_FdlRYtowEdqRBPR5WyT36A" visibility="private" type="_ePDcYNovEdqRBPR5WyT36A" association="_FdlRYNowEdqRBPR5WyT36A"/>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Interface" xmi:id="_o2gxANo0EdqRBPR5WyT36A" name="ScopeRegistry"/>
+ <ownedMember xmi:type="uml:Interface" xmi:id="_Mz_E8No1EdqRBPR5WyT36A" name="Lifecycle"/>
+ <ownedMember xmi:type="uml:Interface" xmi:id="_TI7NwNo1EdqRBPR5WyT36A" name="InstanceWrapper">
+ <generalization xmi:id="_V7zlENo1EdqRBPR5WyT36A" general="_Mz_E8No1EdqRBPR5WyT36A"/>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Association" xmi:id="_cNskcNo2EdqRBPR5WyT36A" memberEnd="_cNskcdo2EdqRBPR5WyT36A _cNskcto2EdqRBPR5WyT36A">
+ <ownedEnd xmi:id="_cNskcto2EdqRBPR5WyT36A" visibility="private" type="_z_g4ANovEdqRBPR5WyT36A" association="_cNskcNo2EdqRBPR5WyT36A"/>
+ </ownedMember>
+ <ownedMember xmi:type="uml:AssociationClass" xmi:id="_pdHMENo2EdqRBPR5WyT36A" name="AssociationClass1" memberEnd="_pdTZUNo2EdqRBPR5WyT36A _pdTZUdo2EdqRBPR5WyT36A">
+ <ownedEnd xmi:id="_pdTZUNo2EdqRBPR5WyT36A" visibility="private" type="_cNskcNo2EdqRBPR5WyT36A" association="_pdHMENo2EdqRBPR5WyT36A"/>
+ <ownedEnd xmi:id="_pdTZUdo2EdqRBPR5WyT36A" visibility="private" type="_ePDcYNovEdqRBPR5WyT36A" association="_pdHMENo2EdqRBPR5WyT36A"/>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Association" xmi:id="_9PH-ANo2EdqRBPR5WyT36A" memberEnd="_9PH-Ado2EdqRBPR5WyT36A _9PH-Ato2EdqRBPR5WyT36A">
+ <ownedEnd xmi:id="_9PH-Ato2EdqRBPR5WyT36A" visibility="private" type="_4WMkYNovEdqRBPR5WyT36A" association="_9PH-ANo2EdqRBPR5WyT36A"/>
+ </ownedMember>
+ <ownedMember xmi:type="uml:Association" xmi:id="_99uwcNo2EdqRBPR5WyT36A" memberEnd="_99uwcdo2EdqRBPR5WyT36A _99uwcto2EdqRBPR5WyT36A">
+ <ownedEnd xmi:id="_99uwcto2EdqRBPR5WyT36A" visibility="private" type="_1yyMcNovEdqRBPR5WyT36A" association="_99uwcNo2EdqRBPR5WyT36A"/>
+ </ownedMember>
+</uml:Model>
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/AbstractLifecycle.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/AbstractLifecycle.java
new file mode 100644
index 0000000000..e8597a55fc
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/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.spi;
+
+/**
+ * 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/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/CoreRuntimeException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/CoreRuntimeException.java
new file mode 100644
index 0000000000..641a4e5d21
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/CoreRuntimeException.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.spi;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * The root exception for the runtime package. Exceptions occurring in the runtime are generally non-recoverable
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class CoreRuntimeException extends TuscanyRuntimeException {
+
+ public CoreRuntimeException() {
+ super();
+ }
+
+ public CoreRuntimeException(String message) {
+ super(message);
+ }
+
+
+ protected CoreRuntimeException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public CoreRuntimeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+
+ protected CoreRuntimeException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+
+ public CoreRuntimeException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/InvalidNameException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/InvalidNameException.java
new file mode 100644
index 0000000000..28bc8652b2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/InvalidNameException.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.spi;
+
+/**
+ * Denotes an invalid name
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidNameException extends CoreRuntimeException {
+
+ public InvalidNameException() {
+ super();
+ }
+
+ public InvalidNameException(String message) {
+ super(message);
+ }
+
+ public InvalidNameException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public InvalidNameException(Throwable cause) {
+ super(cause);
+ }
+
+}
+
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/Lifecycle.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/Lifecycle.java
new file mode 100644
index 0000000000..e8a0448e44
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/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.spi;
+
+/**
+ * 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/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/ObjectCreationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/ObjectCreationException.java
new file mode 100644
index 0000000000..580e928000
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/ObjectCreationException.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.spi;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * Denotes an error creating a new object instance
+ *
+ * @version $Rev$ $Date$
+ */
+public class ObjectCreationException extends TuscanyRuntimeException {
+ private static final long serialVersionUID = -6423113430265944499L;
+
+ public ObjectCreationException() {
+ super();
+ }
+
+ public ObjectCreationException(String message) {
+ super(message);
+ }
+
+ public ObjectCreationException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public ObjectCreationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ObjectCreationException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+
+ public ObjectCreationException(Throwable cause) {
+ super(cause);
+ }
+
+}
+
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/ObjectFactory.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/ObjectFactory.java
new file mode 100644
index 0000000000..d505e14f61
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/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.spi;
+
+/**
+ * Implementations create new instances of a particular type
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ObjectFactory<T> {
+
+ /**
+ * Return a instance of the type that this factory creates.
+ *
+ * @return a instance from this factory
+ */
+ T getInstance() throws ObjectCreationException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/QualifiedName.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/QualifiedName.java
new file mode 100644
index 0000000000..25e2dbbc65
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/QualifiedName.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.spi;
+
+/**
+ * An evaluated name consisting of a part/port pair. In the runtime, a part generally 'contains' or 'provides' ports
+ * such as a component/service point or a component/reference pair.
+ *
+ * @version $Rev$ $Date$
+ */
+public class QualifiedName {
+ public static final String NAME_SEPARATOR = "/";
+
+ private final String qName;
+ private final String fragment;
+ private final String partName;
+ private final String portName;
+
+ /**
+ * Constructs a new qualified name in the form of part/port where part is the parent context and port represents a
+ * child, which is either a service in the case of an atomic context or a contained context in the case of a
+ * composite.
+ *
+ * @throws InvalidNameException if the name is in an invalid format
+ */
+ public QualifiedName(String qualifiedName) throws InvalidNameException {
+ String[] parts = qualifiedName.split(NAME_SEPARATOR);
+ if (parts.length == 1) {
+ partName = parts[0];
+ portName = null;
+ qName = partName;
+ fragment = partName;
+ } else if (parts.length == 2) {
+ partName = parts[0];
+ portName = parts[1];
+ qName = partName + '/' + portName;
+ fragment = partName + '#' + portName;
+ } else {
+ throw new InvalidNameException(qualifiedName);
+ }
+ }
+
+ /**
+ * Constructs a qualified name using the given part/port combination
+ *
+ * @param partName the part name
+ * @param portName the port name
+ */
+ public QualifiedName(String partName, String portName) {
+ this.partName = partName;
+ this.portName = portName;
+ if (portName == null) {
+ qName = partName;
+ fragment = partName;
+ } else {
+ qName = partName + '/' + portName;
+ fragment = partName + '#' + portName;
+ }
+ }
+
+ /**
+ * Returns the parsed part name
+ */
+ public String getPartName() {
+ return partName;
+ }
+
+ /**
+ * Returns the parsed port name if the original is of the compound for part/port
+ */
+ public String getPortName() {
+ return portName;
+ }
+
+ /**
+ * Returns the full part/port name pair
+ */
+ public String getQualifiedName() {
+ return qName;
+ }
+
+ public String getFragment() {
+ return fragment;
+ }
+
+ public String toString() {
+ return qName;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/bootstrap/ComponentNames.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/bootstrap/ComponentNames.java
new file mode 100644
index 0000000000..347c4f4d0b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/bootstrap/ComponentNames.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.spi.bootstrap;
+
+import java.net.URI;
+
+/**
+ * Class that defines the names of well known component
+ *
+ * @version $Rev$ $Date$
+ */
+public final class ComponentNames {
+ /**
+ * The name of the component that forms the root of the runtime tree.
+ */
+ public static final URI TUSCANY_RUNTIME = URI.create("tuscany.runtime");
+
+ /**
+ * The name of the component that is the root of the application composite tree.
+ */
+ public static final URI TUSCANY_APPLICATION_ROOT = URI.create("sca://root.application/");
+
+ /**
+ * The name of the component that is the root of the system composite tree.
+ */
+ public static final URI TUSCANY_SYSTEM_ROOT = URI.create("sca://root.system/");
+
+ /**
+ * The name of the top-level component in the system composite tree.
+ */
+ public static final URI TUSCANY_SYSTEM = TUSCANY_SYSTEM_ROOT.resolve("main/");
+
+ /**
+ * The name of the component that contains the deployer.
+ */
+ public static final URI TUSCANY_DEPLOYER = TUSCANY_SYSTEM.resolve("deployer");
+
+ /**
+ * The name of the component that contains the deployer.
+ */
+ public static final URI TUSCANY_WIRE_SERVICE = TUSCANY_SYSTEM.resolve("proxyService");
+
+ private ComponentNames() {
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BindingBuilder.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BindingBuilder.java
new file mode 100644
index 0000000000..4b63f6d7e9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BindingBuilder.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.spi.builder;
+
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.model.BindingDefinition;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+/**
+ * Responsible for processing a service or reference in an assembly configured with a particular binding. The builder
+ * will create and return corresponding {@link org.apache.tuscany.spi.component.ServiceBinding} or {@link
+ * org.apache.tuscany.spi.component.ReferenceBinding}
+ *
+ * @version $Rev$ $Date$
+ */
+public interface BindingBuilder<B extends BindingDefinition> {
+
+ /**
+ * Creates a service binding
+ *
+ * @param serviceDefinition the service the binding is configured for
+ * @param bindingDefinition the binding definition
+ * @param context the current deployment context
+ * @return a service binding
+ * @throws BuilderException
+ */
+ ServiceBinding build(ServiceDefinition serviceDefinition, B bindingDefinition, DeploymentContext context)
+ throws BuilderException;
+
+ /**
+ * Creates a reference binding
+ *
+ * @param referenceDefinition the reference the binding is configured for
+ * @param bindingDefinition the binding definition
+ * @param context the current deployment context
+ * @return a reference binding
+ * @throws BuilderException
+ */
+ ReferenceBinding build(ReferenceDefinition referenceDefinition, B bindingDefinition, DeploymentContext context)
+ throws BuilderException;
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/Builder.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/Builder.java
new file mode 100644
index 0000000000..4433a4689c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/Builder.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.spi.builder;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+/**
+ * Implementations build <code>SCAObject</code> types from model objects.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Builder {
+ /**
+ * Builds a <code>Component</code> from a <code>ComponentDefinition</code>
+ *
+ * @param definition the component definition as parsed from an SCA assembly
+ * @param context the current deployment context
+ * @return the newly created component
+ * @throws BuilderException
+ */
+ <I extends Implementation<?>> Component build(ComponentDefinition<I> definition, DeploymentContext context)
+ throws BuilderException;
+
+ /**
+ * Builds a <code>Service</code> and its bindings from a <code>BoundServiceDefinition</code>
+ *
+ * @param definition the service definition as parsed from an SCA assembly
+ * @param context the current deployment context
+ * @return the newly created service
+ * @throws BuilderException
+ */
+ Service build(ServiceDefinition definition, DeploymentContext context) throws BuilderException;
+
+ /**
+ * Builds a <code>Reference</code> and its bindings from a <code>BoundReferenceDefinition</code>
+ *
+ * @param definition the reference definition as parsed from an SCA assembly
+ * @param context the current deployment context
+ * @return the newly created reference
+ * @throws BuilderException
+ */
+ Reference build(ReferenceDefinition definition, DeploymentContext context) throws BuilderException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderConfigException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderConfigException.java
new file mode 100644
index 0000000000..6e9f2ef95d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderConfigException.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.spi.builder;
+
+/**
+ * Represents an error processing an assembly model
+ *
+ * @version $Rev$ $Date$
+ */
+public class BuilderConfigException extends BuilderException {
+
+ public BuilderConfigException() {
+ super();
+ }
+
+ public BuilderConfigException(String message) {
+ super(message);
+ }
+
+ public BuilderConfigException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public BuilderConfigException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public BuilderConfigException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderException.java
new file mode 100644
index 0000000000..846d52492c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderException.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.spi.builder;
+
+import org.apache.tuscany.api.TuscanyException;
+
+/**
+ * The root exception for the builder package. Builder exceptions denote a non-recoverable failure.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class BuilderException extends TuscanyException {
+
+ public BuilderException() {
+ super();
+ }
+
+ public BuilderException(String message) {
+ super(message);
+ }
+
+
+ protected BuilderException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public BuilderException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ protected BuilderException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+
+ public BuilderException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderInstantiationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderInstantiationException.java
new file mode 100644
index 0000000000..30957635db
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderInstantiationException.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.spi.builder;
+
+/**
+ * Denotes an error instantiating an <code>SCAObject</code>
+ *
+ * @version $Rev$ $Date$
+ */
+public class BuilderInstantiationException extends BuilderException {
+
+ public BuilderInstantiationException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public BuilderInstantiationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public BuilderInstantiationException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderRegistry.java
new file mode 100644
index 0000000000..c4ecdfa35b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/BuilderRegistry.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.spi.builder;
+
+import org.apache.tuscany.spi.model.BindingDefinition;
+import org.apache.tuscany.spi.model.Implementation;
+
+/**
+ * Maintains a registry of builders in the runtime, dispatching to the appropriate one as an assembly model is processed
+ * into runtime artifacts
+ *
+ * @version $Rev$ $Date$
+ */
+public interface BuilderRegistry extends Builder {
+
+ /**
+ * Register a builder for an implementation type.
+ *
+ * @param implClass the type of implementation that this builder can handle
+ * @param builder the builder to be registered
+ */
+ <I extends Implementation<?>> void register(Class<I> implClass, ComponentBuilder<I> builder);
+
+ /**
+ * Unregister a builder for an implementation type.
+ *
+ * @param implClass the implementation whose builder should be unregistered
+ */
+ <I extends Implementation<?>> void unregister(Class<I> implClass);
+
+ /**
+ * Register a binding builder for a binding type
+ *
+ * @param implClass the binding type
+ * @param builder the buinder to be registered
+ */
+ <B extends BindingDefinition> void register(Class<B> implClass, BindingBuilder<B> builder);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/ComponentBuilder.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/ComponentBuilder.java
new file mode 100644
index 0000000000..b381adddc4
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/ComponentBuilder.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.spi.builder;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Implementation;
+
+/**
+ * Responsible for building a {@link Component} from an component definition
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ComponentBuilder<I extends Implementation<?>> {
+
+ /**
+ * Builds the component
+ *
+ * @param componentDefinition the component definition
+ * @param context the deployment context
+ * @return the built component
+ * @throws BuilderException
+ */
+ Component build(ComponentDefinition<I> componentDefinition, DeploymentContext context) throws BuilderException;
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/Connector.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/Connector.java
new file mode 100644
index 0000000000..4ac762acfb
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/Connector.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.spi.builder;
+
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.physical.PhysicalWireDefinition;
+
+/**
+ * Implementations are responsible for creating a wires between source and target artifacts
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public interface Connector {
+
+ /**
+ * Recursively connects component references and its children. This method will eventially be replaced by one that
+ * just takes a WireDefinition
+ *
+ * @param definition the component definition to connect
+ * @throws WiringException
+ * @deprecated
+ */
+ void connect(ComponentDefinition<? extends Implementation<?>> definition) throws WiringException;
+
+ /**
+ * Placeholder for the connect operation using federated deployment
+ *
+ * @param definition metadata describing the wire to create
+ * @throws WiringException
+ */
+ void connect(PhysicalWireDefinition definition) throws BuilderException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/InvalidServiceInterfaceException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/InvalidServiceInterfaceException.java
new file mode 100644
index 0000000000..78bb5a5cc8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/InvalidServiceInterfaceException.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.spi.builder;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InvalidServiceInterfaceException extends BuilderConfigException {
+ private final Class<?> interfaceClass;
+
+ public InvalidServiceInterfaceException(String message, Class<?> interfaceClass) {
+ super(message);
+ this.interfaceClass = interfaceClass;
+ }
+
+ public Class<?> getInterfaceClass() {
+ return interfaceClass;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/MissingWireTargetException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/MissingWireTargetException.java
new file mode 100644
index 0000000000..dcb0068b9d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/MissingWireTargetException.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.spi.builder;
+
+import java.net.URI;
+
+/**
+ * Denotes a missing wire target in an assembly
+ *
+ * @version $Rev$ $Date$
+ */
+public class MissingWireTargetException extends WiringException {
+
+ public MissingWireTargetException(String message) {
+ super(message);
+ }
+
+ public MissingWireTargetException(String message, URI sourceUri, URI targetUri) {
+ super(message, sourceUri, targetUri);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/ScopeNotFoundException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/ScopeNotFoundException.java
new file mode 100644
index 0000000000..acf8dadda6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/ScopeNotFoundException.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.spi.builder;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ScopeNotFoundException extends BuilderConfigException {
+
+ public ScopeNotFoundException(String scope) {
+ super("Scope not found", scope);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/WiringException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/WiringException.java
new file mode 100644
index 0000000000..1ba2a92d53
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/WiringException.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.spi.builder;
+
+import java.net.URI;
+
+
+/**
+ * Denotes a general error raised during wiring
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class WiringException extends BuilderException {
+ private final URI sourceUri;
+ private final URI targetUri;
+
+ protected WiringException(String message) {
+ super(message);
+ sourceUri = null;
+ targetUri = null;
+ }
+
+ protected WiringException(String message, URI sourceUri, URI targetUri) {
+ super(message);
+ this.sourceUri = sourceUri;
+ this.targetUri = targetUri;
+ }
+
+ protected WiringException(String message, URI sourceUri, URI targetUri, Throwable cause) {
+ super(message, cause);
+ this.sourceUri = sourceUri;
+ this.targetUri = targetUri;
+ }
+
+ protected WiringException(String message, String identifier, URI sourceUri, URI targetUri) {
+ super(message, identifier);
+ this.sourceUri = sourceUri;
+ this.targetUri = targetUri;
+ }
+
+
+ protected WiringException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ sourceUri = null;
+ targetUri = null;
+ }
+
+ /**
+ * Returns the source name for the wire
+ *
+ * @return the source name the source name for the wire
+ */
+ public URI getSourceUri() {
+ return sourceUri;
+ }
+
+ /**
+ * Returns the target name for the wire
+ *
+ * @return the target name the source name for the wire
+ */
+ public URI getTargetUri() {
+ return targetUri;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/interceptor/InterceptorBuilder.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/interceptor/InterceptorBuilder.java
new file mode 100644
index 0000000000..bf26c66c2d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/interceptor/InterceptorBuilder.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.spi.builder.interceptor;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.model.physical.PhysicalInterceptorDefinition;
+import org.apache.tuscany.spi.wire.Interceptor;
+
+/**
+ * Implementations return an interceptor for a given
+ *
+ * @version $Rev$ $Date$
+ */
+public interface InterceptorBuilder {
+
+ Interceptor build(PhysicalInterceptorDefinition definition) throws BuilderException;
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/interceptor/InterceptorBuilderRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/interceptor/InterceptorBuilderRegistry.java
new file mode 100644
index 0000000000..7a2915e956
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/interceptor/InterceptorBuilderRegistry.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.spi.builder.interceptor;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.model.physical.PhysicalInterceptorDefinition;
+import org.apache.tuscany.spi.wire.Interceptor;
+
+/**
+ * A registry of interceptor builders that performs a dispatch to a builder based on an interceptor definition QName
+ *
+ * @version $Rev$ $Date$
+ */
+public interface InterceptorBuilderRegistry {
+
+ /**
+ * Register a interceptor builder for the given QName
+ *
+ * @param name the QName associated with the builder
+ * @param builder the builder to register
+ */
+ void register(QName name, InterceptorBuilder builder);
+
+ /**
+ * Unregister a interceptor builder for the given QName
+ *
+ * @param name the QName associated with the builder to unregister
+ */
+ void unregister(QName name);
+
+ /**
+ * Dispatches to an interceptor builder matching the definition QName
+ *
+ * @param definition the interceptor definition to build from
+ * @return an interceptor matching the given definition
+ * @throws BuilderException if an error ocurrs during the dispatch or build
+ */
+ Interceptor build(PhysicalInterceptorDefinition definition) throws BuilderException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/PhysicalComponentBuilder.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/PhysicalComponentBuilder.java
new file mode 100644
index 0000000000..065b7e793c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/PhysicalComponentBuilder.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.spi.builder.physical;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.model.physical.PhysicalComponentDefinition;
+
+/**
+ * Interface for building components from physical component definitions.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface PhysicalComponentBuilder<PCD extends PhysicalComponentDefinition, C extends Component> {
+
+ /**
+ * Builds a component from its physical component definition.
+ *
+ * @param componentDefinition Physical component definition of the component
+ * to be built.
+ * @return A component instance that is ready to go live.
+ * @throws BuilderException If unable to build the component.
+ */
+ C build(PCD componentDefinition) throws BuilderException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/PhysicalComponentBuilderRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/PhysicalComponentBuilderRegistry.java
new file mode 100644
index 0000000000..dc6ddb5f4b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/PhysicalComponentBuilderRegistry.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.spi.builder.physical;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.model.physical.PhysicalComponentDefinition;
+
+/**
+ * A registry of physical component builders.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface PhysicalComponentBuilderRegistry {
+
+ /**
+ * Registers a physical component builder.
+ *
+ * @param <PCD> Type of the physical component definition.
+ * @param definitionClass Class of the physical component definition.
+ * @param builder Builder for the physical component definition.
+ */
+ <PCD extends PhysicalComponentDefinition, C extends Component>
+ void register(Class<?> definitionClass,
+ PhysicalComponentBuilder<PCD, C> builder);
+
+ /**
+ * Builds a physical component from component definition.
+ *
+ * @param componentDefinition Component definition.
+ * @return Component to be built.
+ */
+ Component build(PhysicalComponentDefinition componentDefinition) throws BuilderException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/WireAttachException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/WireAttachException.java
new file mode 100644
index 0000000000..3e76d987fa
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/WireAttachException.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.spi.builder.physical;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.builder.WiringException;
+
+/**
+ * Thrown when an error is encountered attaching a wire
+ *
+ * @version $Rev$ $Date$
+ */
+public class WireAttachException extends WiringException {
+ public WireAttachException(String message, URI sourceUri, URI targetUri, Throwable cause) {
+ super(message, sourceUri, targetUri, cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/WireAttacher.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/WireAttacher.java
new file mode 100644
index 0000000000..2727b82054
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/WireAttacher.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.spi.builder.physical;
+
+import org.apache.tuscany.spi.builder.WiringException;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * Responsible for attaching a wire to a source and target component. The mechanism for perforing the attach is specific
+ * to the component implementation type.
+ *
+ * @version $Date$ $Revision$
+ */
+public interface WireAttacher<C extends Component,
+ PWSD extends PhysicalWireSourceDefinition,
+ PWTD extends PhysicalWireTargetDefinition> {
+
+ /**
+ * Attaches a wire to a source component.
+ *
+ * @param source the source component
+ * @param sourceDefinition metadata for performing the attach
+ * @param target the target component
+ * @param targetDefinition metadata for performing the attach
+ * @param wire the wire
+ * @throws WiringException if an exception occurs during the attach operation
+ */
+ void attachToSource(C source,
+ PWSD sourceDefinition,
+ Component target,
+ PhysicalWireTargetDefinition targetDefinition,
+ Wire wire) throws WiringException;
+
+ /**
+ * Attaches a wire to a target component.
+ *
+ * @param source the source component
+ * @param sourceDefinition metadata for performing the attach
+ * @param target the target component
+ * @param targetDefinition metadata for performing the attach
+ * @param wire the wire
+ * @throws WiringException if an exception occurs during the attach operation
+ */
+ void attachToTarget(Component source,
+ PhysicalWireSourceDefinition sourceDefinition,
+ C target,
+ PWTD targetDefinition,
+ Wire wire) throws WiringException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/WireAttacherRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/WireAttacherRegistry.java
new file mode 100644
index 0000000000..a29cf3e412
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/builder/physical/WireAttacherRegistry.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.spi.builder.physical;
+
+import org.apache.tuscany.spi.builder.WiringException;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * A registry for wire attachers
+ *
+ * @version $Rev$ $Date$
+ */
+public interface WireAttacherRegistry {
+
+ <C extends Component,
+ PWSD extends PhysicalWireSourceDefinition,
+ PWTD extends PhysicalWireTargetDefinition> void register(Class<?> clazz, WireAttacher<C, PWSD, PWTD> attacher);
+
+ /**
+ * Attaches a wire to a source component.
+ *
+ * @param source the source component
+ * @param sourceDefinition metadata for performing the attach
+ * @param target the target component
+ * @param targetDefinition metadata for performing the attach
+ * @param wire the wire
+ * @throws WiringException if an exception occurs during the attach operation
+ */
+ <C extends Component, PWSD extends PhysicalWireSourceDefinition>
+ void attachToSource(C source,
+ PWSD sourceDefinition,
+ Component target,
+ PhysicalWireTargetDefinition targetDefinition,
+ Wire wire)
+ throws WiringException;
+
+ /**
+ * Attaches a wire to a target component.
+ *
+ * @param source the source component
+ * @param sourceDefinition metadata for performing the attach
+ * @param target the target component
+ * @param targetDefinition metadata for performing the attach
+ * @param wire the wire
+ * @throws WiringException if an exception occurs during the attach operation
+ */
+ <C extends Component, PWTD extends PhysicalWireTargetDefinition>
+ void attachToTarget(Component source,
+ PhysicalWireSourceDefinition sourceDefinition,
+ C target,
+ PWTD targetDefinition,
+ Wire wire) throws WiringException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/AbstractSCAObject.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/AbstractSCAObject.java
new file mode 100644
index 0000000000..d13626ad03
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/AbstractSCAObject.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.spi.component;
+
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.tuscany.spi.AbstractLifecycle;
+import org.apache.tuscany.spi.event.Event;
+import org.apache.tuscany.spi.event.EventFilter;
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+import org.apache.tuscany.spi.event.TrueFilter;
+
+/**
+ * Functionality common to all <code>SCAObject<code> implementations
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractSCAObject extends AbstractLifecycle implements SCAObject {
+ protected static final EventFilter TRUE_FILTER = new TrueFilter();
+ protected Map<EventFilter, List<RuntimeEventListener>> listeners;
+ protected final URI uri;
+
+ public AbstractSCAObject(URI uri) {
+ assert uri != null;
+ this.uri = uri;
+ }
+
+ public URI getUri() {
+ return uri;
+ }
+
+ 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<RuntimeEventListener> 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<RuntimeEventListener> list = getListeners().get(filter);
+ if (list == null) {
+ list = new CopyOnWriteArrayList<RuntimeEventListener>();
+ listeners.put(filter, list);
+ }
+ list.add(listener);
+ }
+ }
+
+ public void publish(Event event) {
+ assert event != null : "Event object was null";
+ for (Map.Entry<EventFilter, List<RuntimeEventListener>> entry : getListeners().entrySet()) {
+ if (entry.getKey().match(event)) {
+ for (RuntimeEventListener listener : entry.getValue()) {
+ listener.onEvent(event);
+ }
+ }
+ }
+ }
+
+ protected Map<EventFilter, List<RuntimeEventListener>> getListeners() {
+ if (listeners == null) {
+ listeners = new ConcurrentHashMap<EventFilter, List<RuntimeEventListener>>();
+ }
+ return listeners;
+ }
+
+ public String toString() {
+ return "[" + uri.toString() + "] in state [" + super.toString() + ']';
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/AtomicComponent.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/AtomicComponent.java
new file mode 100644
index 0000000000..ed56f2dcda
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/AtomicComponent.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.spi.component;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+
+/**
+ * The runtime instantiation of an SCA atomic, or leaf-type, component
+ *
+ * @version $Rev$ $Date$
+ * @param <T> the type of the Java instance associated with this component
+ */
+public interface AtomicComponent<T> extends Component {
+
+ /**
+ * Returns true if component instances should be eagerly initialized.
+ *
+ * @return true if component instances should be eagerly initialized
+ */
+ boolean isEagerInit();
+
+ /**
+ * Returns the initialization level for this component.
+ *
+ * @return the initialization level for this component
+ */
+ int getInitLevel();
+
+ /**
+ * Returns the idle time allowed between operations in milliseconds if the implementation is conversational.
+ *
+ * @return the idle time allowed between operations in milliseconds if the implementation is conversational
+ */
+ long getMaxIdleTime();
+
+ /**
+ * Returns the maximum age a conversation may remain active in milliseconds if the implementation is
+ * conversational.
+ *
+ * @return the maximum age a conversation may remain active in milliseconds if the implementation is conversational
+ */
+ long getMaxAge();
+
+ /**
+ * Create a new implementation instance, fully injected with all property and reference values.
+ * The instance's lifecycle callbacks must not have been called.
+ *
+ * @return a wrapper for a new implementation instance
+ * @throws ObjectCreationException if there was a problem instantiating the implementation
+ */
+ InstanceWrapper<T> createInstanceWrapper() throws ObjectCreationException;
+
+ /**
+ * Create an ObjectFactory that returns an instance of this AtomicComponent.
+ *
+ * @return an ObjectFactory that returns an instance of this AtomicComponent
+ */
+ ObjectFactory<T> createObjectFactory();
+
+ /**
+ * Creates a new implementation instance, generally used as a callback by a {@link
+ * org.apache.tuscany.spi.component.ScopeContainer}.
+ *
+ * @return the instance
+ * @throws ObjectCreationException
+ */
+ @Deprecated
+ Object createInstance() throws ObjectCreationException;
+
+ /**
+ * Removes an implementation instance associated with the current invocation context.
+ *
+ * @throws ComponentException
+ */
+ @Deprecated
+ void removeInstance() throws ComponentException;
+
+ /**
+ * Returns the target instance associated with the component. A target instance is the actual object a request is
+ * dispatched to sans wire chain.
+ *
+ * @throws TargetResolutionException
+ */
+ @Deprecated
+ Object getTargetInstance() throws TargetResolutionException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Component.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Component.java
new file mode 100644
index 0000000000..1b714bde1f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Component.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.spi.component;
+
+import java.util.List;
+import java.util.Map;
+
+import org.osoa.sca.ComponentContext;
+
+import org.apache.tuscany.spi.model.PropertyValue;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * The runtime instantiation of an SCA component
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public interface Component extends Invocable {
+
+ /**
+ * Returns the SCA ComponentContext for this component.
+ *
+ * @return the SCA ComponentContext for this component
+ */
+ ComponentContext getComponentContext();
+
+ /**
+ * Returns a collection of wires for the component associated with a reference.
+ *
+ * @param name the reference name
+ * @return a collection of wires for the component associated with the reference
+ */
+ List<Wire> getWires(String name);
+
+ /**
+ * Returns the default property values associated with the component.
+ *
+ * @return default property values associated with the component.
+ */
+ Map<String, PropertyValue<?>> getDefaultPropertyValues();
+
+ /**
+ * Sets the default property values associated with the component.
+ *
+ * @param defaultPropertyValues Default property values associated with the component.
+ */
+ void setDefaultPropertyValues(Map<String, PropertyValue<?>> defaultPropertyValues);
+
+ /**
+ * Returns the ScopeContainer responsible for managing implementation instance or null if a ScopeContainer is not
+ * associated with the Component
+ *
+ * @return the scope container
+ */
+ ScopeContainer getScopeContainer();
+
+ /**
+ * Returns the component scope
+ *
+ * @return the component scope
+ */
+ @Deprecated
+ Scope getScope();
+
+ /**
+ * Sets the scope container associated with the component
+ *
+ * @param scopeContainer the scope container associated with the component
+ */
+ @Deprecated
+ void setScopeContainer(ScopeContainer scopeContainer);
+
+ /**
+ * Returns true if invocation dispatching can be optimized, i.e. invocation chains are not required
+ *
+ * @return true if invocation dispatching can be optimized, i.e. invocation chains are not required
+ */
+ @Deprecated
+ boolean isOptimizable();
+
+ /**
+ * Registers a service of this composite.
+ *
+ * @param service the service to add as a child
+ * @throws RegistrationException
+ */
+ @Deprecated
+ void register(Service service) throws RegistrationException;
+
+ /**
+ * Registers a reference of this composite.
+ *
+ * @param reference the reference to add as a child
+ * @throws RegistrationException
+ */
+ @Deprecated
+ void register(Reference reference) throws RegistrationException;
+
+ /**
+ * Returns the service with the given name or null if not found
+ *
+ * @param name the service name which is relative to the composite
+ * @return the service with the given name or null if not found
+ */
+ @Deprecated
+ Service getService(String name);
+
+ /**
+ * Returns the reference with the given name or null if not found
+ *
+ * @param name the reference name which is relative to the composite
+ * @return the reference with the given name or null if not found
+ */
+ @Deprecated
+ Reference getReference(String name);
+
+ /**
+ * Attaches a callback wire to the comoponent
+ *
+ * @param wire the wire to attach
+ */
+ @Deprecated
+ void attachCallbackWire(Wire wire);
+
+ /**
+ * Attaches a wire to a component reference
+ *
+ * @param wire the wire to attach
+ */
+ @Deprecated
+ void attachWire(Wire wire);
+
+ /**
+ * Attaches a set of wires to a component reference. Used for multiplicity.
+ *
+ * @param wires the wire to attach
+ */
+ @Deprecated
+ void attachWires(List<Wire> wires);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ComponentException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ComponentException.java
new file mode 100644
index 0000000000..2007cbb6bc
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ComponentException.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.spi.component;
+
+import org.apache.tuscany.api.TuscanyException;
+
+/**
+ * An checked exception encountered by an {@link org.apache.tuscany.spi.component.Component}
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class ComponentException extends TuscanyException {
+
+ protected ComponentException() {
+ }
+
+ protected ComponentException(String message) {
+ super(message);
+ }
+
+ protected ComponentException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ protected ComponentException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ protected ComponentException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+
+ protected ComponentException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ComponentManager.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ComponentManager.java
new file mode 100644
index 0000000000..8c414f8c23
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ComponentManager.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.component;
+
+import java.net.URI;
+import java.util.List;
+
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+import org.apache.tuscany.spi.idl.java.JavaServiceContract;
+
+/**
+ * Responsible for tracking and managing the component tree for a runtime instance. The tree corresponds to components
+ * deployed to the current runtime and hence may be sparse in comparison to the assembly component hierarchy for the SCA
+ * domain as parents and children may be distributed to different runtimes.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ComponentManager extends RuntimeEventListener {
+
+ /**
+ * Registers a component which will be managed by the runtime
+ *
+ * @param component the component
+ * @throws RegistrationException
+ */
+ void register(Component component) throws RegistrationException;
+
+ /**
+ * Deregisters a component
+ *
+ * @param component the component to deregister
+ * @throws RegistrationException
+ */
+ void unregister(Component component) throws RegistrationException;
+
+ /**
+ * Register a simple Java Object as a system component. This is primarily intended for use by bootstrap code to
+ * create the initial configuration components.
+ *
+ * @param uri the uri of the resulting component
+ * @param service the service contract the component should expose
+ * @param instance the Object that will become the component's implementation
+ * @throws RegistrationException
+ */
+ <S, I extends S> void registerJavaObject(URI uri, JavaServiceContract<S> service, I instance)
+ throws RegistrationException;
+
+ /**
+ * Register a simple Java Object as a system component. This is primarily intended for use by bootstrap code to
+ * create the initial configuration components.
+ *
+ * @param uri the name of the resulting component
+ * @param services the service contracts the component should expose
+ * @param instance the Object that will become the component's implementation
+ * @throws RegistrationException
+ */
+ <S, I extends S> void registerJavaObject(URI uri, List<JavaServiceContract<?>> services, I instance)
+ throws RegistrationException;
+
+ /**
+ * Returns the component with the given URI
+ *
+ * @param uri the component URI
+ * @return the component or null if not found
+ */
+ Component getComponent(URI uri);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ComponentRuntimeException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ComponentRuntimeException.java
new file mode 100644
index 0000000000..8479681c75
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ComponentRuntimeException.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.spi.component;
+
+import org.apache.tuscany.spi.CoreRuntimeException;
+
+/**
+ * An unchecked exception encountered by an {@link org.apache.tuscany.spi.component.Component}
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class ComponentRuntimeException extends CoreRuntimeException {
+
+ public ComponentRuntimeException() {
+ super();
+ }
+
+ public ComponentRuntimeException(String message) {
+ super(message);
+ }
+
+ public ComponentRuntimeException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public ComponentRuntimeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ComponentRuntimeException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+
+ public ComponentRuntimeException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/DuplicateNameException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/DuplicateNameException.java
new file mode 100644
index 0000000000..b9ee834b55
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/DuplicateNameException.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.spi.component;
+
+/**
+ * Denotes an attempt to add an child to a composite component with a name equal to an existing child
+ *
+ * @version $Rev$ $Date$
+ */
+public class DuplicateNameException extends RegistrationException {
+
+ public DuplicateNameException(String message) {
+ super(message);
+ }
+
+ public DuplicateNameException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/GroupInitializationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/GroupInitializationException.java
new file mode 100644
index 0000000000..d540262ad7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/GroupInitializationException.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.spi.component;
+
+import java.util.List;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class GroupInitializationException extends TargetResolutionException {
+ private final List<Exception> causes;
+
+ /**
+ * Exception indicating a problem initializing a group of components.
+ *
+ * @param contextId an identified for the context being initialized
+ * @param causes the individual exceptions that occurred
+ */
+ public GroupInitializationException(String contextId, List<Exception> causes) {
+ super(contextId);
+ this.causes = causes;
+ }
+
+ /**
+ * Return the exceptions that occurred as the group was initialized.
+ *
+ * @return a list of exceptions that occurred
+ */
+ public List<Exception> getCauses() {
+ return causes;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/IllegalTargetException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/IllegalTargetException.java
new file mode 100644
index 0000000000..7eb37c3639
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/IllegalTargetException.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.spi.component;
+
+/**
+ * Thrown when a target for an operation is not of the required type
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class IllegalTargetException extends TargetResolutionException {
+
+ public IllegalTargetException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/InstanceWrapper.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/InstanceWrapper.java
new file mode 100644
index 0000000000..e00ca13f66
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/InstanceWrapper.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.spi.component;
+
+import org.apache.tuscany.spi.component.TargetDestructionException;
+import org.apache.tuscany.spi.component.TargetInitializationException;
+
+/**
+ * Provides lifecycle management for an implementation instance associated with an {@link
+ * org.apache.tuscany.spi.component.AtomicComponent} for use by the atomic component's associated {@link
+ * org.apache.tuscany.spi.component.ScopeContainer}
+ *
+ * @version $Rev$ $Date$
+ */
+public interface InstanceWrapper<T> {
+
+ T getInstance();
+
+ boolean isStarted();
+
+ void start() throws TargetInitializationException;
+
+ void stop() throws TargetDestructionException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/InvalidAutowireInterface.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/InvalidAutowireInterface.java
new file mode 100644
index 0000000000..20e5732dd4
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/InvalidAutowireInterface.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.spi.component;
+
+/**
+ * Thrown when an invalid interface is specified during autowire registration
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidAutowireInterface extends RegistrationException {
+
+ public InvalidAutowireInterface(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/InvalidConversationSequenceException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/InvalidConversationSequenceException.java
new file mode 100644
index 0000000000..21a1712e1a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/InvalidConversationSequenceException.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.spi.component;
+
+/**
+ * Denotes an unknown operation sequence in a conversation
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidConversationSequenceException extends TargetInvocationException {
+
+ public InvalidConversationSequenceException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Invocable.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Invocable.java
new file mode 100644
index 0000000000..1aabd99401
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Invocable.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.spi.component;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+/**
+ * @version $Rev$ $Date$
+ *
+ */
+@Deprecated
+public interface Invocable extends SCAObject {
+
+ /**
+ * Callback to create a {@link org.apache.tuscany.spi.wire.TargetInvoker} which dispatches to a service offered this
+ * artifact
+ *
+ * @param targetName the service name
+ * @param operation the operation to invoke
+ * @return the target invoker
+ * @throws TargetInvokerCreationException
+ */
+ @Deprecated
+ TargetInvoker createTargetInvoker(String targetName, Operation operation) throws TargetInvokerCreationException;
+
+ /**
+ * Callback to create a {@link org.apache.tuscany.spi.wire.TargetInvoker} which dispatches to a service offered this
+ * artifact
+ *
+ * @param targetName the service name
+ * @param operation the operation to invoke
+ * @return the target invoker
+ * @throws TargetInvokerCreationException if an error is encountered creating the invoker
+ */
+ @Deprecated
+ TargetInvoker createTargetInvoker(String targetName, PhysicalOperationDefinition operation)
+ throws TargetInvokerCreationException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/MalformedNameException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/MalformedNameException.java
new file mode 100644
index 0000000000..de5225d12b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/MalformedNameException.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.spi.component;
+
+/**
+ * Denotes an attempt to add a child to a composite component with an illegal name
+ *
+ * @version $Rev$ $Date$
+ */
+public class MalformedNameException extends RegistrationException {
+
+ public MalformedNameException(Throwable e) {
+ super("Malformed name", e);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/PersistenceException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/PersistenceException.java
new file mode 100644
index 0000000000..06940aaff7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/PersistenceException.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.spi.component;
+
+/**
+ * Raised when an error persisting a component implementation instance is encountered
+ *
+ * @version $Rev$ $Date$
+ */
+public class PersistenceException extends ComponentException {
+ 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/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ReactivationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ReactivationException.java
new file mode 100644
index 0000000000..4ef0929422
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ReactivationException.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.spi.component;
+
+/**
+ * Raised when an error is encountered reactivating a serialized instance
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReactivationException extends ComponentRuntimeException {
+ private String owner;
+
+ public ReactivationException(String message) {
+ super(message);
+ }
+
+ public ReactivationException(String message, String identifier, String ower) {
+ super(message, identifier);
+ this.owner = ower;
+ }
+
+ public ReactivationException(Throwable cause) {
+ super(cause);
+ }
+
+ public String getOwner() {
+ return owner;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Reference.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Reference.java
new file mode 100644
index 0000000000..1ab107fd38
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Reference.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.spi.component;
+
+import java.util.List;
+
+import org.apache.tuscany.spi.model.ServiceContract;
+
+/**
+ * The runtime instantiation of an SCA reference
+ *
+ * @version $Rev$ $Date$
+ * @Deprecated
+ */
+public interface Reference extends SCAObject {
+
+ /**
+ * Returns the contract for the reference.
+ *
+ * @return the contract for the reference.
+ */
+ ServiceContract<?> getServiceContract();
+
+ /**
+ * Returns the collection of bindings configured for the reference.
+ *
+ * @return the collection of bindings configured for the reference.
+ */
+ List<ReferenceBinding> getReferenceBindings();
+
+ /**
+ * Adds a binding the reference is configured with.
+ *
+ * @param binding the binding the reference is configured with.
+ */
+ void addReferenceBinding(ReferenceBinding binding);
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ReferenceBinding.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ReferenceBinding.java
new file mode 100644
index 0000000000..32bc8f1624
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ReferenceBinding.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.spi.component;
+
+import java.net.URI;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * Manages an SCA reference configured with a binding
+ *
+ * @version $Rev$ $Date$
+ * @Deprecated
+ */
+public interface ReferenceBinding extends Invocable {
+
+ /**
+ * Returns the binding qualified name
+ *
+ * @return the binding qualified name
+ */
+ QName getBindingType();
+
+ /**
+ * Returns the wire for flowing a request through the reference
+ */
+ Wire getWire();
+
+ /**
+ * Sets the wire wire for flowing a request through the reference
+ */
+ void setWire(Wire wire);
+
+ /**
+ * Returns the service contract for the binding
+ *
+ * @return the service contract for the binding
+ */
+ ServiceContract<?> getBindingServiceContract();
+
+ /**
+ * Returns the target URI for the binding
+ *
+ * @return the target URI for the binding
+ */
+ URI getTargetUri();
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/RegistrationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/RegistrationException.java
new file mode 100644
index 0000000000..b776c49c00
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/RegistrationException.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.spi.component;
+
+/**
+ * Thrown when an error is encountered registering a service or reference on a composite
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public abstract class RegistrationException extends ComponentException {
+ public RegistrationException() {
+ }
+
+ public RegistrationException(String message) {
+ super(message);
+ }
+
+ public RegistrationException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public RegistrationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public RegistrationException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAExternalizable.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAExternalizable.java
new file mode 100644
index 0000000000..6454e66369
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAExternalizable.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.spi.component;
+
+/**
+ * A serialization contract for runtime SCA artifacts. When an instance is deserialized, runtime services defined in
+ * this contract must be set before reactivating the instance
+ *
+ * @version $Rev$ $Date$
+ */
+public interface SCAExternalizable {
+
+ /**
+ * Sets the current work context
+ *
+ * @param context the current work context
+ */
+ void setWorkContext(WorkContext context);
+
+ /**
+ * Callback after all values have been set prior to making the instance available in the runtime
+ *
+ * @throws org.apache.tuscany.spi.component.ReactivationException
+ *
+ */
+ void reactivate() throws ReactivationException;
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObject.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObject.java
new file mode 100644
index 0000000000..d92385cd6f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObject.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.spi.component;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.Lifecycle;
+import org.apache.tuscany.spi.event.EventPublisher;
+
+/**
+ * Represents the base SCA artifact type in an assembly
+ *
+ * @version $Rev$ $Date$
+ */
+public interface SCAObject extends EventPublisher, Lifecycle {
+
+ /**
+ * Returns the artifact URI
+ *
+ * @return the artifact URI
+ */
+ URI getUri();
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObjectInputStream.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObjectInputStream.java
new file mode 100644
index 0000000000..052a1d053b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObjectInputStream.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.spi.component;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamClass;
+
+/**
+ * Deserializes an object based on the thread context classloader and provides special handling for {@link
+ * SCAExternalizable}
+ *
+ * @version $Rev$ $Date$
+ */
+public class SCAObjectInputStream extends ObjectInputStream {
+ private final ClassLoader classLoader;
+ private WorkContext context;
+
+ public SCAObjectInputStream(InputStream in, WorkContext context) throws IOException, SecurityException {
+ super(in);
+ this.context = context;
+ this.classLoader = Thread.currentThread().getContextClassLoader();
+ enableResolveObject(true);
+ }
+
+ protected Class resolveClass(ObjectStreamClass streamClass) throws IOException, ClassNotFoundException {
+ return classLoader.loadClass(streamClass.getName());
+ }
+
+ protected Object resolveObject(Object obj) throws IOException {
+ if (obj instanceof SCAExternalizable) {
+ SCAExternalizable ext = (SCAExternalizable) obj;
+ ext.setWorkContext(context);
+ ext.reactivate();
+ }
+ return obj;
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObjectStartException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObjectStartException.java
new file mode 100644
index 0000000000..a712b1b0eb
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObjectStartException.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.spi.component;
+
+import org.apache.tuscany.spi.CoreRuntimeException;
+
+/**
+ * Denotes an error starting an SCAObject
+ *
+ * @version $Rev$ $Date$
+ */
+public class SCAObjectStartException extends CoreRuntimeException {
+
+ public SCAObjectStartException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObjectStopException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObjectStopException.java
new file mode 100644
index 0000000000..9f430bc414
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/SCAObjectStopException.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.spi.component;
+
+import org.apache.tuscany.spi.CoreRuntimeException;
+
+/**
+ * Denotes an error stopping an SCAObject
+ *
+ * @version $Rev$ $Date$
+ */
+public class SCAObjectStopException extends CoreRuntimeException {
+
+ public SCAObjectStopException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ScopeContainer.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ScopeContainer.java
new file mode 100644
index 0000000000..ef09521a95
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ScopeContainer.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.component;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.Lifecycle;
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+import org.apache.tuscany.spi.model.Scope;
+
+
+/**
+ * Manages the lifecycle and visibility of instances associated with a an {@link AtomicComponent}.
+ *
+ * @version $Rev$ $Date$
+ * @param <KEY> 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<KEY> extends Lifecycle, RuntimeEventListener {
+
+ /**
+ * Returns the Scope that this container supports.
+ *
+ * @return the Scope that this container supports
+ */
+ Scope getScope();
+
+ /**
+ * Registers a component with the scope.
+ *
+ * @param component the component to register
+ * @param groupId the id of the group to associate this component with
+ */
+ <T> void register(AtomicComponent<T> component, URI groupId);
+
+ /**
+ * Unregisters a component with the scope.
+ *
+ * @param component the component to unregister
+ */
+ <T> void unregister(AtomicComponent<T> component);
+
+ /**
+ * Start a new context with the supplied ID.
+ *
+ * @param contextId an ID that uniquely identifies the context.
+ * @param groupId the group of components to associate with this context
+ * @throws GroupInitializationException if an exception was thrown by any eagerInit component
+ */
+ void startContext(KEY contextId, URI groupId) throws GroupInitializationException;
+
+ /**
+ * 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 <T> the type of the target instance
+ * @param component the component
+ * @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
+ */
+ <T> InstanceWrapper<T> getWrapper(AtomicComponent<T> component, 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 <T> the type of the target instance
+ * @param component the component
+ * @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
+ */
+ <T> InstanceWrapper<T> getAssociatedWrapper(AtomicComponent<T> component, KEY contextId)
+ throws TargetResolutionException;
+
+ /**
+ * Return a wrapper after use (for example, after invoking the instance).
+ *
+ * @param <T> the type of the target instance
+ * @param component the component
+ * @param contextId the id for the scope context
+ * @param wrapper the wrapper for the target instance being returned
+ * @throws TargetDestructionException if there was a problem returning the target instance
+ */
+ <T> void returnWrapper(AtomicComponent<T> component, InstanceWrapper<T> 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
+ */
+ <T> void remove(AtomicComponent<T> component) throws PersistenceException;
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ScopeContainerMonitor.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ScopeContainerMonitor.java
new file mode 100644
index 0000000000..3e7649d59e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ScopeContainerMonitor.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.spi.component;
+
+import org.apache.tuscany.api.annotation.LogLevel;
+
+/**
+ * Defines monitor events for scope containers
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ScopeContainerMonitor {
+
+ @LogLevel("SEVERE")
+ void eagerInitializationError(Exception e);
+
+ @LogLevel("SEVERE")
+ void destructionError(TargetDestructionException e);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ScopeRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ScopeRegistry.java
new file mode 100644
index 0000000000..91cf1d9b6e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ScopeRegistry.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.spi.component;
+
+import org.apache.tuscany.spi.model.Scope;
+
+/**
+ * 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(Scope scope);
+
+ void register(ScopeContainer container);
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Service.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Service.java
new file mode 100644
index 0000000000..fc0708f7c1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/Service.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.spi.component;
+
+import java.util.List;
+
+import org.apache.tuscany.spi.model.ServiceContract;
+
+/**
+ * The runtime instantiation of an SCA service
+ *
+ * @version $Rev$ $Date$
+ * @Deprecated
+ */
+public interface Service extends SCAObject {
+
+ /**
+ * Returns the contract for the service.
+ *
+ * @return the contract for the service.
+ */
+ ServiceContract<?> getServiceContract();
+
+ /**
+ * Returns the collection of bindings configured for the service.
+ *
+ * @return the collection of bindings configured for the service.
+ */
+ List<ServiceBinding> getServiceBindings();
+
+ /**
+ * Adds a binding the service is exposed over.
+ *
+ * @param binding the binding the service is exposed over.
+ */
+ void addServiceBinding(ServiceBinding binding);
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ServiceBinding.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ServiceBinding.java
new file mode 100644
index 0000000000..60cd822913
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/ServiceBinding.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.spi.component;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * The runtime instantiation of an SCA service binding.
+ *
+ * @version $Rev$ $Date$
+ * @Deprecated
+ */
+public interface ServiceBinding extends Invocable {
+
+ /**
+ * Returns the binding qualified name
+ *
+ * @return the binding qualified name
+ */
+ QName getBindingType();
+
+ /**
+ * Get the ServiceContract for the binding
+ *
+ * @return the ServiceContract for the binding
+ */
+ ServiceContract<?> getBindingServiceContract();
+
+ Wire getWire();
+
+ void setWire(Wire wire);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetDestructionException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetDestructionException.java
new file mode 100644
index 0000000000..5f521f9b0a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetDestructionException.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.spi.component;
+
+/**
+ * Denotes an error destroying a target
+ *
+ * @version $Rev$ $Date$
+ */
+public class TargetDestructionException extends TargetResolutionException {
+
+ public TargetDestructionException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public TargetDestructionException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+
+
+ public TargetDestructionException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetException.java
new file mode 100644
index 0000000000..6b8278cf8b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetException.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.spi.component;
+
+/**
+ * Denotes an error while performing an operation on a target component implementation instance
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class TargetException extends ComponentException {
+
+ public TargetException(String message) {
+ super(message);
+ }
+
+
+ public TargetException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public TargetException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+
+ public TargetException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+
+ public TargetException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetInitializationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetInitializationException.java
new file mode 100644
index 0000000000..eaea4c3bc9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetInitializationException.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.spi.component;
+
+/**
+ * Denotes an error initializing a target
+ *
+ * @version $Rev$ $Date$
+ */
+public class TargetInitializationException extends TargetResolutionException {
+
+ public TargetInitializationException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public TargetInitializationException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+
+ public TargetInitializationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetInvocationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetInvocationException.java
new file mode 100644
index 0000000000..1fc2b24f5b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetInvocationException.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.spi.component;
+
+/**
+ * Raised when an error is encountered during a target invocation
+ *
+ * @version $Rev$ $Date$
+ */
+public class TargetInvocationException extends TargetException {
+
+ public TargetInvocationException(String message) {
+ super(message);
+ }
+
+ public TargetInvocationException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public TargetInvocationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public TargetInvocationException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetInvokerCreationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetInvokerCreationException.java
new file mode 100644
index 0000000000..da44ec82ae
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetInvokerCreationException.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.spi.component;
+
+/**
+ * Denotes an error creating a {@link org.apache.tuscany.spi.wire.TargetInvoker}
+ *
+ * @version $Rev$ $Date$
+ * @Deprecated
+ */
+public abstract class TargetInvokerCreationException extends ComponentException {
+
+ public TargetInvokerCreationException() {
+ }
+
+ public TargetInvokerCreationException(String message) {
+ super(message);
+ }
+
+ public TargetInvokerCreationException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public TargetInvokerCreationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public TargetInvokerCreationException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+
+ public TargetInvokerCreationException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetNotFoundException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetNotFoundException.java
new file mode 100644
index 0000000000..cd6996789c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetNotFoundException.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.spi.component;
+
+/**
+ * Thrown when a target of an operation cannot be found
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class TargetNotFoundException extends TargetResolutionException {
+
+ public TargetNotFoundException(String message) {
+ super(message);
+ }
+
+ public TargetNotFoundException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetResolutionException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetResolutionException.java
new file mode 100644
index 0000000000..858fa9415d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/TargetResolutionException.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.spi.component;
+
+/**
+ * Denotes an error retrieving a target instance
+ *
+ * @version $Rev$ $Date$
+ */
+public class TargetResolutionException extends TargetException {
+
+ public TargetResolutionException(String message) {
+ super(message);
+ }
+
+ public TargetResolutionException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public TargetResolutionException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public TargetResolutionException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/WorkContext.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/WorkContext.java
new file mode 100644
index 0000000000..14b190f99b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/component/WorkContext.java
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.component;
+
+import java.net.URI;
+import java.util.LinkedList;
+
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * Implementations track information associated with a request as it is processed by the runtime
+ *
+ * @version $Rev$ $Date$
+ */
+public interface WorkContext {
+
+ /**
+ * Returns the unique key for the given identifier associated with the current request
+ */
+ Object getIdentifier(Object type);
+
+ /**
+ * Sets the unique key for the given identifier associated with the current request
+ */
+ void setIdentifier(Object type, Object identifier);
+
+ /**
+ * Clears the unique key for the given identifier associated with the current request
+ */
+ void clearIdentifier(Object type);
+
+ /**
+ * Clears all identifiers associated with the current request
+ */
+ void clearIdentifiers();
+
+ /**
+ * Returns an ordered list of callback URIs for the current context. Ordering is based on the sequence of service
+ * invocations for collocated components
+ *
+ * @return the current list of callback URIs
+ * @Deprecated
+ */
+ LinkedList<URI> getCallbackUris();
+
+ /**
+ * Sets an ordered list of callback URIs for the current context. Ordering is based on the sequence of service
+ * invocations for collocated components
+ *
+ * @Deprecated
+ */
+ void setCallbackUris(LinkedList<URI> uris);
+
+ /**
+ * Returns an ordered list of callback wures for the current context. Ordering is based on the sequence of service
+ * invocations for collocated components
+ *
+ * @return the current list of callback wires
+ */
+ LinkedList<Wire> getCallbackWires();
+
+ /**
+ * Sets an ordered list of callback wires for the current context. Ordering is based on the sequence of service
+ * invocations for collocated components
+ */
+ void setCallbackWires(LinkedList<Wire> wires);
+
+ /**
+ * Returns the correlation id for the current invocation or null if not available. Transports may use correlation
+ * ids for message routing.
+ *
+ * @return the correlation id for the current invocation or null
+ */
+ Object getCorrelationId();
+
+ /**
+ * Sets the correlation id for the current invocation. Transports may use correlation ids for message routing.
+ *
+ * @param id the correlation id
+ */
+ void setCorrelationId(Object id);
+
+ /**
+ * Returns the current atomic component as a request is processed or null if it is not being tracked. Note that the
+ * current atomic component is typically only tracked during persistence operations involving implementation
+ * instances
+ *
+ * @return the current atomic component as a request is processed or null
+ */
+ AtomicComponent getCurrentAtomicComponent();
+
+ /**
+ * Sets the current atomic component that is handling processing of a request. Note that in most cases it will not
+ * be necessary to track this in the rumtime
+ *
+ * @param component the current atomic component
+ */
+ void setCurrentAtomicComponent(AtomicComponent component);
+
+ /**
+ * Removes and returns the name of the last remotable service to handle the current request
+ *
+ * @return the name of the last remotable service to handle the current request or null
+ */
+ String popServiceName();
+
+ /**
+ * Returns the name of the last remotable service to handle the current request
+ *
+ * @return the name of the last remotable service to handle the current request or null
+ */
+ String getCurrentServiceName();
+
+ /**
+ * Adds the name of the last remotable service to handle the current request
+ *
+ * @param name the name of the last remotable service to handle the current request or null
+ */
+ void pushServiceName(String name);
+
+ /**
+ * Clears the stack of current service names
+ */
+ void clearServiceNames();
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/DataBinding.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/DataBinding.java
new file mode 100644
index 0000000000..a33b40a785
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/DataBinding.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.spi.databinding;
+
+import org.apache.tuscany.spi.model.DataType;
+
+/**
+ * DataBinding represents a data representation, for example, SDO, JAXB and AXIOM
+ */
+public interface DataBinding {
+ /**
+ * The name of a databinding should be case-insensitive and unique
+ *
+ * @return The name of the databinding
+ */
+ String getName();
+
+ /**
+ * Introspect a java class or interface to create a DataType model
+ *
+ * @param javaType The java class or interface to be introspected
+ * @return The DataType or null if the java type is not supported by this databinding
+ */
+ DataType introspect(Class<?> javaType);
+
+ /**
+ * 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 object 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();
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/DataBindingRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/DataBindingRegistry.java
new file mode 100644
index 0000000000..ba47401cc2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/DataBindingRegistry.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.spi.databinding;
+
+import org.apache.tuscany.spi.model.DataType;
+
+/**
+ * The registry for data bindings
+ */
+public interface DataBindingRegistry {
+ /**
+ * Register a data binding
+ *
+ * @param dataBinding
+ */
+ void register(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 unregister(String id);
+
+ /**
+ * Introspect the java class to figure out what DataType supports it
+ *
+ * @param javaType The java class or interface
+ * @return A DataType representing the java type or null if no databinding
+ * recognizes the java type
+ */
+ DataType introspectType(Class<?> javaType);
+
+ /**
+ * Introspect the value to figure out the corresponding DataType
+ *
+ * @param value The object value
+ * @return A DataType representing the value or null if no databinding
+ * recognizes the value
+ */
+ DataType introspectType(Object value);
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/DataPipe.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/DataPipe.java
new file mode 100755
index 0000000000..dcb83426d1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/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.spi.databinding;
+
+/**
+ * Data pipe allows a data source pushes data into its sink and pipe the data into its result
+ *
+ * @param <S> The data binding type of the sink
+ * @param <R> The data binding type of the result
+ */
+public interface DataPipe<S, R> 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 the result
+ */
+ R getResult();
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/Mediator.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/Mediator.java
new file mode 100755
index 0000000000..0983ed46fd
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/Mediator.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.spi.databinding;
+
+import java.util.Map;
+
+import org.apache.tuscany.spi.model.DataType;
+
+/**
+ * This interface will be used as a Tuscany system service to perform data mediations
+ * <p/>
+ * 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 the context for the mediation
+ * @return the result of the mediation
+ */
+ Object mediate(Object source, DataType sourceDataType, DataType targetDataType, Map<Class<?>, Object> 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
+ * @param context the context for the mediation
+ */
+ void mediate(Object source,
+ Object target,
+ DataType sourceDataType,
+ DataType targetDataType,
+ Map<Class<?>, Object> context);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/PullTransformer.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/PullTransformer.java
new file mode 100644
index 0000000000..21e8cc2750
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/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.spi.databinding;
+
+/**
+ * PullTransformer transforms data from one binding format to the other one which can be directly consumed
+ *
+ * @param <S> The source data type
+ * @param <R> the target data type
+ */
+public interface PullTransformer<S, R> extends Transformer {
+ /**
+ * Transform source data into the result type.
+ *
+ * @param source The source data
+ * @param context The context for the transformation
+ * @return The transformed result
+ */
+ R transform(S source, TransformationContext context);
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/PushTransformer.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/PushTransformer.java
new file mode 100644
index 0000000000..d68b6aa772
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/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.spi.databinding;
+
+/**
+ * A transformer that pushes data from its source into the sink
+ *
+ * @param <S>
+ * @param <R>
+ */
+public interface PushTransformer<S, R> extends Transformer {
+ /**
+ * @param source The source data
+ * @param sink The sink to receive the data
+ * @param context
+ */
+ void transform(S source, R sink, TransformationContext context);
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/SimpleTypeMapper.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/SimpleTypeMapper.java
new file mode 100644
index 0000000000..0da681c71e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/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.spi.databinding;
+
+import org.apache.tuscany.spi.model.TypeInfo;
+
+/**
+ * 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(TypeInfo 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(TypeInfo simpleType, Object obj, TransformationContext context);
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/TransformationContext.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/TransformationContext.java
new file mode 100755
index 0000000000..efddfb8fc0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/TransformationContext.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.spi.databinding;
+
+import java.util.Map;
+
+import org.apache.tuscany.spi.model.DataType;
+
+/**
+ * Context for data transformation
+ */
+public interface TransformationContext {
+ /**
+ * Get the source data type
+ *
+ * @return the source data type
+ */
+ DataType getSourceDataType();
+
+ /**
+ * Get the target data type
+ *
+ * @return the target datatype
+ */
+ DataType getTargetDataType();
+
+ /**
+ * Set the source data type
+ *
+ * @param sourceDataType the source data type
+ */
+ void setSourceDataType(DataType sourceDataType);
+
+ /**
+ * Set the target data type
+ *
+ * @param targetDataType the target data type
+ */
+ void setTargetDataType(DataType targetDataType);
+
+ /**
+ * Get the classloader
+ *
+ * @return the classloader
+ */
+ ClassLoader getClassLoader();
+
+ /**
+ * Get a map of metadata
+ *
+ * @return the map of metadata
+ */
+ Map<Class<?>, Object> getMetadata();
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/TransformationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/TransformationException.java
new file mode 100755
index 0000000000..9b57e1cf70
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/TransformationException.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.spi.databinding;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * Reports problems during data transformation
+ */
+public class TransformationException extends TuscanyRuntimeException {
+
+ private static final long serialVersionUID = 7662385613693006428L;
+
+ public TransformationException() {
+ super();
+ }
+
+ public TransformationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public TransformationException(String message) {
+ super(message);
+ }
+
+ public TransformationException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/Transformer.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/Transformer.java
new file mode 100755
index 0000000000..2f969e979d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/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.spi.databinding;
+
+/**
+ * A transformer provides the data transformation from source type to target type. The cost of the transformation is
+ * modeled as weight.
+ */
+public interface Transformer {
+ /**
+ * Get the source type that this transformer transforms data from. The type is used as the key when the transformer
+ * is registered with TransformerRegistry.
+ *
+ * @return A key indentifying the source type
+ */
+ String getSourceDataBinding();
+
+ /**
+ * Get the target type that this transformer transforms data into. The type is used as the key when the transformer
+ * is registered with TransformerRegistry.
+ *
+ * @return A key indentifying the target type
+ */
+ String getTargetDataBinding();
+
+ /**
+ * Get the cost of the transformation. The weight can be used to choose the most efficient path if there are more
+ * than one available from the source to the target.
+ *
+ * @return An integer representing the cost of the transformation
+ */
+ int getWeight();
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/TransformerRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/TransformerRegistry.java
new file mode 100755
index 0000000000..18a01b7853
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/TransformerRegistry.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.spi.databinding;
+
+import java.util.List;
+
+/**
+ * Registry for data transformers
+ */
+public interface TransformerRegistry {
+ /**
+ * Register a transformer
+ *
+ * @param sourceDataBinding
+ * @param targetDataBinding
+ * @param weight
+ * @param transformer
+ */
+ void registerTransformer(String sourceDataBinding,
+ String targetDataBinding,
+ int weight,
+ Transformer transformer);
+
+ /**
+ * Register a transformer
+ *
+ * @param transformer
+ */
+ void registerTransformer(Transformer transformer);
+
+ /**
+ * Unregister a transformer
+ *
+ * @param sourceDataBinding
+ * @param targetDataBinding
+ * @return true if sucessfully unregistered
+ */
+ boolean unregisterTransformer(String sourceDataBinding, String targetDataBinding);
+
+ /**
+ * Get the direct Transformer which can transform data from source type to result type
+ *
+ * @param sourceDataBinding
+ * @param targetDataBinding
+ * @return the transformer
+ */
+ 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 the list of transformers
+ */
+ List<Transformer> getTransformerChain(String sourceDataBinding, String targetDataBinding);
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/WrapperHandler.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/WrapperHandler.java
new file mode 100644
index 0000000000..1cb8d00bf5
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/WrapperHandler.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.spi.databinding;
+
+import org.apache.tuscany.spi.model.ElementInfo;
+
+/**
+ * A contract for transformers to deal with wrapping/unwrapping for WSDL wrapper style operations
+ */
+public interface WrapperHandler<T> {
+ /**
+ * 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 child element from the wrapper
+ *
+ * @param wrapper The wrapper
+ * @param i The index
+ * @param element The XSD element
+ * @return The value of the child
+ */
+ Object getChild(T wrapper, int i, ElementInfo element);
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/DOMHelper.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/DOMHelper.java
new file mode 100644
index 0000000000..2b927b8e55
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/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.spi.databinding.extension;
+
+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/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/DataBindingExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/DataBindingExtension.java
new file mode 100644
index 0000000000..bc9483f01f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/DataBindingExtension.java
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.databinding.extension;
+
+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.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Scope;
+import org.osoa.sca.annotations.Service;
+
+import org.apache.tuscany.spi.databinding.DataBinding;
+import org.apache.tuscany.spi.databinding.DataBindingRegistry;
+import org.apache.tuscany.spi.databinding.SimpleTypeMapper;
+import org.apache.tuscany.spi.databinding.WrapperHandler;
+import org.apache.tuscany.spi.model.DataType;
+
+/**
+ * Base Implementation of DataBinding
+ *
+ * @version $Rev$ $Date$
+ */
+@Service(DataBinding.class)
+@Scope("COMPOSITE")
+@EagerInit
+public abstract class DataBindingExtension implements DataBinding {
+
+ protected DataBindingRegistry registry;
+
+ protected Class<?> baseType;
+
+ protected String name;
+
+ /**
+ * Create a databinding with the base java type whose name will be used as the name of the databinding
+ *
+ * @param baseType The base java class or interface representing the databinding, for example, org.w3c.dom.Node
+ */
+ protected DataBindingExtension(Class<?> baseType) {
+ this(baseType.getName(), baseType);
+ }
+
+ /**
+ * Create a databinding with the name and base java type
+ *
+ * @param name The name of the databinding
+ * @param baseType The base java class or interface representing the databinding, for example, org.w3c.dom.Node
+ */
+ protected DataBindingExtension(String name, Class<?> baseType) {
+ this.name = name;
+ this.baseType = baseType;
+ }
+
+ @Reference
+ public void setDataBindingRegistry(DataBindingRegistry registry) {
+ this.registry = registry;
+ }
+
+ @Init
+ public void init() {
+ registry.register(this);
+ }
+
+ public DataType introspect(Class<?> javaType) {
+ if (baseType == null || javaType == null) {
+ return null;
+ }
+ if (baseType.isAssignableFrom(javaType)) {
+ return new DataType<Class>(name, javaType, baseType);
+ } else {
+ return null;
+ }
+ }
+
+ public DataType introspect(Object value) {
+ if (value == null) {
+ return null;
+ } else {
+ return introspect(value.getClass());
+ }
+ }
+
+ public final String getName() {
+ return name;
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.DataBinding#getWrapperHandler()
+ */
+ public WrapperHandler getWrapperHandler() {
+ return null;
+ }
+
+ 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;
+ }
+
+ public SimpleTypeMapper getSimpleTypeMapper() {
+ return new SimpleTypeMapperExtension();
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/Java2SimpleTypeTransformer.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/Java2SimpleTypeTransformer.java
new file mode 100644
index 0000000000..3150dfad3d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/Java2SimpleTypeTransformer.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.spi.databinding.extension;
+
+import org.apache.tuscany.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.SimpleTypeMapper;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.model.ElementInfo;
+import org.apache.tuscany.spi.model.TypeInfo;
+
+/**
+ * Transformer to convert data from a simple java object to a databinding's representation
+ */
+public abstract class Java2SimpleTypeTransformer<T> extends TransformerExtension<Object, T> implements
+ PullTransformer<Object, T> {
+
+ protected SimpleTypeMapper mapper;
+
+ public Java2SimpleTypeTransformer() {
+ this.mapper = new SimpleTypeMapperExtension();
+ }
+
+ public Java2SimpleTypeTransformer(SimpleTypeMapper mapper) {
+ this.mapper = (mapper != null) ? mapper : new SimpleTypeMapperExtension();
+ }
+
+ public T transform(Object source, TransformationContext context) {
+ ElementInfo element =
+ (ElementInfo) context.getTargetDataType().getMetadata(ElementInfo.class.getName());
+ TypeInfo simpleType = (TypeInfo) element.getType();
+ String text = mapper.toXMLLiteral(simpleType, source, context);
+ return createElement(element, text, context);
+ }
+
+ public Class getSourceType() {
+ return Object.class;
+ }
+
+ public int getWeight() {
+ return 10000;
+ }
+
+ protected abstract T createElement(ElementInfo element, String literal, TransformationContext context);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/SimpleType2JavaTransformer.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/SimpleType2JavaTransformer.java
new file mode 100644
index 0000000000..2304990e88
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/SimpleType2JavaTransformer.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.spi.databinding.extension;
+
+import org.apache.tuscany.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.SimpleTypeMapper;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.model.ElementInfo;
+import org.apache.tuscany.spi.model.TypeInfo;
+
+/**
+ * Transformer to convert data from a databinding's representation of simple types to Java Objects
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class SimpleType2JavaTransformer<T> extends TransformerExtension<T, Object> implements
+ PullTransformer<T, Object> {
+
+ protected SimpleTypeMapper mapper;
+
+ public SimpleType2JavaTransformer() {
+ this.mapper = new SimpleTypeMapperExtension();
+ }
+
+ public SimpleType2JavaTransformer(SimpleTypeMapper mapper) {
+ this.mapper = (mapper != null) ? mapper : new SimpleTypeMapperExtension();
+ }
+
+ public Object transform(T source, TransformationContext context) {
+ TypeInfo simpleType = (TypeInfo) context.getSourceDataType().getMetadata(TypeInfo.class.getName());
+ if (simpleType == null) {
+ ElementInfo element =
+ (ElementInfo) context.getSourceDataType().getMetadata(ElementInfo.class.getName());
+ simpleType = element.getType();
+ }
+
+ return mapper.toJavaObject(simpleType, 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 the source to return the string from
+ * @return A string
+ */
+ protected abstract String getText(T source);
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtension.java
new file mode 100644
index 0000000000..5ce3eb978e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtension.java
@@ -0,0 +1,415 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.spi.databinding.extension;
+
+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.spi.databinding.SimpleTypeMapper;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.model.TypeInfo;
+
+public class SimpleTypeMapperExtension extends XSDDataTypeConverter implements SimpleTypeMapper {
+
+ public static final int BASE64_ENCODING = 1;
+ public static final int HEXBIN_ENCODING = 2;
+
+ public static final String SET = "set";
+
+ public static final Map<Class, String> JAVA2XML = new HashMap<Class, String>();
+
+ public static final String URI_2001_SCHEMA_XSD = "http://www.w3.org/2001/XMLSchema";
+
+ public static final Map<String, Class> XML2JAVA = new HashMap<String, Class>();
+
+ 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<String, TypeInfo> XSD_SIMPLE_TYPES = new HashMap<String, TypeInfo>();
+
+ 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 int byteEncoding = BASE64_ENCODING;
+ private DatatypeFactory factory;
+
+ public SimpleTypeMapperExtension() {
+ super();
+ try {
+ this.factory = DatatypeFactory.newInstance();
+ } catch (DatatypeConfigurationException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ public Class getJavaType(TypeInfo xmlType) {
+ TypeInfo baseType = xmlType;
+ while (baseType.getBaseType() != null) {
+ baseType = baseType.getBaseType();
+ }
+ return XML2JAVA.get(baseType.getQName().getLocalPart());
+ }
+
+ public TypeInfo getXMLType(Class javaType) {
+ return XSD_SIMPLE_TYPES.get(JAVA2XML.get(javaType));
+ }
+
+ public Object toJavaObject(TypeInfo simpleType, String literal, TransformationContext context) {
+ /**
+ * <ul>
+ * <li>xsd:string --- java.lang.String
+ * <li>xsd:integer --- java.math.BigInteger
+ * <li>xsd:int --- int
+ * <li>xsd:long --- long
+ * <li>xsd:short --- short
+ * <li>xsd:decimal --- java.math.BigDecimal
+ * <li>xsd:float --- float
+ * <li>xsd:double --- double
+ * <li>xsd:boolean --- boolean
+ * <li>xsd:byte --- byte
+ * <li>xsd:QName --- javax.xml.namespace.QName
+ * <li>xsd:dateTime --- javax.xml.datatype.XMLGregorianCalendar
+ * <li>xsd:base64Binary --- byte[]
+ * <li>xsd:hexBinary --- byte[]
+ * <li>xsd:unsignedInt --- long
+ * <li>xsd:unsignedShort --- int
+ * <li>xsd:unsignedByte --- short
+ * <li>xsd:time --- javax.xml.datatype.XMLGregorianCalendar
+ * <li>xsd:date --- javax.xml.datatype.XMLGregorianCalendar
+ * <li>xsd:g* --- javax.xml.datatype.XMLGregorianCalendar
+ * <li>xsd:anySimpleType (for xsd:element of this type)a
+ * java.lang.Object
+ * <li>xsd:anySimpleType (for xsd:attribute of this type)
+ * java.lang.String
+ * <li>xsd:duration javax.xml.datatype.Duration
+ * <li>xsd:NOTATION javax.xml.namespace.QName
+ * </ul>
+ */
+
+ if (literal == null) {
+ return null;
+ }
+ String value = literal.trim();
+ if (!simpleType.isSimpleType()) {
+ throw new IllegalArgumentException("Complex type is not supported for simple java databinding.");
+ }
+ TypeInfo baseType = simpleType;
+ while (baseType.getBaseType() != null) {
+ baseType = (TypeInfo)baseType.getBaseType();
+ }
+
+ QName type = baseType.getQName();
+ 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) : null);
+ return parseQName(value, namespaceContext);
+ } else if (type.equals(XSD_NOTATION)) {
+ NamespaceContext namespaceContext =
+ (NamespaceContext)((context != null) ? context.getMetadata().get(NamespaceContext.class) : 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(TypeInfo 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.getQName().equals(XSD_BASE64)) {
+ byteEncoding = BASE64_ENCODING;
+ } else if (simpleType.getQName().equals(XSD_HEXBIN)) {
+ byteEncoding = BASE64_ENCODING;
+ }
+ }
+ if (byteEncoding == BASE64_ENCODING) {
+ return printBase64Binary((byte[])obj);
+ } else if (byteEncoding == HEXBIN_ENCODING) {
+ return printHexBinary((byte[])obj);
+ }
+ } else if (obj instanceof QName) {
+ NamespaceContext namespaceContext =
+ (NamespaceContext)((context != null) ? context.getMetadata().get(NamespaceContext.class) : null);
+ return printQName((QName)obj, namespaceContext);
+ }
+ return obj.toString();
+ }
+
+ public static boolean isSimpleXSDType(QName typeName) {
+ return typeName.getNamespaceURI().equals(URI_2001_SCHEMA_XSD)
+ && XSD_SIMPLE_TYPES.get(typeName.getLocalPart()) != null;
+ }
+
+ public int getByteEncoding() {
+ return byteEncoding;
+ }
+
+ public void setByteEncoding(int byteEncoding) {
+ this.byteEncoding = byteEncoding;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/TransformerExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/TransformerExtension.java
new file mode 100644
index 0000000000..374ac58e0d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/TransformerExtension.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.spi.databinding.extension;
+
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Scope;
+import org.osoa.sca.annotations.Service;
+
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.TransformerRegistry;
+
+/**
+ * Base Implementation of Transformer which provides the registration to the transformer registry
+ *
+ * @version $Rev$ $Date$
+ */
+@Service(Transformer.class)
+@Scope("COMPOSITE")
+@EagerInit
+public abstract class TransformerExtension<S, T> implements Transformer {
+
+ protected TransformerRegistry registry;
+
+ protected TransformerExtension() {
+ super();
+ }
+
+ @Reference
+ public void setTransformerRegistry(TransformerRegistry registry) {
+ this.registry = registry;
+ }
+
+ @Init
+ public void init() {
+ registry.registerTransformer(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/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/XSDDataTypeConverter.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/XSDDataTypeConverter.java
new file mode 100644
index 0000000000..a0c75570bd
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/databinding/extension/XSDDataTypeConverter.java
@@ -0,0 +1,940 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.spi.databinding.extension;
+
+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);
+ }
+ }
+ }
+
+ /**
+ * <p/>
+ * Utility class for xs:hexbinary. </p>
+ */
+ public static final class HexBinary {
+ private HexBinary() {
+ }
+
+ /**
+ * Converts the string <code>pValue</code> 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 <code>pHexBinary</code> 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);
+ }
+ }
+
+ /**
+ * <p/>
+ * An instance of {@link java.text.Format}, which may be used to parse and format <code>xs:dateTime</code> values.
+ * </p>
+ */
+ 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/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ArtifactResolver.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ArtifactResolver.java
new file mode 100644
index 0000000000..bd4c29e48b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ArtifactResolver.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.spi.deployer;
+
+import java.net.URL;
+import java.util.Map;
+
+import org.apache.tuscany.spi.model.Contribution;
+
+
+/**
+ * SCA Assemblies reference many artifacts of a wide variety of types. These
+ * include:
+ * <ul>
+ * <li> Reference from one SCA composite to another SCA composite
+ * <li> Reference to PolicySet files
+ * <li> Reference to interface definition files, either WSDL or Java interfaces
+ * <li> Reference to XSD files
+ * <li> Reference to any of a wide variety of implementation artifact files,
+ * including Java classes, BPEL scripts, C++ DLLs and classes, PHP scripts
+ * </ul>
+ * 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 ArtifactResolver {
+ /**
+ * Resolve an artifact by the qualified name
+ *
+ * @param contribution the model of the contribution
+ * @param modelClass The java type of the artifact
+ * @param namespace The namespace of the artifact
+ * @param name The name of the artifact
+ * @param attributes Additional attributes that can be used to constrain the
+ * resolution
+ * @param context The deployment context
+ * @return The resolved artifact
+ */
+ <T> T resolve(Contribution contribution,
+ Class<T> modelClass,
+ String namespace,
+ String name,
+ Map attributes,
+ DeploymentContext context);
+
+ /**
+ * Resolve an artifact by the URI. Some typical use cases are:
+ * <ul>
+ * <li>Reference a XML schema using
+ * {http://www.w3.org/2001/XMLSchema-instance}schemaLocation or
+ * <li>Reference a list of WSDLs using
+ * {http://www.w3.org/2004/08/wsdl-instance}wsdlLocation
+ * </ul>
+ * @param targetNamespace The target namespace of the referenced artifact,
+ * if the targetNamespace is null, then it's not specified
+ * @param location The URI of the referenced artifact, it can be absolute or
+ * relative
+ * @param baseURI The URI of the owning artifact
+ *
+ * @return The URI of the resolved artifact
+ */
+ URL resolve(Contribution contribution, String targetNamespace, String location, String baseURI);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ArtifactResolverRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ArtifactResolverRegistry.java
new file mode 100644
index 0000000000..f24fb7269a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ArtifactResolverRegistry.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.spi.deployer;
+
+
+/**
+ * Registry for artifact resolvers
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ArtifactResolverRegistry extends ArtifactResolver {
+ /**
+ * Register a resolver by the type of artifacts. For example, you can
+ * register a resolver to resolve WSDL model objects and other resolver
+ * for java classes
+ *
+ * @param modelClass The java type of the model object
+ * @param resolver The resolver
+ */
+ void registerResolver(Class<?> modelClass, ArtifactResolver resolver);
+
+ /**
+ * Unregister all resolvers for the given model class
+ *
+ * @param modelClass
+ */
+ void unregisterResolver(Class<?> modelClass);
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ChangeSetHandler.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ChangeSetHandler.java
new file mode 100644
index 0000000000..fead0453be
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ChangeSetHandler.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.spi.deployer;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.tuscany.host.deployment.DeploymentException;
+
+/**
+ * Interface implemented by services that process assembly change sets.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ChangeSetHandler {
+ /**
+ * Returns the content type that this implementation can handle.
+ *
+ * @return the content type that this implementation can handle
+ */
+ String getContentType();
+
+ /**
+ * Apply the changes in the supplied changeSet stream to an Assembly.
+ * The content on the stream must match the content type this implementation can handle.
+ *
+ * @param changeSet the set of changes to apply represented as the supported content type
+ * @throws DeploymentException if there was a problem applying the changes
+ * @throws IOException if there was a problem reading the stream
+ */
+ void applyChanges(InputStream changeSet) throws DeploymentException, IOException;
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ChangeSetHandlerRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ChangeSetHandlerRegistry.java
new file mode 100644
index 0000000000..df0bf4109b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ChangeSetHandlerRegistry.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.spi.deployer;
+
+/**
+ * Registry for ChangeSetHandler implementations.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ChangeSetHandlerRegistry {
+ void register(ChangeSetHandler handler);
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/CompositeClassLoader.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/CompositeClassLoader.java
new file mode 100644
index 0000000000..732c70d40e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/CompositeClassLoader.java
@@ -0,0 +1,181 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.deployer;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+/**
+ * ClassLoader associated with a composite.
+ * Each classloader has a name that can be used to reference it in the runtime.
+ * The classloader supports multiple parents allowing application code to share selected
+ * libraries with the runtime infrastructure as determined by the component's implementation type.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeClassLoader extends URLClassLoader {
+ private static final URL[] NOURLS = {};
+
+ private final URI name;
+ private final List<ClassLoader> parents = new CopyOnWriteArrayList<ClassLoader>();
+
+ /**
+ * Constructs a classloader with a name and a single parent.
+ *
+ * @param name a name used to identify this classloader
+ * @param parent the initial parent
+ */
+ public CompositeClassLoader(URI name, ClassLoader parent) {
+ this(name, NOURLS, parent);
+ }
+
+ /**
+ * Constructs a classloader with a name, a set of resources and a single parent.
+ *
+ * @param name a name used to identify this classloader
+ * @param urls the URLs from which to load classes and resources
+ * @param parent the initial parent
+ */
+ public CompositeClassLoader(URI name, URL[] urls, ClassLoader parent) {
+ super(urls);
+ this.name = name;
+ if (parent != null) {
+ parents.add(parent);
+ }
+ }
+
+
+ /**
+ * Add a resource URL to this classloader's classpath.
+ * The "createClassLoader" RuntimePermission is required.
+ *
+ * @param url an additional URL from which to load classes and resources
+ */
+ public void addURL(URL url) {
+ // Require RuntimePermission("createClassLoader")
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ sm.checkCreateClassLoader();
+ }
+ super.addURL(url);
+ }
+
+ /**
+ * Add a parent to this classloader.
+ * The "createClassLoader" RuntimePermission is required.
+ *
+ * @param parent an additional parent classloader
+ */
+ public void addParent(ClassLoader parent) {
+ // Require RuntimePermission("createClassLoader")
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ sm.checkCreateClassLoader();
+ }
+ if (parent != null) {
+ parents.add(parent);
+ }
+ }
+
+ /**
+ * Returns the name of this classloader.
+ *
+ * @return the name of this classloader
+ */
+ public URI getName() {
+ return name;
+ }
+
+ protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
+ // look for already loaded classes
+ Class clazz = findLoadedClass(name);
+ if (clazz != null) {
+ if (resolve) {
+ resolveClass(clazz);
+ }
+ return clazz;
+ }
+
+ // look in our parents
+ for (ClassLoader parent : parents) {
+ try {
+ clazz = parent.loadClass(name);
+ if (resolve) {
+ resolveClass(clazz);
+ }
+ return clazz;
+ } catch (ClassNotFoundException e) {
+ continue;
+ }
+ }
+
+ // look in our classpath
+ clazz = findClass(name);
+ if (resolve) {
+ resolveClass(clazz);
+ }
+ return clazz;
+ }
+
+
+ protected Class<?> findClass(String string) throws ClassNotFoundException {
+ return super.findClass(string);
+ }
+
+ public URL findResource(String name) {
+ // look in our parents
+ for (ClassLoader parent : parents) {
+ URL resource = parent.getResource(name);
+ if (resource != null) {
+ return resource;
+ }
+ }
+ // look in our classpath
+ return super.findResource(name);
+ }
+
+ public Enumeration<URL> findResources(String name) throws IOException {
+ // LinkedHashSet because we want all resources in the order found but no duplicates
+ Set<URL> resources = new LinkedHashSet<URL>();
+ for (ClassLoader parent : parents) {
+ Enumeration<URL> parentResources = parent.getResources(name);
+ while (parentResources.hasMoreElements()) {
+ resources.add(parentResources.nextElement());
+ }
+ }
+ Enumeration<URL> myResources = super.findResources(name);
+ while (myResources.hasMoreElements()) {
+ resources.add(myResources.nextElement());
+ }
+ return Collections.enumeration(resources);
+ }
+
+
+ public String toString() {
+ return name.toString();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContentType.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContentType.java
new file mode 100644
index 0000000000..d29f935dc4
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContentType.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.spi.deployer;
+
+public interface ContentType {
+ /**
+ * Archive specific content types
+ */
+ public static final String JAR = "application/x-compressed";
+ public static final String FOLDER = "application/vnd.tuscany.folder";
+
+ /**
+ * Artifact/File specific content types
+ */
+ public static final String CONTRIBUTION_METADATA = "application/vnd.tuscany.contribution.metadata";
+ public static final String COMPOSITE = "application/vnd.tuscany.composite";
+ public static final String WSDL = "application/vnd.tuscany.wsdl";
+ public static final String JAVA = "application/java-vm";
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContentTypeDescriber.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContentTypeDescriber.java
new file mode 100644
index 0000000000..e723080781
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContentTypeDescriber.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.spi.deployer;
+
+import java.net.URL;
+
+/**
+ * Provide content type for a given resource
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ContentTypeDescriber {
+ /**
+ * @param resourceURL the resource url
+ * @param defaultContentType the default content type
+ * @return the content type
+ */
+ String getContentType(URL resourceURL, String defaultContentType);
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessor.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessor.java
new file mode 100644
index 0000000000..a3d57870a7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessor.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.spi.deployer;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+
+import org.apache.tuscany.host.deployment.DeploymentException;
+import org.apache.tuscany.spi.model.Contribution;
+
+/**
+ * Interface for services that can process contributions.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ContributionProcessor {
+ /**
+ * Process a contribution or an artifact in the contribution from the input
+ * stream. The processor might add artifacts or model objects to the
+ * contribution object.
+ *
+ * @param contribution The contribution model that will be used to hold the
+ * results from the processing
+ * @param source The URI for the contribution/artifact
+ * @param inputStream The input stream for the contribution. The stream will
+ * not be closed but the read position after the call is
+ * undefined
+ * @throws DeploymentException if there was a problem with the contribution
+ * @throws IOException if there was a problem reading the stream
+ */
+ void processContent(Contribution contribution, URI source, InputStream inputStream) throws DeploymentException,
+ IOException;
+
+ /**
+ * Process a contribution from another model object. It will be used for the
+ * case that one artifact has other inline artifacts, for example, the WSDL
+ * with inline schemas. The schema contribution processor should be able to
+ * load the schema model from the WSDL definition.
+ *
+ * @param contribution The contribution model that will be used to hold the
+ * results from the processing
+ * @param source The URI for the contribution/artifact.
+ * @param modelObject A model object for further processing by the processor
+ * @throws DeploymentException
+ * @throws IOException
+ */
+ void processModel(Contribution contribution, URI source, Object modelObject) throws DeploymentException,
+ IOException;
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessorRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessorRegistry.java
new file mode 100644
index 0000000000..c1b6e93cb3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionProcessorRegistry.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.spi.deployer;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface ContributionProcessorRegistry extends ContributionProcessor {
+ /**
+ * Register a ContributionProcessor using the content type as the key
+ * @param processor
+ */
+ void register(String contentType, ContributionProcessor processor);
+
+ /**
+ * Unregister a ContributionProcessor by content type
+ * @param contentType
+ */
+ void unregister(String contentType);
+} \ No newline at end of file
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionRepository.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionRepository.java
new file mode 100644
index 0000000000..77a46237a0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/ContributionRepository.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.spi.deployer;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+import java.util.List;
+
+public interface ContributionRepository {
+ /**
+ * Get the URI of the SCA domain
+ *
+ * @return
+ */
+ URI getDomain();
+
+ /**
+ * Copies a contribution to the repository.
+ *
+ * @param contribution A URl pointing to the contribution being copied to
+ * the repository
+ * @param contributionStream InputStream with the content of the
+ * distribution
+ */
+ URL store(URI contribution, InputStream contributionStream) throws IOException;
+ /**
+ * Copy a contribution from the source URL to the repository
+ * @param contribution
+ * @param sourceURL
+ * @return
+ * @throws IOException
+ */
+ URL store(URI 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(URI contribution);
+
+ /**
+ * Remove a contribution from the repository
+ *
+ * @param contribution The URI of the contribution to be removed
+ */
+ void remove(URI contribution);
+
+ /**
+ * Get list of URIs for all the contributions in the repository
+ *
+ * @return A list of contribution URIs
+ */
+ List<URI> list();
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/Deployer.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/Deployer.java
new file mode 100644
index 0000000000..0b655fc5aa
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/Deployer.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.spi.deployer;
+
+import java.util.Collection;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ComponentException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.resolver.ResolutionException;
+
+/**
+ * Interface that can be used to deploy SCA bundles to a runtime.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Deployer {
+ /**
+ * Deploy a component as a child of the supplied parent. This operation creates a new component in the runtime to
+ * represent the supplied component definition. The type of component created will depend on the component
+ * definition implementation; for example, if the implementation of the component definition is a composite then
+ * typically a CompositeComponent would be returned.
+ *
+ * @param parent the parent context
+ * @param componentDefinition the component definition as parsed from an assembly
+ * @return the newly deployed component
+ */
+ <I extends Implementation<?>> Collection<Component> deploy(Component parent,
+ ComponentDefinition<I> componentDefinition)
+ throws LoaderException, BuilderException, ComponentException, ResolutionException;
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/DeploymentContext.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/DeploymentContext.java
new file mode 100644
index 0000000000..5ed5992b8c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/DeploymentContext.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.spi.deployer;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.Map;
+import javax.xml.stream.XMLInputFactory;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ScopeContainer;
+
+/**
+ * A holder that can be used during the load process to store information that is not part of the logical assembly
+ * model. This should be regarded as transient and references to this context should not be stored inside the model.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface DeploymentContext {
+ /**
+ * Returns the parent of this deployment context. Will be null for the context created at the root of a deployment.
+ *
+ * @return the parent of this deployment context; may be null
+ */
+ DeploymentContext getParent();
+
+ /**
+ * Returns a class loader that can be used to load application resources.
+ *
+ * @return a class loader that can be used to load application resources
+ */
+ ClassLoader getClassLoader();
+
+ /**
+ * Returns a factory that can be used to obtain an StAX XMLStreamReader.
+ *
+ * @return a factory that can be used to obtain an StAX XMLStreamReader
+ */
+ XMLInputFactory getXmlFactory();
+
+ /**
+ * Returns the ScopeContainer for the COMPOSITE scope that will be associated with this deployment unit.
+ *
+ * @return the ScopeContainer for the COMPOSITE scope that will be associated with this deployment unit
+ */
+ @Deprecated
+ ScopeContainer getCompositeScope();
+
+ /**
+ * Returns the URI of the composite scope group.
+ * @return the URI of the composite scope group
+ */
+ URI getGroupId();
+
+ /**
+ * Returns the location of the SCDL definition being deployed.
+ *
+ * @return the location of the SCDL definition being deployed
+ */
+ URL getScdlLocation();
+
+ /**
+ * Returns the URI of the composite component currently being deployed.
+ *
+ * @return the URI of the composite component currently being deployed
+ */
+ URI getComponentId();
+
+ /**
+ * Returns true if the autowire is enabled for the current deployment.
+ *
+ * @return true if the autowire is enabled for the current deployment
+ */
+ boolean isAutowire();
+
+ /**
+ * Sets if the autowire is enabled for the current deployment.
+ *
+ * @param autowire true if autowire is enabled
+ */
+ void setAutowire(boolean autowire);
+
+ @Deprecated
+ Map<URI, Component> getComponents();
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/DeploymentMonitor.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/DeploymentMonitor.java
new file mode 100644
index 0000000000..12ce6e73e6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/deployer/DeploymentMonitor.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.spi.deployer;
+
+import org.apache.tuscany.api.TuscanyException;
+import org.apache.tuscany.api.annotation.LogLevel;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface DeploymentMonitor {
+
+ @LogLevel("FINER")
+ void startDeployment();
+
+ @LogLevel("FINER")
+ void endDeployment();
+
+ @LogLevel("SEVERE")
+ void deploymentError(TuscanyException e);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/AbstractEventPublisher.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/AbstractEventPublisher.java
new file mode 100644
index 0000000000..cc20866cbb
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/AbstractEventPublisher.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.spi.event;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+/**
+ * Base implementation of an <code>EventPublisher</code>
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractEventPublisher implements EventPublisher {
+ protected static final EventFilter TRUE_FILTER = new TrueFilter();
+ protected Map<EventFilter, List<RuntimeEventListener>> 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<RuntimeEventListener> 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<RuntimeEventListener> list = getListeners().get(filter);
+ if (list == null) {
+ list = new CopyOnWriteArrayList<RuntimeEventListener>();
+ listeners.put(filter, list);
+ }
+ list.add(listener);
+ }
+ }
+
+ public void publish(Event event) {
+ assert event != null : "Event object was null";
+ for (Map.Entry<EventFilter, List<RuntimeEventListener>> entry : getListeners().entrySet()) {
+ if (entry.getKey().match(event)) {
+ for (RuntimeEventListener listener : entry.getValue()) {
+ listener.onEvent(event);
+ }
+ }
+ }
+ }
+
+ protected Map<EventFilter, List<RuntimeEventListener>> getListeners() {
+ if (listeners == null) {
+ listeners = new ConcurrentHashMap<EventFilter, List<RuntimeEventListener>>();
+ }
+ return listeners;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/Event.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/Event.java
new file mode 100644
index 0000000000..b874ca43c9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/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.spi.event;
+
+/**
+ * Represents an event that is propagated in the runtime
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public interface Event {
+
+ /**
+ * Returns the source of the event
+ */
+ Object getSource();
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/EventFilter.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/EventFilter.java
new file mode 100644
index 0000000000..d61d04cdc8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/EventFilter.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.spi.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
+ */
+ boolean match(Event event);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/EventPublisher.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/EventPublisher.java
new file mode 100644
index 0000000000..35df22fb9c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/EventPublisher.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.spi.event;
+
+/**
+ * Publishes events in the runtime
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public interface EventPublisher {
+
+ /**
+ * Publish an event
+ */
+ void publish(Event object);
+
+ /**
+ * Registers a listener to receive notifications for the context
+ */
+ void addListener(RuntimeEventListener listener);
+
+ /**
+ * Registers a listener to receive notifications for the context
+ */
+ void addListener(EventFilter filter, RuntimeEventListener listener);
+
+
+ /**
+ * Removes a previously registered listener
+ */
+ void removeListener(RuntimeEventListener listener);
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/RuntimeEventListener.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/RuntimeEventListener.java
new file mode 100644
index 0000000000..5146559098
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/RuntimeEventListener.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.spi.event;
+
+import java.util.EventListener;
+
+/**
+ * Listeners observe events fired in the SCA runtime.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface RuntimeEventListener extends EventListener {
+
+ void onEvent(Event event);
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/TrueFilter.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/TrueFilter.java
new file mode 100644
index 0000000000..81382b86ac
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/event/TrueFilter.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.spi.event;
+
+/**
+ * An event filter that always returns a true condition
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class TrueFilter implements EventFilter {
+
+ public boolean match(Event event) {
+ return true;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/AbstractComponentExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/AbstractComponentExtension.java
new file mode 100644
index 0000000000..46fa51711d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/AbstractComponentExtension.java
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.extension;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.osoa.sca.ComponentContext;
+
+import org.apache.tuscany.spi.component.AbstractSCAObject;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.DuplicateNameException;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.RegistrationException;
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.model.PropertyValue;
+
+/**
+ * @version Provides support for property accessors.
+ */
+public abstract class AbstractComponentExtension extends AbstractSCAObject implements Component {
+ protected final List<Service> services = new ArrayList<Service>();
+ protected final List<Reference> references = new ArrayList<Reference>();
+ protected final Map<String, SCAObject> children = new ConcurrentHashMap<String, SCAObject>();
+ protected ScopeContainer scopeContainer;
+ private Map<String, PropertyValue<?>> defaultPropertyValues;
+
+ /**
+ * Initializes component name and parent.
+ *
+ * @param name Name of the component.
+ */
+ public AbstractComponentExtension(URI name) {
+ super(name);
+ }
+
+ public ScopeContainer getScopeContainer() {
+ return scopeContainer;
+ }
+
+ public void setScopeContainer(ScopeContainer scopeContainer) {
+ this.scopeContainer = scopeContainer;
+ }
+
+ public Map<String, PropertyValue<?>> getDefaultPropertyValues() {
+ return defaultPropertyValues;
+ }
+
+ public void setDefaultPropertyValues(Map<String, PropertyValue<?>> defaultPropertyValues) {
+ this.defaultPropertyValues = defaultPropertyValues;
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+
+ public Service getService(String name) {
+ if (name == null) {
+ if (services.size() == 1) {
+ return services.get(0);
+ } else {
+ return null;
+ }
+ }
+ SCAObject o = children.get(name);
+ if (o instanceof Service) {
+ return (Service) o;
+ }
+ return null;
+ }
+
+ public Reference getReference(String name) {
+ if (name == null) {
+ if (references.size() == 1) {
+ return references.get(0);
+ } else {
+ return null;
+ }
+ }
+ SCAObject o = children.get(name);
+ if (o instanceof Reference) {
+ return (Reference) o;
+ }
+ return null;
+ }
+
+ public void register(Service service) throws RegistrationException {
+ String name = service.getUri().getFragment();
+ assert name != null;
+ if (children.get(name) != null) {
+ String uri = service.getUri().toString();
+ throw new DuplicateNameException("A service or reference is already registered with the name", uri);
+ }
+ children.put(name, service);
+ synchronized (services) {
+ services.add(service);
+ }
+ }
+
+ public void register(Reference reference) throws RegistrationException {
+ String name = reference.getUri().getFragment();
+ assert name != null;
+ if (children.get(name) != null) {
+ String uri = reference.getUri().toString();
+ throw new DuplicateNameException("A service or reference is already registered with the name", uri);
+ }
+ children.put(name, reference);
+ synchronized (services) {
+ references.add(reference);
+ }
+ }
+
+ public ComponentContext getComponentContext() {
+ // by default, a component will not give out a component context
+ return null;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ArtifactResolverExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ArtifactResolverExtension.java
new file mode 100644
index 0000000000..32d715e84b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ArtifactResolverExtension.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.spi.extension;
+
+import org.apache.tuscany.spi.deployer.ArtifactResolver;
+import org.apache.tuscany.spi.deployer.ArtifactResolverRegistry;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * The base class for ContributionProcessor implementations
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+@Service(ArtifactResolver.class)
+public abstract class ArtifactResolverExtension implements ArtifactResolver {
+ /**
+ * The ArtifactResolverRegistry that this resolver should register with; usually set by injection.
+ */
+ protected final ArtifactResolverRegistry registry;
+
+ /**
+ * @param registry the registry to set
+ */
+ @Constructor
+ public ArtifactResolverExtension(@Reference ArtifactResolverRegistry registry) {
+ this.registry = registry;
+ }
+
+ /**
+ * Initialize the resolver. It registers itself to the registry by model type it supports.
+ */
+ @Init
+ public void start() {
+ this.registry.registerResolver(this.getType(), this);
+ }
+
+ /**
+ * Destroy the resolver. It unregisters itself from the registry.
+ */
+ @Destroy
+ public void stop() {
+ registry.unregisterResolver(this.getType());
+ }
+
+ /**
+ * Returns the model type that this resolver can handle.
+ *
+ * @return the model type that this resolver can handle
+ */
+ public abstract Class<?> getType();
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/AtomicComponentExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/AtomicComponentExtension.java
new file mode 100644
index 0000000000..d3a835b5f5
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/AtomicComponentExtension.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.spi.extension;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.CoreRuntimeException;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ComponentException;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.wire.ProxyService;
+
+/**
+ * An extension point for atomic component type, which new implementation types may extend
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public abstract class AtomicComponentExtension extends AbstractComponentExtension implements AtomicComponent {
+ protected ScopeContainer scopeContainer;
+ protected Scope scope;
+ protected ProxyService proxyService;
+ protected WorkContext workContext;
+ protected final URI groupId;
+ private final int initLevel;
+ private final long maxIdleTime;
+ private final long maxAge;
+
+ protected AtomicComponentExtension(URI name,
+ ProxyService proxyService,
+ WorkContext workContext,
+ URI groupId,
+ int initLevel) {
+ this(name, proxyService, workContext, groupId, initLevel, -1, -1);
+ }
+
+ protected AtomicComponentExtension(URI name,
+ ProxyService proxyService,
+ WorkContext workContext,
+ URI groupId,
+ int initLevel,
+ long maxIdleTime,
+ long maxAge) {
+ super(name);
+ assert groupId != null;
+ assert !(maxIdleTime > 0 && maxAge > 0);
+ this.proxyService = proxyService;
+ this.workContext = workContext;
+ this.groupId = groupId;
+ this.initLevel = initLevel;
+ this.maxIdleTime = maxIdleTime;
+ this.maxAge = maxAge;
+ }
+
+ public Scope getScope() {
+ return scope;
+ }
+
+ public int getInitLevel() {
+ return initLevel;
+ }
+
+ public boolean isEagerInit() {
+ return initLevel > 0;
+ }
+
+ public long getMaxIdleTime() {
+ return maxIdleTime;
+ }
+
+ public long getMaxAge() {
+ return maxAge;
+ }
+
+ public void setScopeContainer(ScopeContainer scopeContainer) {
+ this.scopeContainer = scopeContainer;
+ scope = scopeContainer.getScope();
+ }
+
+ public void start() throws CoreRuntimeException {
+ super.start();
+ scopeContainer.register(this, groupId);
+ }
+
+ public void stop() {
+ scopeContainer.unregister(this);
+ super.stop();
+ }
+
+ public void removeInstance() throws ComponentException {
+ scopeContainer.remove(this);
+ }
+
+ public ObjectFactory createObjectFactory() {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/BindingBuilderExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/BindingBuilderExtension.java
new file mode 100644
index 0000000000..8490eb187d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/BindingBuilderExtension.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.spi.extension;
+
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.builder.BindingBuilder;
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.builder.BuilderRegistry;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.model.BindingDefinition;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+/**
+ * An extension point for binding builders. When adding support for new serviceBindings, implementations may extend this
+ * class as a convenience.
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+@EagerInit
+public abstract class BindingBuilderExtension<B extends BindingDefinition> implements BindingBuilder<B> {
+ protected BuilderRegistry builderRegistry;
+
+ @Reference
+ public void setBuilderRegistry(BuilderRegistry registry) {
+ this.builderRegistry = registry;
+ }
+
+ @Init
+ public void init() {
+ builderRegistry.register(getBindingType(), this);
+ }
+
+ public ServiceBinding build(ServiceDefinition serviceDefinition, B bindingDefinition, DeploymentContext context)
+ throws BuilderException {
+ return null;
+ }
+
+ public ReferenceBinding build(ReferenceDefinition boundReferenceDefinition,
+ B bindingDefinition,
+ DeploymentContext context) throws BuilderException {
+ return null;
+ }
+
+ protected abstract Class<B> getBindingType();
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ComponentBuilderExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ComponentBuilderExtension.java
new file mode 100644
index 0000000000..203a703133
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ComponentBuilderExtension.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.spi.extension;
+
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.builder.BuilderRegistry;
+import org.apache.tuscany.spi.builder.ComponentBuilder;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.policy.PolicyBuilderRegistry;
+import org.apache.tuscany.spi.wire.ProxyService;
+
+/**
+ * An extension point for component builders. When adding support for new component types, implementations may extend
+ * this class as a convenience.
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+@EagerInit
+public abstract class ComponentBuilderExtension<I extends Implementation<?>> implements ComponentBuilder<I> {
+ protected BuilderRegistry builderRegistry;
+ protected ScopeRegistry scopeRegistry;
+ protected ProxyService proxyService;
+ protected WorkContext workContext;
+ protected PolicyBuilderRegistry policyBuilderRegistry;
+
+ @Reference
+ public void setBuilderRegistry(BuilderRegistry registry) {
+ this.builderRegistry = registry;
+ }
+
+ @Reference
+ public void setScopeRegistry(ScopeRegistry scopeRegistry) {
+ this.scopeRegistry = scopeRegistry;
+ }
+
+ @Reference
+ public void setProxyService(ProxyService proxyService) {
+ this.proxyService = proxyService;
+ }
+
+ @Reference
+ public void setWorkContext(WorkContext workContext) {
+ this.workContext = workContext;
+ }
+
+ @Reference
+ public void setPolicyBuilderRegistry(PolicyBuilderRegistry registry) {
+ policyBuilderRegistry = registry;
+ }
+
+ @Init
+ public void init() {
+ builderRegistry.register(getImplementationType(), this);
+ }
+
+ protected abstract Class<I> getImplementationType();
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ComponentTypeLoaderExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ComponentTypeLoaderExtension.java
new file mode 100644
index 0000000000..097b94318a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ComponentTypeLoaderExtension.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.spi.extension;
+
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Scope;
+
+import org.apache.tuscany.spi.loader.ComponentTypeLoader;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.Implementation;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@Scope("COMPOSITE")
+@EagerInit
+public abstract class ComponentTypeLoaderExtension<I extends Implementation> implements ComponentTypeLoader<I> {
+ protected LoaderRegistry loaderRegistry;
+
+ protected ComponentTypeLoaderExtension() {
+ }
+
+ protected ComponentTypeLoaderExtension(LoaderRegistry loaderRegistry) {
+ this.loaderRegistry = loaderRegistry;
+ }
+
+ @Reference
+ public void setLoaderRegistry(LoaderRegistry loaderRegistry) {
+ this.loaderRegistry = loaderRegistry;
+ }
+
+ @Init
+ public void start() {
+ loaderRegistry.registerLoader(getImplementationClass(), this);
+ }
+
+ @Destroy
+ public void stop() {
+ loaderRegistry.unregisterLoader(getImplementationClass());
+ }
+
+ protected abstract Class<I> getImplementationClass();
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeComponentExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeComponentExtension.java
new file mode 100644
index 0000000000..5ca43b3e67
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/CompositeComponentExtension.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.spi.extension;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.event.Event;
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+/**
+ * An extension point for composite components, which new types may extend
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public abstract class CompositeComponentExtension extends AbstractComponentExtension implements RuntimeEventListener {
+
+ protected CompositeComponentExtension(URI name) {
+ super(name);
+ }
+
+ public Scope getScope() {
+ return Scope.SYSTEM;
+ }
+
+ public void onEvent(Event event) {
+ publish(event);
+ }
+
+ public TargetInvoker createTargetInvoker(String name, Operation operation)
+ throws TargetInvokerCreationException {
+ Service service = getService(name);
+ if (service != null) {
+ if (service.getServiceBindings().isEmpty()) {
+ // for now, throw an assertion exception.
+ // We will need to choose bindings during allocation
+ throw new AssertionError();
+ }
+ ServiceBinding binding = service.getServiceBindings().get(0);
+ return binding.createTargetInvoker(name, operation);
+ }
+ Reference reference = getReference(name);
+ if (reference != null) {
+ if (reference.getReferenceBindings().isEmpty()) {
+ // for now, throw an assertion exception.
+ // We will need to choose bindings during allocation
+ throw new AssertionError();
+ }
+ ReferenceBinding binding = reference.getReferenceBindings().get(0);
+ binding.createTargetInvoker(name, operation);
+ }
+ return null;
+ }
+
+ public TargetInvoker createTargetInvoker(String name, PhysicalOperationDefinition operation)
+ throws TargetInvokerCreationException {
+ Service service = getService(name);
+ if (service != null) {
+ if (service.getServiceBindings().isEmpty()) {
+ // for now, throw an assertion exception.
+ // We will need to choose bindings during allocation
+ throw new AssertionError();
+ }
+ ServiceBinding binding = service.getServiceBindings().get(0);
+ return binding.createTargetInvoker(name, operation);
+ }
+ Reference reference = getReference(name);
+ if (reference != null) {
+ if (reference.getReferenceBindings().isEmpty()) {
+ // for now, throw an assertion exception.
+ // We will need to choose bindings during allocation
+ throw new AssertionError();
+ }
+ ReferenceBinding binding = reference.getReferenceBindings().get(0);
+ binding.createTargetInvoker(name, operation);
+ }
+ return null;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ContributionProcessorExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ContributionProcessorExtension.java
new file mode 100644
index 0000000000..8b9b1e8dc7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ContributionProcessorExtension.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.spi.extension;
+
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Service;
+
+import org.apache.tuscany.spi.deployer.ContributionProcessor;
+import org.apache.tuscany.spi.deployer.ContributionProcessorRegistry;
+
+/**
+ * The base class for ContributionProcessor implementations
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+@Service(ContributionProcessor.class)
+public abstract class ContributionProcessorExtension implements ContributionProcessor {
+ /**
+ * The ContributionProcessorRegistry that this processor should register with; usually set by injection. This
+ * registry may also be used to process other sub-artifacts.
+ */
+ protected ContributionProcessorRegistry registry;
+
+ /**
+ * @param registry the registry to set
+ */
+ @Reference
+ public void setContributionProcessorRegistry(ContributionProcessorRegistry registry) {
+ this.registry = registry;
+ }
+
+ /**
+ * Initialize the processor. It registers itself to the registry by content type it supports.
+ */
+ @Init
+ public void start() {
+ registry.register(this.getContentType(), this);
+ }
+
+ /**
+ * Destroy the processor. It unregisters itself from the registry.
+ */
+ @Destroy
+ public void stop() {
+ registry.unregister(this.getContentType());
+ }
+
+ /**
+ * Returns the content type that this implementation can handle.
+ *
+ * @return the content type that this implementation can handle
+ */
+ public abstract String getContentType();
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ExecutionMonitor.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ExecutionMonitor.java
new file mode 100644
index 0000000000..fc6e5b7a14
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ExecutionMonitor.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.spi.extension;
+
+/**
+ * A monitor used to log events during an invocation
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public interface ExecutionMonitor {
+
+ /**
+ * Logs an exception thrown during an invocation
+ */
+ void executionError(Throwable e);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/InterceptorBuilderExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/InterceptorBuilderExtension.java
new file mode 100644
index 0000000000..85cd3a1fa2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/InterceptorBuilderExtension.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.spi.extension;
+
+import javax.xml.namespace.QName;
+
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.builder.interceptor.InterceptorBuilder;
+import org.apache.tuscany.spi.builder.interceptor.InterceptorBuilderRegistry;
+
+/**
+ * Abstract class interceptor builders may extend to handle registration with the interceptor builder registry
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+public abstract class InterceptorBuilderExtension implements InterceptorBuilder {
+ protected InterceptorBuilderRegistry registry;
+
+ @Reference(required = true)
+ public void setRegistry(InterceptorBuilderRegistry registry) {
+ this.registry = registry;
+ }
+
+ @Init
+ public void init() {
+ registry.register(getName(), this);
+ }
+
+ protected abstract QName getName();
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/LoaderExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/LoaderExtension.java
new file mode 100644
index 0000000000..db041cd51d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/LoaderExtension.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.spi.extension;
+
+import javax.xml.namespace.QName;
+
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.StAXElementLoader;
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * Support class for extending the Loader mechanism.
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+public abstract class LoaderExtension<T extends ModelObject> implements StAXElementLoader<T> {
+ /**
+ * The LoaderRegistry that this loader should register with; usually set by injection. This registry may also be
+ * used to load sub-elements.
+ */
+ protected LoaderRegistry registry;
+
+ /**
+ * Constructor specifies the registry to register with.
+ *
+ * @param registry the LoaderRegistry this loader should register with
+ */
+ protected LoaderExtension(@Reference LoaderRegistry registry) {
+ this.registry = registry;
+ }
+
+ /**
+ * Initialize the loader. The base implementation registers this loader with the registry as a handler for the XML
+ * type returned by {@link #getXMLType()}. Implementations may override this to register the loader as a handler for
+ * multiple XML types.
+ */
+ @Init
+ public void start() {
+ registry.registerLoader(getXMLType(), this);
+ }
+
+ /**
+ * Destroy the loader. The base implementation unregisters the loader from the regsitry based on the type returned
+ * by {@link #getXMLType()}.
+ */
+ @Destroy
+ public void stop() {
+ registry.unregisterLoader(getXMLType(), this);
+ }
+
+ /**
+ * Returns the QName of the element that this implementation handles.
+ *
+ * @return the QName of the element that this implementation handles
+ */
+ public abstract QName getXMLType();
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ReferenceBindingExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ReferenceBindingExtension.java
new file mode 100644
index 0000000000..1f577a4104
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ReferenceBindingExtension.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.spi.extension;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.component.AbstractSCAObject;
+import org.apache.tuscany.spi.component.ReferenceBinding;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * The default implementation of an SCA reference
+ *
+ * @version $Rev$ $Date$
+ * @Deprecated
+ */
+public abstract class ReferenceBindingExtension extends AbstractSCAObject implements ReferenceBinding {
+ protected Wire wire;
+ protected ServiceContract<?> bindingServiceContract;
+ protected URI targetUri;
+
+ protected ReferenceBindingExtension(URI name, URI targetUri) {
+ super(name);
+ this.targetUri = targetUri;
+ }
+
+ public ServiceContract<?> getBindingServiceContract() {
+ return bindingServiceContract;
+ }
+
+ public Wire getWire() {
+ return wire;
+ }
+
+ public void setWire(Wire wire) {
+ this.wire = wire;
+ }
+
+
+ public URI getTargetUri() {
+ return targetUri;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ServiceBindingExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ServiceBindingExtension.java
new file mode 100644
index 0000000000..eb8aa5dac2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/ServiceBindingExtension.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.spi.extension;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.CoreRuntimeException;
+import org.apache.tuscany.spi.component.AbstractSCAObject;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * The default implementation of an SCA service
+ *
+ * @version $Rev$ $Date$
+ * @Deprecated
+ */
+public abstract class ServiceBindingExtension extends AbstractSCAObject implements ServiceBinding {
+ protected ServiceContract<?> bindingServiceContract;
+ protected Wire wire;
+
+ public ServiceBindingExtension(URI name) throws CoreRuntimeException {
+ super(name);
+ }
+
+ public TargetInvoker createTargetInvoker(ServiceContract contract, Operation operation)
+ throws TargetInvokerCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public ServiceContract<?> getBindingServiceContract() {
+ return bindingServiceContract;
+ }
+
+ public Wire getWire() {
+ return wire;
+ }
+
+ public void setWire(Wire wire) {
+ this.wire = wire;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/TargetInvokerExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/TargetInvokerExtension.java
new file mode 100644
index 0000000000..1250907085
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/extension/TargetInvokerExtension.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.spi.extension;
+
+import java.lang.reflect.InvocationTargetException;
+import java.net.URI;
+import java.util.LinkedList;
+
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+/**
+ * The default implementation of a TargetInvoker
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class TargetInvokerExtension implements TargetInvoker {
+ protected boolean cacheable;
+
+ public Message invoke(Message msg) throws InvocationRuntimeException {
+ try {
+ Object messageId = msg.getMessageId();
+ WorkContext workContext = msg.getWorkContext();
+ if (messageId != null) {
+ workContext.setCorrelationId(messageId);
+ }
+ LinkedList<URI> callbackRoutingChain = msg.getCallbackUris();
+ if (callbackRoutingChain != null) {
+ workContext.setCallbackUris(callbackRoutingChain);
+ }
+ Object resp = invokeTarget(msg.getBody(), msg.getConversationSequence(), workContext);
+ msg.setBody(resp);
+ } catch (InvocationTargetException e) {
+ msg.setBodyWithFault(e.getCause());
+ }
+ return msg;
+ }
+
+ public boolean isCacheable() {
+ return cacheable;
+ }
+
+ public void setCacheable(boolean cacheable) {
+ this.cacheable = cacheable;
+ }
+
+ public boolean isOptimizable() {
+ return isCacheable();
+ }
+
+ public Object clone() throws CloneNotSupportedException {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException e) {
+ // TargetInvoker extends Cloneable so this should not have been thrown
+ throw new AssertionError(e);
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/BindingGenerator.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/BindingGenerator.java
new file mode 100644
index 0000000000..34b57bdb3f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/BindingGenerator.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.spi.generator;
+
+import org.apache.tuscany.spi.model.BindingDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface BindingGenerator {
+
+ PhysicalWireSourceDefinition generateWireSource(BindingDefinition definition, GeneratorContext context)
+ throws GenerationException;
+
+ PhysicalWireTargetDefinition generateWireTarget(BindingDefinition definition, GeneratorContext context)
+ throws GenerationException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/ComponentGenerator.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/ComponentGenerator.java
new file mode 100644
index 0000000000..583cd2574a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/ComponentGenerator.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.spi.generator;
+
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireSourceDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalWireTargetDefinition;
+
+/**
+ * Implementations are responsible for generating {@link org.apache.tuscany.spi.model.physical.PhysicalChangeSet}
+ * metadata used to provision components to service nodes
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ComponentGenerator<C extends ComponentDefinition<? extends Implementation>> {
+
+ /**
+ * Generates an {@link org.apache.tuscany.spi.model.physical.PhysicalComponentDefinition} based on a {@link
+ * org.apache.tuscany.spi.model.ComponentDefinition}. The resulting PhysicalComponentDefinition is added to the
+ * PhysicalChangeSet associated with the current GeneratorContext.
+ *
+ * @param definition the component definition to evaluate
+ * @param context the current generator context, which contains the PhysicalChangeSet to be marshalled
+ * @throws GenerationException if an error occurs during the generation process
+ */
+ void generate(C definition, GeneratorContext context) throws GenerationException;
+
+ /**
+ * Generates a {@link PhysicalWireSourceDefinition} used to attach a wire to a source component. Metadata contained
+ * in the PhysicalWireSourceDefinition is specific to the component implementation type and used when the wire is
+ * attached to its source on a service node.
+ *
+ * @param definition the component definition for the wire source
+ * @param referenceDefinition the source reference definition
+ * @param optimizable true is the wire may be optimized. ComponentGenerator implementations may decide to
+ * attach optimizable wires is a specialized manner, such as by not generating proxies
+ * @param context the current generator context
+ * @return the meta data used to attach the wire to its source on the service node
+ * @throws GenerationException if an error occurs during the generation process
+ */
+ PhysicalWireSourceDefinition generateWireSource(C definition,
+ ReferenceDefinition referenceDefinition,
+ boolean optimizable,
+ GeneratorContext context) throws GenerationException;
+
+ /**
+ * Generates a {@link PhysicalWireTargetDefinition} used to attach a wire to a target component. Metadata contained
+ * in the PhysicalWireSourceDefinition is specific to the component implementation type and used when the wire is
+ * attached to its target on a service node.
+ *
+ * @param definition the component definition for the wire source
+ * @param serviceDefinition the target refernce definition
+ * @param context the current generator context
+ * @return the meta data used to attach the wire to its target on the service node
+ * @throws GenerationException if an error occurs during the generation process
+ */
+ PhysicalWireTargetDefinition generateWireTarget(C definition,
+ ServiceDefinition serviceDefinition,
+ GeneratorContext context) throws GenerationException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/GenerationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/GenerationException.java
new file mode 100644
index 0000000000..33ab768494
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/GenerationException.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.spi.generator;
+
+import org.apache.tuscany.api.TuscanyException;
+
+/**
+ * Base generation exception
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class GenerationException extends TuscanyException {
+
+ public GenerationException() {
+ }
+
+ public GenerationException(String message) {
+ super(message);
+ }
+
+ public GenerationException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public GenerationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public GenerationException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+
+ public GenerationException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/GeneratorContext.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/GeneratorContext.java
new file mode 100644
index 0000000000..d1fb5e5a7a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/GeneratorContext.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.spi.generator;
+
+import org.apache.tuscany.spi.model.physical.PhysicalChangeSet;
+
+/**
+ * A context used during generation of physical definitions
+ *
+ * @version $Rev$ $Date$
+ */
+public interface GeneratorContext {
+
+ /**
+ * Returns the current changeset.
+ *
+ * @return the current changeset
+ */
+ PhysicalChangeSet getPhysicalChangeSet();
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/GeneratorRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/GeneratorRegistry.java
new file mode 100644
index 0000000000..a9c76d9fe4
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/GeneratorRegistry.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.spi.generator;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.model.BindingDefinition;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.IntentDefinition;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ResourceDefinition;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+/**
+ * A registry for generators
+ *
+ * @version $Rev$ $Date$
+ */
+public interface GeneratorRegistry {
+
+ public <T extends Implementation<?>> void register(Class<T> clazz,
+ ComponentGenerator<ComponentDefinition<T>> generator);
+
+ void register(Class<?> clazz, BindingGenerator generator);
+
+ <T extends IntentDefinition> void register(Class<T> phase, InterceptorGenerator<T> generator);
+
+ void register(Class<?> clazz, ResourceGenerator generator);
+
+ /**
+ * Generates a PhysicalComponentDefinition
+ *
+ * @param definition
+ * @param context
+ * @throws GenerationException
+ */
+ <C extends ComponentDefinition<? extends Implementation>> void generate(C definition, GeneratorContext context)
+ throws GenerationException;
+
+
+ /**
+ * Generates a PhysicalWireDefinition from a service binding to a component service
+ *
+ * @param contract
+ * @param bindingDefinition
+ * @param componentDefinition
+ * @param context
+ * @param serviceDefinition
+ * @throws GenerationException
+ */
+ <C extends ComponentDefinition<? extends Implementation>> void generateWire(ServiceContract<?> contract,
+ BindingDefinition bindingDefinition,
+ ServiceDefinition serviceDefinition,
+ C componentDefinition,
+ GeneratorContext context)
+ throws GenerationException;
+
+
+ <C extends ComponentDefinition<? extends Implementation>> void generateWire(C componentDefinition,
+ ReferenceDefinition referenceDefinition,
+ BindingDefinition bindingDefinition,
+ GeneratorContext context)
+ throws GenerationException;
+
+ <S extends ComponentDefinition<? extends Implementation>, T extends ComponentDefinition<? extends Implementation>>
+ void generateWire(S sourceDefinition,
+ ReferenceDefinition referenceDefinition,
+ ServiceDefinition serviceDefinition,
+ T targetDefinition,
+ GeneratorContext context) throws GenerationException;
+
+ URI generate(ResourceDefinition definition, GeneratorContext context) throws GenerationException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/InterceptorGenerator.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/InterceptorGenerator.java
new file mode 100644
index 0000000000..7f93aa61ce
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/InterceptorGenerator.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.spi.generator;
+
+import org.apache.tuscany.spi.model.IntentDefinition;
+import org.apache.tuscany.spi.model.physical.PhysicalInterceptorDefinition;
+
+/**
+ * Implementations are responsible for generating physical interceptor definitions for a wire based on an intent.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface InterceptorGenerator<T extends IntentDefinition> {
+
+ /**
+ * Generates the physical interceptor definition for a wire
+ *
+ * @param definition the intent definition
+ * @param context the current generator context
+ * @return the interceptor definition
+ * @throws GenerationException if an error occurs during the generation process
+ */
+ PhysicalInterceptorDefinition generate(T definition, GeneratorContext context) throws GenerationException;
+
+}
+
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/ResourceGenerator.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/ResourceGenerator.java
new file mode 100644
index 0000000000..2ef422c03d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/generator/ResourceGenerator.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.spi.generator;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.model.ResourceDefinition;
+
+/**
+ * Implementations generate physical resource definitions
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ResourceGenerator {
+
+ /**
+ * Updates the change set with a physical resource definition
+ *
+ * @param definition the logical resource definition to generate the physical definition from
+ * @param context the current generator context
+ * @return the id of the physical resource
+ * @throws GenerationException if an error occurs during the generation process
+ */
+ URI generate(ResourceDefinition definition, GeneratorContext context) throws GenerationException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceHost.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceHost.java
new file mode 100644
index 0000000000..b273ec6729
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceHost.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.spi.host;
+
+/**
+ * Interface implemented by host environments that allow for resolution of component implementation resources, e.g.
+ * items bound in a JNDI tree.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ResourceHost {
+
+ /**
+ * Resolve a resource matching the given type
+ *
+ * @param type the type of the resources
+ * @throws ResourceResolutionException if an error is encountered during resolution
+ */
+ <T> T resolveResource(Class<T> type) throws ResourceResolutionException;
+
+ /**
+ * Resolve a resource matching the given type and name
+ *
+ * @param type the type of the resources
+ * @param mappedName the mapped name of the resource
+ * @throws ResourceResolutionException if an error is encountered during resolution
+ */
+ <T> T resolveResource(Class<T> type, String mappedName) throws ResourceResolutionException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceHostRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceHostRegistry.java
new file mode 100644
index 0000000000..b4964cce3b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceHostRegistry.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.spi.host;
+
+/**
+ * Implementations manage a registry of resources and resource hosts in the runtime
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ResourceHostRegistry {
+ /**
+ * Registers a resource host for the given uri prefix
+ *
+ * @param uri the uri prefix the host resolves resources for
+ * @param host the resource host
+ */
+ void registerResourceHost(String uri, ResourceHost host);
+
+ /**
+ * Removes a resource host registered for the given uri prefix
+ */
+ void unregisterResourceHost(String uri);
+
+ /**
+ * Register a resource by type
+ *
+ * @param type the type of the resource
+ * @param resource the resource
+ */
+ void registerResource(Class<?> type, Object resource);
+
+ /**
+ * Register a resource by type and name
+ *
+ * @param type the type of the resource
+ * @param name the mapped resource name
+ * @param resource the resource
+ */
+ void registerResource(Class<?> type, String name, Object resource);
+
+ /**
+ * Unregister a resource
+ *
+ * @param type the type the resource was registered with
+ * @param name the mapped name the resource was registered with
+ */
+ void unregisterResource(Class<?> type, String name);
+
+ /**
+ * Unregister a resource
+ *
+ * @param type the type the resource was registered with
+ */
+ void unregisterResource(Class<?> type);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceResolutionException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceResolutionException.java
new file mode 100644
index 0000000000..23c18f5115
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ResourceResolutionException.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.spi.host;
+
+import org.apache.tuscany.api.TuscanyException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ResourceResolutionException extends TuscanyException {
+
+ public ResourceResolutionException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ServletHost.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ServletHost.java
new file mode 100644
index 0000000000..37937808d4
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/host/ServletHost.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.spi.host;
+
+import javax.servlet.Servlet;
+
+/**
+ * Interface implemented by host environments that allow Servlets to be registered.
+ * <p/>
+ * This interface allows an SCA system service to register a servlet to handle inbound requests.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ServletHost {
+ /**
+ * Register a mapping for an instance of a Servlet. This requests that the servlet container direct all requests to
+ * the designated mapping to the supplied Servlet instance.
+ *
+ * @param mapping the uri-mapping for the Servlet
+ * @param servlet the Servlet that should be invoked
+ */
+ void registerMapping(String mapping, Servlet servlet);
+
+ /**
+ * Unregister a servlet mapping. This directs the servlet contain not to direct any more requests to a previously
+ * registered Servlet.
+ *
+ * @param mapping the uri-mapping for the Servlet
+ * @return the servlet that was registered to the mapping, null if nothing was registered to the mapping
+ */
+ Servlet unregisterMapping(String mapping);
+
+ /**
+ * Check to see if a mapping exists.
+ *
+ * @param mapping the uri-mapping for the Servlet
+ * @return true if mapping is registered, false otherwise
+ */
+ boolean isMappingRegistered(String mapping);
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/ElementInfo.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/ElementInfo.java
new file mode 100644
index 0000000000..5a0bd3bb5f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/ElementInfo.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.spi.idl;
+
+import javax.xml.namespace.QName;
+
+/**
+ * An abstraction of XML schema elements
+ */
+public class ElementInfo {
+ private QName name;
+ private TypeInfo type;
+
+ /**
+ * @param name
+ * @param type
+ */
+ public ElementInfo(QName name, TypeInfo type) {
+ super();
+ this.name = name;
+ this.type = type;
+ }
+
+ /**
+ * @return the name
+ */
+ public QName getQName() {
+ return name;
+ }
+
+ /**
+ * @return the type
+ */
+ public TypeInfo getType() {
+ return type;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/InvalidConversationalOperationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/InvalidConversationalOperationException.java
new file mode 100644
index 0000000000..e2b4acec24
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/InvalidConversationalOperationException.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.spi.idl;
+
+import java.lang.reflect.Method;
+
+/**
+ * Denotes an invalid conversational interface definition
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidConversationalOperationException extends InvalidServiceContractException {
+ private final Method operation;
+
+ public InvalidConversationalOperationException(String message, String identifier, Method operation) {
+ super(message, identifier);
+ this.operation = operation;
+ }
+
+ public Method getOperation() {
+ return operation;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/InvalidServiceContractException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/InvalidServiceContractException.java
new file mode 100644
index 0000000000..e977592df0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/InvalidServiceContractException.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.spi.idl;
+
+import org.apache.tuscany.api.TuscanyException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public abstract class InvalidServiceContractException extends TuscanyException {
+
+ public InvalidServiceContractException() {
+ }
+
+ public InvalidServiceContractException(String message) {
+ super(message);
+ }
+
+ protected InvalidServiceContractException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public InvalidServiceContractException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ protected InvalidServiceContractException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+
+ public InvalidServiceContractException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/OverloadedOperationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/OverloadedOperationException.java
new file mode 100644
index 0000000000..b1d4cb4e7c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/OverloadedOperationException.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.spi.idl;
+
+import java.lang.reflect.Method;
+
+/**
+ * Exception thrown to indicate that a service contract specification contains an overloaded method.
+ *
+ * @version $Rev$ $Date$
+ */
+public class OverloadedOperationException extends InvalidServiceContractException {
+ private static final long serialVersionUID = -4658711318608885638L;
+ private final Method operation;
+
+ public OverloadedOperationException(Method operation) {
+ super(null, operation.getDeclaringClass().getName());
+ this.operation = operation;
+ }
+
+ public Method getOperation() {
+ return operation;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/ServiceFaultException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/ServiceFaultException.java
new file mode 100644
index 0000000000..559cf409cc
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/ServiceFaultException.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.spi.idl;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.api.TuscanyException;
+
+/**
+ * The generic java exception to wrap service faults
+ *
+ * @version $Rev$ $Date$
+ */
+public class ServiceFaultException extends TuscanyException {
+ private static final long serialVersionUID = -8002583655240625792L;
+ private Object faultInfo;
+ private QName logical;
+
+ /**
+ * @param message
+ * @param faultInfo
+ */
+ public ServiceFaultException(String message, Object faultInfo) {
+ super(message);
+ this.faultInfo = faultInfo;
+ }
+
+ /**
+ * @param message
+ * @param faultInfo
+ * @param cause
+ */
+ public ServiceFaultException(String message, Object faultInfo, Throwable cause) {
+ super(message, cause);
+ this.faultInfo = faultInfo;
+ }
+
+ /**
+ * @return the faultInfo
+ */
+ public Object getFaultInfo() {
+ return faultInfo;
+ }
+
+ public QName getLogical() {
+ return logical;
+ }
+
+ public void setLogical(QName logical) {
+ this.logical = logical;
+ }
+
+ public boolean isMatchingType(Object type) {
+ if (logical == null) {
+ return false;
+ }
+
+ if ((type instanceof QName) && logical.equals(type)) {
+ return true;
+ }
+ if (type instanceof XMLType && logical.equals(((XMLType)type).getElementName())) {
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/TypeInfo.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/TypeInfo.java
new file mode 100644
index 0000000000..9bb107812c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/TypeInfo.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.spi.idl;
+
+import javax.xml.namespace.QName;
+
+/**
+ * An abstraction of XML schema types
+ */
+public class TypeInfo {
+ private QName name;
+
+ private boolean isSimpleType;
+
+ private TypeInfo baseType;
+
+ /**
+ * @param name
+ * @param isSimpleType
+ */
+ public TypeInfo(QName name, boolean isSimpleType, TypeInfo baseType) {
+ super();
+ this.name = name;
+ this.isSimpleType = isSimpleType;
+ this.baseType = baseType;
+ }
+
+ /**
+ * @return the isSimpleType
+ */
+ public boolean isSimpleType() {
+ return isSimpleType;
+ }
+
+ /**
+ * @return the name
+ */
+ public QName getQName() {
+ return name;
+ }
+
+ /**
+ * @return the baseType
+ */
+ public TypeInfo getBaseType() {
+ return baseType;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/XMLType.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/XMLType.java
new file mode 100644
index 0000000000..1d626516b0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/XMLType.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.spi.idl;
+
+import javax.xml.namespace.QName;
+
+/**
+ * The metadata for an XML element or type
+ */
+public class XMLType {
+ public static final XMLType UNKNOWN = new XMLType(null, null);
+ private QName element;
+ private QName type;
+
+ /**
+ * @param element
+ */
+ public XMLType(ElementInfo element) {
+ super();
+ this.element = element.getQName();
+ if (element.getType() != null) {
+ this.type = element.getType().getQName();
+ }
+ }
+
+ /**
+ * @param element
+ */
+ public XMLType(TypeInfo type) {
+ this.element = null;
+ this.type = type.getQName();
+ }
+
+ public XMLType(QName element, QName type) {
+ this.element = element;
+ this.type = type;
+ }
+
+ /**
+ * @return the type
+ */
+ public QName getTypeName() {
+ return type;
+ }
+
+ public boolean isElement() {
+ return element != null;
+ }
+
+ public QName getElementName() {
+ return element;
+ }
+
+ public static XMLType getType(QName type) {
+ return new XMLType(null, type);
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + ((element == null) ? 0 : element.hashCode());
+ result = PRIME * result + ((type == null) ? 0 : type.hashCode());
+ return result;
+ }
+
+ /**
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final XMLType other = (XMLType)obj;
+ if (element == null) {
+ if (other.element != null) {
+ return false;
+ }
+ } else if (!element.equals(other.element)) {
+ return false;
+ }
+ if (type == null) {
+ if (other.type != null) {
+ return false;
+ }
+ } else if (!type.equals(other.type)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "Element: " + element + " Type: " + type;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/InterfaceJavaIntrospector.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/InterfaceJavaIntrospector.java
new file mode 100644
index 0000000000..13946793ea
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/InterfaceJavaIntrospector.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.spi.idl.java;
+
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+
+/**
+ * Processor for creating JavaServiceContract definitions from Java Classes.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface InterfaceJavaIntrospector {
+
+ /**
+ * Introspect a Java interface and return a service contract definition.
+ *
+ * @param type the interface to inspect
+ * @return a JavaServiceContract corresponding to the Java interface
+ */
+ <I> JavaServiceContract<I> introspect(Class<I> type) throws InvalidServiceContractException;
+
+ /**
+ * Introspect a Java interface and return a service contract definition.
+ *
+ * @param type the interface to inspect
+ * @param callback the callback interface to inspec
+ * @return a JavaServiceContract corresponding to the Java interface
+ */
+ <I, C> JavaServiceContract<I> introspect(Class<I> type, Class<C> callback) throws InvalidServiceContractException;
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaIDLUtils.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaIDLUtils.java
new file mode 100644
index 0000000000..83b8d19e79
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaIDLUtils.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.spi.idl.java;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+
+/**
+ * Contains methods for mapping between an operation in a {@link org.apache.tuscany.spi.model.ServiceContract} and a
+ * method defined by a Java interface
+ *
+ * @version $Rev$ $Date$
+ */
+public final class JavaIDLUtils {
+
+ private JavaIDLUtils() {
+ }
+
+ /**
+ * Return the method on the implementation class that matches the operation.
+ *
+ * @param implClass the implementation class or interface
+ * @param operation the operation to match
+ * @return the method described by the operation
+ * @throws NoSuchMethodException if no such method exists
+ * @Deprecated
+ */
+ public static <T> Method findMethod(Class<?> implClass, Operation<T> operation) throws NoSuchMethodException {
+ String name = operation.getName();
+ Class<?>[] paramTypes = getPhysicalTypes(operation);
+ return implClass.getMethod(name, paramTypes);
+ }
+
+ /**
+ * TODO JFM testme
+ */
+ public static Method findMethod2(Class<?> implClass, PhysicalOperationDefinition operation)
+ throws NoSuchMethodException, ClassNotFoundException {
+ String name = operation.getName();
+ List<String> params = operation.getParameters();
+ Class<?>[] types = new Class<?>[params.size()];
+ for (int i = 0; i < params.size(); i++) {
+ types[i] = implClass.getClassLoader().loadClass(params.get(i));
+ }
+ return implClass.getMethod(name, types);
+ }
+
+
+ /**
+ * @Deprecated
+ */
+ private static <T> Class<?>[] getPhysicalTypes(Operation<T> operation) {
+ DataType<List<DataType<T>>> inputType = operation.getInputType();
+ List<DataType<T>> types = inputType.getLogical();
+ Class<?>[] javaTypes = new Class<?>[types.size()];
+ for (int i = 0; i < javaTypes.length; i++) {
+ Type physical = types.get(i).getPhysical();
+ if (physical instanceof Class<?>) {
+ javaTypes[i] = (Class<?>) physical;
+ } else {
+ throw new UnsupportedOperationException();
+ }
+ }
+ return javaTypes;
+ }
+
+ /**
+ * Searches a collection of operations for a match against the given method
+ *
+ * @param method the method to match
+ * @param operations the operations to match against
+ * @return a matching operation or null
+ * @Deprecated
+ */
+ public static Operation findOperation(Method method, Collection<Operation<?>> operations) {
+ for (Operation<?> operation : operations) {
+ if (match(operation, method)) {
+ return operation;
+ }
+ }
+ return null;
+ }
+
+ public static PhysicalOperationDefinition findOperation2(Method method,
+ Collection<PhysicalOperationDefinition> operations) {
+ for (PhysicalOperationDefinition operation : operations) {
+ Class<?>[] params = method.getParameterTypes();
+ List<String> types = operation.getParameters();
+ boolean found = true;
+ if (types.size() == params.length && method.getName().equals(operation.getName())) {
+ for (int i = 0; i < params.length; i++) {
+ if (params[i].getName().equals(types.get(0))) {
+ found = false;
+ }
+ }
+ if (found) {
+ return operation;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Determines if the given operation matches the given method
+ *
+ * @return true if the operation matches, false if does not
+ */
+ private static <T> boolean match(Operation<T> operation, Method method) {
+ Class<?>[] params = method.getParameterTypes();
+ DataType<List<DataType<T>>> inputType = operation.getInputType();
+ List<DataType<T>> types = inputType.getLogical();
+ boolean found = 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())) {
+ found = false;
+ }
+ }
+ } else {
+ found = false;
+ }
+ return found;
+
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaInterfaceProcessor.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaInterfaceProcessor.java
new file mode 100644
index 0000000000..afe98f0773
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaInterfaceProcessor.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.spi.idl.java;
+
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+
+/**
+ * Implementations introspect metadata on a Java interface, populating the
+ * corresponding {@link JavaServiceContract}
+ *
+ * @version $Rev$ $Date$
+ */
+public interface JavaInterfaceProcessor {
+
+ void visitInterface(Class<?> clazz, Class<?> callbackClass, JavaServiceContract contract)
+ throws InvalidServiceContractException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaInterfaceProcessorExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaInterfaceProcessorExtension.java
new file mode 100644
index 0000000000..5c9ad40053
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaInterfaceProcessorExtension.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.spi.idl.java;
+
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * A convenience class for <code>JavaInterfaceProcessor</code> extensions that performs autowiring
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+public abstract class JavaInterfaceProcessorExtension implements JavaInterfaceProcessor {
+
+ protected JavaInterfaceProcessorRegistry registry;
+
+ @Reference
+ public void setRegistry(JavaInterfaceProcessorRegistry registry) {
+ this.registry = registry;
+ }
+
+ @Init
+ public void init() {
+ registry.registerProcessor(this);
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaInterfaceProcessorRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaInterfaceProcessorRegistry.java
new file mode 100644
index 0000000000..38c64e6f88
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaInterfaceProcessorRegistry.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.spi.idl.java;
+
+/**
+ * A registry of {@link JavaInterfaceProcessor}s. Interface processors update a service contract definition based on a
+ * Java interface
+ *
+ * @version $Rev$ $Date$
+ */
+public interface JavaInterfaceProcessorRegistry extends InterfaceJavaIntrospector {
+
+ /**
+ * Registers the given processor
+ */
+ void registerProcessor(JavaInterfaceProcessor processor);
+
+ /**
+ * Deregisters the given processor
+ */
+ void unregisterProcessor(JavaInterfaceProcessor processor);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaServiceContract.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaServiceContract.java
new file mode 100644
index 0000000000..9571dd86cf
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/idl/java/JavaServiceContract.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.spi.idl.java;
+
+import java.lang.reflect.Type;
+
+import org.apache.tuscany.spi.model.ServiceContract;
+
+/**
+ * Represents a service contract specified using a Java interface
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaServiceContract<I> extends ServiceContract<Type> {
+
+ public JavaServiceContract() {
+ }
+
+ public JavaServiceContract(Class<I> interfaceClass) {
+ super(interfaceClass);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessor.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessor.java
new file mode 100644
index 0000000000..d81ec73ba1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessor.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.spi.implementation.java;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.tuscany.spi.databinding.DataBinding;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+
+import org.apache.tuscany.api.annotation.DataType;
+
+/**
+ * Base class for ImplementationProcessors that handle annotations that add Properties.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractPropertyProcessor<A extends Annotation> extends ImplementationProcessorExtension {
+ private final Class<A> annotationClass;
+ private ImplementationProcessorService service;
+
+ protected AbstractPropertyProcessor(Class<A> annotationClass, ImplementationProcessorService service) {
+ this.annotationClass = annotationClass;
+ this.service = service;
+ }
+
+ public void visitMethod(
+ Method method,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException {
+ A annotation = method.getAnnotation(annotationClass);
+ if (annotation == null) {
+ return;
+ }
+
+ if (!Void.TYPE.equals(method.getReturnType())) {
+ throw new IllegalPropertyException("Method does not have void return type", method.toString());
+ }
+ Class[] paramTypes = method.getParameterTypes();
+ if (paramTypes.length != 1) {
+ throw new IllegalPropertyException("Method must have a single parameter", method.toString());
+ }
+ Class<?> javaType = paramTypes[0];
+
+ String name = getName(annotation);
+ if (name == null || name.length() == 0) {
+ name = method.getName();
+ if (name.startsWith("set")) {
+ name = toPropertyName(method.getName());
+ }
+ }
+
+ Map<String, JavaMappedProperty<?>> properties = type.getProperties();
+ if (properties.containsKey(name)) {
+ throw new DuplicatePropertyException(name);
+ }
+
+ Class<?> baseType = getBaseType(javaType, method.getGenericParameterTypes()[0]);
+ JavaMappedProperty<?> property = createProperty(name, baseType, method);
+ if (javaType.isArray() || Collection.class.isAssignableFrom(javaType)) {
+ property.setMany(true);
+ }
+
+ //add databinding available as annotations, as extensions
+ DataType propertyDataBinding = method.getAnnotation(DataType.class);
+ if (propertyDataBinding != null) {
+ property.getExtensions().put(DataBinding.class.getName(), propertyDataBinding.name());
+ }
+ initProperty(property, annotation, context);
+ properties.put(name, property);
+ }
+
+ public void visitField(
+ Field field,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException {
+
+ A annotation = field.getAnnotation(annotationClass);
+ if (annotation == null) {
+ return;
+ }
+
+ Class<?> javaType = field.getType();
+
+ String name = getName(annotation);
+ if (name == null || name.length() == 0) {
+ name = field.getName();
+ }
+
+ Map<String, JavaMappedProperty<?>> properties = type.getProperties();
+ if (properties.containsKey(name)) {
+ throw new DuplicatePropertyException(name);
+ }
+
+ Class<?> baseType = getBaseType(javaType, field.getGenericType());
+ JavaMappedProperty<?> property = createProperty(name, baseType, field);
+ if (javaType.isArray() || Collection.class.isAssignableFrom(javaType)) {
+ property.setMany(true);
+ }
+
+ //add databinding available as annotations, as extensions
+ DataType propertyDataBinding = field.getAnnotation(DataType.class);
+ if (propertyDataBinding != null) {
+ property.getExtensions().put(DataBinding.class.getName(), propertyDataBinding.name());
+ }
+
+ initProperty(property, annotation, context);
+ properties.put(name, property);
+ }
+
+ public <T> void visitConstructor(Constructor<T> constructor,
+ PojoComponentType<JavaMappedService,
+ JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException {
+
+ ConstructorDefinition<?> definition = type.getConstructorDefinition();
+ Class[] params = constructor.getParameterTypes();
+ Map<String, JavaMappedProperty<?>> properties = type.getProperties();
+ Annotation[][] annotations = constructor.getParameterAnnotations();
+ for (int i = 0; i < params.length; i++) {
+ Class<?> param = params[i];
+ Annotation[] paramAnnotations = annotations[i];
+ for (Annotation annotation : paramAnnotations) {
+ if (annotation.annotationType().equals(annotationClass)) {
+ if (definition == null) {
+ definition = new ConstructorDefinition<T>(constructor);
+ type.setConstructorDefinition(definition);
+ }
+ A monitorAnnot = annotationClass.cast(annotation);
+ String name = getName(monitorAnnot);
+ if (name == null || name.length() == 0) {
+ name = param.getName();
+ }
+
+ Class<?> baseType = getBaseType(param, constructor.getGenericParameterTypes()[i]);
+ JavaMappedProperty<?> property = createProperty(name, baseType, constructor);
+ if (param.isArray() || Collection.class.isAssignableFrom(param)) {
+ property.setMany(true);
+ }
+ initProperty(property, monitorAnnot, context);
+ properties.put(name, property);
+ service.addName(definition.getInjectionNames(), i, name);
+ }
+ }
+ }
+ }
+
+ protected abstract String getName(A annotation);
+
+ protected <T> void initProperty(JavaMappedProperty<T> property, A annotation, DeploymentContext context)
+ throws ProcessingException {
+ }
+
+ protected <T> JavaMappedProperty<T> createProperty(String name, Class<T> javaType, Member member)
+ throws ProcessingException {
+ return new JavaMappedProperty<T>(name, null, javaType, member);
+ }
+
+
+ public static String toPropertyName(String name) {
+ if (!name.startsWith("set")) {
+ return name;
+ }
+ return Character.toLowerCase(name.charAt(3)) + name.substring(4);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ConstructorDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ConstructorDefinition.java
new file mode 100644
index 0000000000..94c185966f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ConstructorDefinition.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.spi.implementation.java;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Hold injection information for the constructor used to instantiate a component implementation instance
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConstructorDefinition<T> {
+
+ private Constructor<T> constructor;
+ private List<String> injectionNames;
+
+ public ConstructorDefinition(Constructor<T> constructor) {
+ this.constructor = constructor;
+ injectionNames = new ArrayList<String>();
+ }
+
+ public Constructor<T> getConstructor() {
+ return constructor;
+ }
+
+ public List<String> getInjectionNames() {
+ return injectionNames;
+ }
+
+ public void setInjectionNames(List<String> injectionNames) {
+ this.injectionNames = injectionNames;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/DuplicatePropertyException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/DuplicatePropertyException.java
new file mode 100644
index 0000000000..87c4074fe7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/DuplicatePropertyException.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.spi.implementation.java;
+
+/**
+ * Thrown when an implementation has more than one property injection site with the same name
+ *
+ * @version $Rev$ $Date$
+ */
+public class DuplicatePropertyException extends ProcessingException {
+
+ public DuplicatePropertyException(String message) {
+ super(message);
+ }
+
+ public DuplicatePropertyException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/IllegalPropertyException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/IllegalPropertyException.java
new file mode 100644
index 0000000000..f251f60630
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/IllegalPropertyException.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.spi.implementation.java;
+
+/**
+ * Denotes an illegal property definition in a component type
+ *
+ * @version $Rev$ $Date$
+ */
+public class IllegalPropertyException extends ProcessingException {
+
+ public IllegalPropertyException(String message) {
+ super(message);
+ }
+
+
+ public IllegalPropertyException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ImplementationProcessor.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ImplementationProcessor.java
new file mode 100644
index 0000000000..e886eb7e6b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ImplementationProcessor.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.spi.implementation.java;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+
+/**
+ * Implementations process class-level metadata, typically parsing annotations and updating the corresponding
+ * <code>ComponentType</code>. A processor may, for example, create a {@link JavaMappedProperty} which is responsible
+ * for injecting a complex type on a component implementation instance when it is instantiated.
+ * <p/>
+ * Processors will receive callbacks as the implementation class is walked while evalauting an assembly. It is the
+ * responsibility of the parser to determine whether to perform an action during the callback.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ImplementationProcessor {
+
+ /**
+ * A callback received when the component implementation class is first loaded
+ *
+ * @param clazz the component implementation class
+ * @param type the incomplete component type associated with the implementation class
+ * @param context the current deployment context
+ * @throws ProcessingException if an error is encountered while processing metadata
+ */
+ <T> void visitClass(Class<T> clazz,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException;
+
+ /**
+ * A callback received as the component implementation class hierarchy is evaluated
+ *
+ * @param clazz the superclass in the component implmentation's class hierarchy
+ * @param type the incomplete component type associated with the implementation class
+ * @param context the current deployment context
+ * @throws ProcessingException if an error is encountered while processing metadata
+ */
+ <T> void visitSuperClass(
+ Class<T> clazz,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException;
+
+ /**
+ * A callback received as the component implementation's public and protected methods are evaluated
+ *
+ * @param method the current public or protected method being evaluated
+ * @param type the incomplete component type associated with the implementation class
+ * @param context the current deployment context
+ * @throws ProcessingException if an error is encountered while processing metadata
+ */
+ void visitMethod(
+ Method method,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException;
+
+ /**
+ * A callback received as the component implementation's constructor used for instantiation by the runtime is
+ * evaluated. If an implementation contains more than one constructor, the constructor passed to the callback will
+ * be chosen according to the algorithm described in the SCA Java Client and Implementation Model Specification.
+ *
+ * @param constructor the constructor used for instantiating component implementation instances
+ * @param type the incomplete component type associated with the implementation class
+ * @param context the current deployment context
+ * @throws ProcessingException if an error is encountered while processing metadata
+ */
+ <T> void visitConstructor(
+ Constructor<T> constructor,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context)
+ throws ProcessingException;
+
+ /**
+ * A callback received as the component implementation's public and protected fields are evaluated
+ *
+ * @param field the current public or protected field being evaluated
+ * @param type the incomplete component type associated with the implementation class
+ * @param context the current deployment context
+ * @throws ProcessingException if an error is encountered while processing metadata
+ */
+ void visitField(
+ Field field,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException;
+
+ /**
+ * The final callback received when all other callbacks during evaluation of the component implementation have been
+ * issued
+ *
+ * @param clazz the component implementation class
+ * @param type the incomplete component type associated with the implementation class
+ * @param context the current deployment context
+ * @throws ProcessingException if an error is encountered while processing metadata
+ */
+ <T> void visitEnd(
+ Class<T> clazz,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ImplementationProcessorExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ImplementationProcessorExtension.java
new file mode 100644
index 0000000000..66b973a179
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ImplementationProcessorExtension.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.spi.implementation.java;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.Collection;
+
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+
+/**
+ * A convenience class for annotation processors which alleviates the need to implement unused callbacks
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+public abstract class ImplementationProcessorExtension implements ImplementationProcessor {
+ private IntrospectionRegistry registry;
+
+ @Reference
+ public void setRegistry(IntrospectionRegistry registry) {
+ this.registry = registry;
+ }
+
+ @Init
+ public void init() {
+ registry.registerProcessor(this);
+ }
+
+ @Destroy
+ public void destroy() {
+ registry.unregisterProcessor(this);
+ }
+
+ public <T> void visitClass(Class<T> clazz,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context)
+ throws ProcessingException {
+ }
+
+ public <T> void visitSuperClass(Class<T> clazz,
+ PojoComponentType<JavaMappedService,
+ JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context)
+ throws ProcessingException {
+ }
+
+ public void visitMethod(Method method,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context)
+ throws ProcessingException {
+ }
+
+ public <T> void visitConstructor(Constructor<T> constructor,
+ PojoComponentType<JavaMappedService,
+ JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context)
+ throws ProcessingException {
+ }
+
+ public void visitField(Field field,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException {
+ }
+
+ public <T> void visitEnd(Class<T> clazz,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException {
+
+ }
+
+ protected static Class<?> getBaseType(Class<?> cls, Type genericType) {
+ if (cls.isArray()) {
+ return cls.getComponentType();
+ } else if (Collection.class.isAssignableFrom(cls)) {
+ if (genericType == cls) {
+ return Object.class;
+ } else {
+ ParameterizedType parameterizedType = (ParameterizedType) genericType;
+ Type baseType = parameterizedType.getActualTypeArguments()[0];
+ if (baseType instanceof Class) {
+ return (Class<?>) baseType;
+ } else if (baseType instanceof ParameterizedType) {
+ return (Class<?>) ((ParameterizedType) baseType).getRawType();
+ } else {
+ return null;
+ }
+ }
+ } else {
+ return cls;
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ImplementationProcessorService.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ImplementationProcessorService.java
new file mode 100644
index 0000000000..9dccfad23f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ImplementationProcessorService.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.spi.implementation.java;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+import java.lang.reflect.Type;
+import java.util.List;
+
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+/**
+ * Provides utility methods for Java implementation processing
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ImplementationProcessorService {
+
+ /**
+ * Introspects the given interface to produce a mapped service
+ */
+ JavaMappedService createService(Class<?> interfaze) throws InvalidServiceContractException;
+
+ JavaMappedReference createReference(String name, Member member, Class<?> paramType) throws ProcessingException;
+
+ /**
+ * Processes the callback contract for a given interface type
+ *
+ * @param interfaze the interface type to examine
+ * @param contract the service contract the callback is associated wth
+ * @throws InvalidServiceContractException
+ *
+ */
+ void processCallback(Class<?> interfaze, ServiceContract<?> contract) throws InvalidServiceContractException;
+
+ /**
+ * Determines if all the members of a collection have unique types
+ *
+ * @param collection the collection to analyze
+ * @return true if the types are unique
+ */
+ boolean areUnique(Class[] collection);
+
+ /**
+ * Inserts a name at the specified position, paddiling the list if its size is less than the position
+ */
+ void addName(List<String> names, int pos, String name);
+
+ /**
+ * Processes a constructor parameter by introspecting its annotations
+ *
+ * @param param the parameter to process
+ * @param genericParam the generic type of the parameter
+ * @param paramAnnotations the parameter annotations
+ * @param constructorNames the array of constructorNames specified by
+ * @param pos the declaration position of the constructor parameter
+ * @param type the component type associated with implementation being reflected
+ * @param injectionNames the list of parameter constructorNames specified on parameter annotations
+ * @throws ProcessingException
+ */
+ boolean processParam(Class<?> param,
+ Type genericParam,
+ Annotation[] paramAnnotations,
+ String[] constructorNames,
+ int pos,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ List<String> injectionNames) throws ProcessingException;
+
+ /**
+ * Returns true if <code>@Property</code> or <code>@Reference</code> are present in the given array
+ * @return true if one of the annotations are present
+ */
+ boolean injectionAnnotationsPresent(Annotation[][] annots);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/IntrospectionRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/IntrospectionRegistry.java
new file mode 100644
index 0000000000..a6122a6ff1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/IntrospectionRegistry.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.spi.implementation.java;
+
+/**
+ * A system service which tracks {@link ImplementationProcessor}s
+ *
+ * @version $Rev$ $Date$
+ */
+public interface IntrospectionRegistry extends Introspector {
+
+ /**
+ * Registers the given processor and makes it available during assembly evaluation (i.e. build)
+ */
+ void registerProcessor(ImplementationProcessor processor);
+
+ /**
+ * Deregisters the given processor
+ */
+ void unregisterProcessor(ImplementationProcessor processor);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/Introspector.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/Introspector.java
new file mode 100644
index 0000000000..bb7550440b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/Introspector.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.spi.implementation.java;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+
+/**
+ * Implementations are responsible for walking a component implementation class, adding additional component type
+ * information as appropriate
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Introspector {
+
+ /**
+ * Walks the given component implementation class
+ *
+ * @param clazz the component implementation class
+ * @param type the component type associated with the implementation class
+ * @return the updated component type
+ * @throws ProcessingException if an error is encountered evaluating the implementation class
+ */
+ PojoComponentType introspect(Class<?> clazz,
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type,
+ DeploymentContext context) throws ProcessingException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedComponentType.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedComponentType.java
new file mode 100644
index 0000000000..34ac8f53f9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedComponentType.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.spi.implementation.java;
+
+import org.apache.tuscany.spi.model.ComponentType;
+
+/**
+ * A specialized component type definition whose services, references and properties can be mapped to the Java
+ * programming model.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaMappedComponentType<
+ S extends JavaMappedService,
+ R extends JavaMappedReference,
+ P extends JavaMappedProperty<?>
+ > extends ComponentType<S, R, P> {
+
+ private Class<?> implClass;
+
+ public JavaMappedComponentType() {
+ }
+
+ public JavaMappedComponentType(Class<?> implClass) {
+ this.implClass = implClass;
+ }
+
+ /**
+ * Returns the implementation class associated with this component type.
+ *
+ * @return the implementation class associated with this component type
+ */
+ public Class<?> getImplClass() {
+ return implClass;
+ }
+
+ /**
+ * Sets the implementation class associated with this component type.
+ *
+ * @param implClass the implementation class associated with this component type
+ */
+ public void setImplClass(Class<?> implClass) {
+ this.implClass = implClass;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedProperty.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedProperty.java
new file mode 100644
index 0000000000..6d1715a035
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedProperty.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.spi.implementation.java;
+
+import java.lang.reflect.Member;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.model.Property;
+
+/**
+ * A Property definition that is mapped to a specific location in the implementation class. This location will typically
+ * be used to inject property values.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaMappedProperty<T> extends Property<T> {
+ private Member member;
+
+ public JavaMappedProperty() {
+ }
+
+ public JavaMappedProperty(String name, QName xmlType, Class<T> javaType) {
+ super(name, xmlType, javaType);
+ }
+
+ public JavaMappedProperty(String name, QName xmlType, Class<T> javaType, Member member) {
+ super(name, xmlType, javaType);
+ this.member = member;
+ }
+
+ /**
+ * Returns the Member that this property is mapped to.
+ *
+ * @return the Member that this property is mapped to
+ */
+ public Member getMember() {
+ return member;
+ }
+
+ /**
+ * Sets the Member that this property is mapped to
+ *
+ * @param member the Member that this property is mapped to
+ */
+ public void setMember(Member member) {
+ this.member = member;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedReference.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedReference.java
new file mode 100644
index 0000000000..26b79068c2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedReference.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.spi.implementation.java;
+
+import java.lang.reflect.Member;
+import java.net.URI;
+
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+/**
+ * A ReferenceDefinition definition that is mapped to a specific location in the implementation class. This location
+ * will typically be used to inject reference values.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaMappedReference extends ReferenceDefinition {
+ private Member member;
+
+ public JavaMappedReference() {
+ }
+
+ public JavaMappedReference(URI name, ServiceContract serviceContract, Member member) {
+ super(name, serviceContract);
+ this.member = member;
+ }
+
+ /**
+ * Returns the Member that this reference is mapped to.
+ *
+ * @return the Member that this reference is mapped to
+ */
+ public Member getMember() {
+ return member;
+ }
+
+ /**
+ * Sets the Member that this reference is mapped to
+ *
+ * @param member the Member that this reference is mapped to
+ */
+ public void setMember(Member member) {
+ this.member = member;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedService.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedService.java
new file mode 100644
index 0000000000..d7675da4e9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/JavaMappedService.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.implementation.java;
+
+import java.lang.reflect.Member;
+import java.net.URI;
+
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+/**
+ * A ServiceDefinition definition that is mapped to a Java interface. The mapped interface is not required to be the
+ * same as the interface specified in the service contract. This is to allow the service contract to be specified using
+ * different interface definition languages or, in the case were the IDL is Java, to allow the service definition to be
+ * loaded from a different classloader.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaMappedService extends ServiceDefinition {
+ private Class<?> serviceInterface;
+ private Member callbackMember;
+
+ public JavaMappedService() {
+ }
+
+ public JavaMappedService(Class<?> serviceInterface) {
+ this.serviceInterface = serviceInterface;
+ }
+
+ public JavaMappedService(URI name, ServiceContract contract, boolean remotable) {
+ super(name, contract, remotable);
+ }
+
+ public JavaMappedService(URI name,
+ ServiceContract contract,
+ boolean remotable,
+ String callbackRefName,
+ Member callbackMember) {
+ super(name, contract, remotable, callbackRefName);
+ this.callbackMember = callbackMember;
+ }
+
+ /**
+ * Returns the Java interface for this service. This may be different from the interface that defines the service
+ * contract.
+ *
+ * @return the Java interface for this service
+ */
+ public Class<?> getServiceInterface() {
+ return serviceInterface;
+ }
+
+ /**
+ * Sets the Java interface for this service. This may be different from the interface used to define the service
+ * contract.
+ *
+ * @param serviceInterface the Java interface for this service
+ */
+ public void setServiceInterface(Class<?> serviceInterface) {
+ this.serviceInterface = serviceInterface;
+ }
+
+ public Member getCallbackMember() {
+ return callbackMember;
+ }
+
+ public void setCallbackMember(Member callbackMember) {
+ this.callbackMember = callbackMember;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/PojoComponentType.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/PojoComponentType.java
new file mode 100644
index 0000000000..795e37e288
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/PojoComponentType.java
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.implementation.java;
+
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+/**
+ * A component type specialization for POJO implementations
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class PojoComponentType<S extends ServiceDefinition, R extends ReferenceDefinition, P extends Property<?>>
+ extends ComponentType<S, R, P> {
+ private Class<?> implClass;
+ private ConstructorDefinition<?> constructorDefinition;
+ private Method initMethod;
+ private Method destroyMethod;
+ private final Map<String, Resource> resources = new HashMap<String, Resource>();
+ private Member conversationIDMember;
+
+ /**
+ * Deprecated no-arg constructor, replaced with one that takes the POJO class.
+ */
+ @Deprecated
+ public PojoComponentType() {
+ }
+
+ /**
+ * Constructor specifying the java class for the POJO this is describing.
+ *
+ * @param implClass the java class for the POJO this is describing
+ */
+ public PojoComponentType(Class<?> implClass) {
+ this.implClass = implClass;
+ }
+
+ /**
+ * Returns the java class for the POJO this is describing.
+ *
+ * @return the java class for the POJO this is describing
+ */
+ public Class<?> getImplClass() {
+ return implClass;
+ }
+
+ /**
+ * Sets the java class for the POJO this is describing.
+ *
+ * @param implClass the java class for the POJO this is describing
+ */
+ public void setImplClass(Class<?> implClass) {
+ this.implClass = implClass;
+ }
+
+ /**
+ * Returns the constructor used to instantiate implementation instances.
+ *
+ * @return the constructor used to instantiate implementation instances
+ */
+ public ConstructorDefinition<?> getConstructorDefinition() {
+ return constructorDefinition;
+ }
+
+ /**
+ * Sets the constructor used to instantiate implementation instances
+ *
+ * @param definition the constructor used to instantiate implementation instances
+ */
+ public void setConstructorDefinition(ConstructorDefinition<?> definition) {
+ this.constructorDefinition = definition;
+ }
+
+ /**
+ * Returns the component initializer method.
+ *
+ * @return the component initializer method
+ */
+ public Method getInitMethod() {
+ return initMethod;
+ }
+
+ /**
+ * Sets the component initializer method.
+ *
+ * @param initMethod the component initializer method
+ */
+ public void setInitMethod(Method initMethod) {
+ this.initMethod = initMethod;
+ }
+
+ /**
+ * Returns the component destructor method.
+ *
+ * @return the component destructor method
+ */
+ public Method getDestroyMethod() {
+ return destroyMethod;
+ }
+
+ /**
+ * Sets the component destructor method.
+ *
+ * @param destroyMethod the component destructor method
+ */
+ public void setDestroyMethod(Method destroyMethod) {
+ this.destroyMethod = destroyMethod;
+ }
+
+ public Map<String, Resource> getResources() {
+ return resources;
+ }
+
+ public void add(Resource resource) {
+ resources.put(resource.getName(), resource);
+ }
+
+ public Member getConversationIDMember() {
+ return this.conversationIDMember;
+ }
+
+ public void setConversationIDMember(Member conversationIDMember) {
+ this.conversationIDMember = conversationIDMember;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ProcessingException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ProcessingException.java
new file mode 100644
index 0000000000..40fd1dfd15
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/ProcessingException.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.spi.implementation.java;
+
+import java.lang.reflect.Member;
+
+import org.apache.tuscany.spi.loader.LoaderException;
+
+/**
+ * Denotes a problem processing annotations on a POJO implementation
+ *
+ * @version $Rev$ $Date$
+ */
+public class ProcessingException extends LoaderException {
+ private Member member;
+
+ public ProcessingException() {
+ }
+
+ public ProcessingException(String message) {
+ super(message);
+ }
+
+ public ProcessingException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public ProcessingException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+
+ public ProcessingException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ProcessingException(Throwable cause) {
+ super(cause);
+ }
+
+
+ public Member getMemberName() {
+ return member;
+ }
+
+ public void setMember(Member member) {
+ this.member = member;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/Resource.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/Resource.java
new file mode 100644
index 0000000000..61e2970bec
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/implementation/java/Resource.java
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.implementation.java;
+
+import java.lang.reflect.Member;
+
+import org.apache.tuscany.spi.ObjectFactory;
+
+/**
+ * A resource dependency declared by a Java component implementation
+ *
+ * @version $Rev$ $Date$
+ * @param <T> the Java type of the resource
+ */
+public class Resource<T> {
+
+ private String name;
+ private String mappedName;
+ private boolean optional;
+ private Member member;
+ private Class<T> type;
+ private ObjectFactory<T> objectFactory;
+
+ public Resource(String name, Class<T> type, Member member) {
+ this.name = name;
+ this.type = type;
+ this.member = member;
+ }
+
+ /**
+ * The name of the resource
+ *
+ * @return the name of the resource
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name of the resource
+ *
+ * @param name the name of the resource
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns the URI of the resource
+ *
+ * @return the URI of the resource
+ */
+ public String getMappedName() {
+ return mappedName;
+ }
+
+ /**
+ * Sets the resource URI
+ */
+ public void setMappedName(String mappedName) {
+ this.mappedName = mappedName;
+ }
+
+ /**
+ * If true, the resource is optional
+ *
+ * @return true if the resource is optional
+ */
+ public boolean isOptional() {
+ return optional;
+ }
+
+ /**
+ * Sets whether the resource is optional
+ */
+ public void setOptional(boolean optional) {
+ this.optional = optional;
+ }
+
+ /**
+ * Returns the Member that this resource is mapped to.
+ *
+ * @return the Member that this resource is mapped to
+ */
+ public Member getMember() {
+ return member;
+ }
+
+ /**
+ * Sets the Member that this resource is mapped to
+ *
+ * @param member the Member that this resource is mapped to
+ */
+ public void setMember(Member member) {
+ this.member = member;
+ }
+
+ /**
+ * Returns the resource type
+ *
+ * @return the resource type
+ */
+ public Class<T> getType() {
+ return type;
+ }
+
+ /**
+ * Sets the resource type
+ */
+ public void setType(Class<T> type) {
+ this.type = type;
+ }
+
+ /**
+ * Returns the obeject factory
+ *
+ * @return the object factory
+ */
+ public ObjectFactory<T> getObjectFactory() {
+ return objectFactory;
+ }
+
+ /**
+ * Sets the object factory
+ */
+ public void setObjectFactory(ObjectFactory<T> objectFactory) {
+ this.objectFactory = objectFactory;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/ComponentTypeLoader.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/ComponentTypeLoader.java
new file mode 100644
index 0000000000..f83b2fc5b3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/ComponentTypeLoader.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.spi.loader;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.model.Implementation;
+
+/**
+ * Loader that will load the ComponentType definition for the supplied implementation. The actual mechanism used to load
+ * that definition is determined by the Client and Implementation Specification for the implementaion type. In some
+ * cases the definition may be contained in a XML file related to the implementation artifact in some well defined
+ * manner; other implementations may obtain this information from introspection of the artifact itself (for example, by
+ * examining Java annotations).
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ComponentTypeLoader<I extends Implementation> {
+ /**
+ * Load the component type definition for the supplied implementation.
+ *
+ * @param implementation the implementation whose component type information should be loaded
+ * @param context the current deployment context
+ * @throws LoaderException if there was a problem loading the configuration type
+ */
+ void load(I implementation, DeploymentContext context) throws LoaderException;
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/IllegalSCDLNameException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/IllegalSCDLNameException.java
new file mode 100644
index 0000000000..7c944c6251
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/IllegalSCDLNameException.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.spi.loader;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class IllegalSCDLNameException extends LoaderException {
+ public IllegalSCDLNameException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidConfigurationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidConfigurationException.java
new file mode 100644
index 0000000000..1c7f3e073d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidConfigurationException.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.spi.loader;
+
+/**
+ * Denotes an invalid configuration artifact
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidConfigurationException extends LoaderException {
+
+ public InvalidConfigurationException(String message) {
+ super(message);
+ }
+
+ public InvalidConfigurationException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidReferenceException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidReferenceException.java
new file mode 100644
index 0000000000..b2a5a26fec
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidReferenceException.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.spi.loader;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InvalidReferenceException extends LoaderException {
+ private static final long serialVersionUID = -4346666572527197558L;
+
+ public InvalidReferenceException(String message) {
+ super(message);
+ }
+
+ public InvalidReferenceException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public InvalidReferenceException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+
+ public InvalidReferenceException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidServiceException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidServiceException.java
new file mode 100644
index 0000000000..1717cae0c3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidServiceException.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.spi.loader;
+
+/**
+ * @version $Rev: 430937 $ $Date: 2006-08-12 06:47:56 +0530 (Sat, 12 Aug 2006) $
+ */
+public class InvalidServiceException extends LoaderException {
+
+ public InvalidServiceException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidValueException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidValueException.java
new file mode 100644
index 0000000000..b0ad8594ca
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidValueException.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.spi.loader;
+
+/**
+ * Exception that indicates the loader encountered an invalid value.
+ * The message should be set to the invalid value.
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidValueException extends LoaderException {
+
+ 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/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidWireException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidWireException.java
new file mode 100644
index 0000000000..b26c81168f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/InvalidWireException.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.spi.loader;
+
+/**
+ * @version $Rev: 430937 $ $Date: 2006-08-12 06:47:56 +0530 (Sat, 12 Aug 2006) $
+ */
+public class InvalidWireException extends LoaderException {
+
+ public InvalidWireException() {
+ }
+
+ public InvalidWireException(String message) {
+ super(message);
+ }
+
+
+ public InvalidWireException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public InvalidWireException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public InvalidWireException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/Loader.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/Loader.java
new file mode 100644
index 0000000000..14e5a0ec57
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/Loader.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.spi.loader;
+
+import java.net.URL;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * System service for loading physical artifacts that represent SCDL configurations and creating the model objects that
+ * represent them.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Loader {
+ /**
+ * Parse the supplied XML stream, dispatching to the appropriate registered loader for each element encountered in
+ * the stream.
+ * <p/>
+ * This method must be called with the XML cursor positioned on a START_ELEMENT event. When this method returns, the
+ * stream will be positioned on the corresponding END_ELEMENT event.
+ *
+ * @param object the model object to load configuration data into. If null, the loader dispatched to is
+ * responsible for creating a model object itself
+ * @param reader the XML stream to parse
+ * @param deploymentContext the current deployment context
+ * @return the model object obtained by parsing the current element on the stream
+ * @throws LoaderException if there was a problem loading the document
+ * @throws XMLStreamException if there was a problem reading the stream
+ */
+ ModelObject load(ModelObject object, XMLStreamReader reader, DeploymentContext deploymentContext)
+ throws XMLStreamException, LoaderException;
+
+ /**
+ * Load a model object from a specified location.
+ *
+ * @param object the model object to load configuration data into. If null, the loader dispatched to is responsible
+ * for creating a model object itself
+ * @param url the location of an XML document to be loaded
+ * @param type the type of ModelObject that is expected to be in the document
+ * @param context the current deployment context
+ * @return the model ojbect loaded from the document
+ * @throws LoaderException if there was a problem loading the document
+ */
+ <MO extends ModelObject> MO load(ModelObject object, URL url, Class<MO> type, DeploymentContext context)
+ throws LoaderException;
+
+ /**
+ * Load the component type definition for a given implementation. How the component type information is located is
+ * defined by the implementation specification. It may include loading from an XML sidefile, introspection of some
+ * artifact related to the implementation, some combination of those techniques or any other implementation-defined
+ * mechanism.
+ *
+ * @param implementation the implementation whose component type should be loaded
+ * @param context the current deployment context
+ * @throws LoaderException if there was a problem loading the component type definition
+ */
+ <I extends Implementation<?>> void loadComponentType(I implementation, DeploymentContext context)
+ throws LoaderException;
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderException.java
new file mode 100644
index 0000000000..defc6b06c9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderException.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.spi.loader;
+
+import org.apache.tuscany.api.TuscanyException;
+
+/**
+ * Base class for Exceptions raised during the loading process. Loader implementations should throw a subclass of this
+ * to indicate the actual problem.
+ *
+ * @version $Rev$ $Date$
+ */
+public class LoaderException extends TuscanyException {
+ public static final int UNDEFINED = -1;
+ private static final long serialVersionUID = -7459051598906813461L;
+ private String resourceURI;
+ private int line = UNDEFINED;
+ private int column = UNDEFINED;
+
+ public LoaderException() {
+ }
+
+ public LoaderException(String message) {
+ super(message);
+ }
+
+ public LoaderException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public LoaderException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public LoaderException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+
+ public LoaderException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Returns the location of the resource that was being loaded.
+ *
+ * @return the location of the resource that was being loaded
+ */
+ public String getResourceURI() {
+ return resourceURI;
+ }
+
+ /**
+ * Sets the location of the resource that was being loaded.
+ *
+ * @param resourceURI the location of the resource that was being loaded
+ */
+ public void setResourceURI(String resourceURI) {
+ this.resourceURI = resourceURI;
+ }
+
+ public int getLine() {
+ return line;
+ }
+
+ public void setLine(int line) {
+ this.line = line;
+ }
+
+ public int getColumn() {
+ return column;
+ }
+
+ public void setColumn(int column) {
+ this.column = column;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderRegistry.java
new file mode 100644
index 0000000000..ea88b99b22
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderRegistry.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.spi.loader;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * Registry for XML loaders that can parse a StAX input stream and return model objects.
+ * <p/>
+ * Loaders will typically be contributed to the system by any extension that needs to handle extension specific
+ * information contained in some XML configuration file. The loader can be contributed as a system component with an
+ * autowire reference to this builderRegistry which is used during initialization to actually register. </p> This
+ * builderRegistry can also be used to parse an input stream, dispatching to the appropriate loader for each element
+ * accepted. Loaders can call back to the builderRegistry to load sub-elements that they are not able to handle
+ * directly.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface LoaderRegistry extends Loader {
+ /**
+ * Register a loader. This operation will typically be called by a loader during its initialization.
+ *
+ * @param element the element that should be delegated to the contibuted loader
+ * @param loader a loader that is being contributed to the system
+ */
+ <T extends ModelObject> void registerLoader(QName element, StAXElementLoader<T> loader);
+
+ /**
+ * Unregister a loader. This will typically be called by a loader as it is being destroyed.
+ *
+ * @param element the element that was being delegated to the contibuted loader
+ * @param loader a loader that should no longer be used
+ */
+ <T extends ModelObject> void unregisterLoader(QName element, StAXElementLoader<T> loader);
+
+ /**
+ * Regsiter a component type loader.
+ *
+ * @param key a type of implementation this loader can load component types for
+ * @param loader the loader that is being contributed to the system
+ */
+ <I extends Implementation<?>> void registerLoader(Class<I> key, ComponentTypeLoader<I> loader);
+
+ /**
+ * Unregister a component type loader form the system.
+ *
+ * @param key a type of implementation whose loader should be unregistered
+ */
+ <I extends Implementation<?>> void unregisterLoader(Class<I> key);
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderUtil.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderUtil.java
new file mode 100644
index 0000000000..bf48f91a74
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/LoaderUtil.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.spi.loader;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamConstants;
+
+/**
+ * Utility functions to support loader implementations.
+ *
+ * @version $Rev$ $Date$
+ */
+public final class LoaderUtil {
+ private LoaderUtil() {
+ }
+
+ /**
+ * 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
+ */
+ public static void skipToEndElement(XMLStreamReader reader) throws XMLStreamException {
+ int depth = 0;
+ while (true) {
+ int event = reader.next();
+ if (event == XMLStreamConstants.START_ELEMENT) {
+ depth++;
+ } else if (event == XMLStreamConstants.END_ELEMENT) {
+ if (depth == 0) {
+ return;
+ }
+ depth--;
+ }
+ }
+ }
+
+ /**
+ * Load the class using the supplied ClassLoader.
+ * The class will be defined so any initializers present will be fired.
+ * As the class is being loaded, the Thread context ClassLoader will be
+ * set to the supplied classloader.
+ *
+ * @param name the name of the class to load
+ * @param cl the classloader to use to load it
+ * @return the class
+ * @throws MissingResourceException if the class could not be found
+ */
+ public static Class<?> loadClass(String name, ClassLoader cl) throws MissingResourceException {
+ final Thread thread = Thread.currentThread();
+ final ClassLoader oldCL = thread.getContextClassLoader();
+ try {
+ thread.setContextClassLoader(cl);
+ return Class.forName(name, true, cl);
+ } catch (ClassNotFoundException e) {
+ throw new MissingResourceException(name, e);
+ } finally {
+ thread.setContextClassLoader(oldCL);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingImplementationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingImplementationException.java
new file mode 100644
index 0000000000..89a44083cc
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingImplementationException.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.spi.loader;
+
+/**
+ * Exception that indicates that an implementation was not provided.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MissingImplementationException extends LoaderException {
+ private static final long serialVersionUID = -2917278473974880124L;
+
+ /**
+ * Default constructor.
+ */
+ public MissingImplementationException() {
+ super();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingIncludeException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingIncludeException.java
new file mode 100644
index 0000000000..10e40f9288
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingIncludeException.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.spi.loader;
+
+/**
+ * Exception that indicates that an include was not provided.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MissingIncludeException extends LoaderException {
+ private static final long serialVersionUID = -2917278473974880124L;
+
+ public MissingIncludeException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingPromoteException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingPromoteException.java
new file mode 100644
index 0000000000..325de281a7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingPromoteException.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.spi.loader;
+
+/**
+ * Denotes a missing promote attribute in a SCDL configuration
+ *
+ * @version $Rev$ $Date$
+ */
+public class MissingPromoteException extends LoaderException {
+
+ public MissingPromoteException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingReferenceException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingReferenceException.java
new file mode 100644
index 0000000000..7bc206de34
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingReferenceException.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.spi.loader;
+
+/**
+ * Indicates a required reference was not configured
+ *
+ * @version $Rev$ $Date$
+ */
+public class MissingReferenceException extends LoaderException {
+
+ public MissingReferenceException(String message) {
+ super(message);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingRequiredPropertyException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingRequiredPropertyException.java
new file mode 100644
index 0000000000..30955bb4e5
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingRequiredPropertyException.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.spi.loader;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MissingRequiredPropertyException extends LoaderException {
+
+ public MissingRequiredPropertyException(String name) {
+ super(name);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingResourceException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingResourceException.java
new file mode 100644
index 0000000000..3b6a21aa74
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/MissingResourceException.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.spi.loader;
+
+/**
+ * Exception that indicates an expected resource could not be found. The message should be set to the name of the
+ * resource.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MissingResourceException extends LoaderException {
+ private static final long serialVersionUID = 3775013318397916445L;
+
+ /**
+ * Constructor that indicates which resource could not be found. The supplied parameter is also returned as the
+ * message.
+ *
+ * @param resource the resource that could not be found
+ */
+ public MissingResourceException(String resource) {
+ super("Missing resource", resource);
+ }
+
+ public MissingResourceException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ /**
+ * Constructor that indicates which resource could not be found. The supplied parameter is also returned as the
+ * message.
+ *
+ * @param resource the resource that could not be found
+ * @param cause the error thrown resolving the resource
+ */
+ public MissingResourceException(String resource, Throwable cause) {
+ super("Missing resource", resource, cause);
+ }
+
+
+ /**
+ * Constructor that indicates which resource could not be found. The supplied parameter is also returned as the
+ * message.
+ *
+ * @param message the message set on the exception
+ * @param identifier the resource that could not be found
+ * @param cause the error thrown resolving the resource
+ */
+ public MissingResourceException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/PropertyObjectFactory.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/PropertyObjectFactory.java
new file mode 100644
index 0000000000..8b569d76fb
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/PropertyObjectFactory.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.spi.loader;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.PropertyValue;
+
+/**
+ * A factory that will create an ObjectFactory for a property
+ *
+ * @version $Rev$ $Date$
+ */
+public interface PropertyObjectFactory {
+ /**
+ * Return an ObjectFactory for instances of a property defined in an XML. The ObjectFactory must return instances
+ * that can safely be supplied to component implementations. If the instance is mutable and isolation between
+ * components is required, then the factory must clone or otherwise protect the implementation from unexpected
+ * modifications by other implementation instances.
+ *
+ * @param property the Property definition that the resulting ObjectFactory must be able to assign to
+ * @param propertyValue The component configuration of the property
+ * @return an ObjectFactory that can produce instances that can be assigned to the supplied Property
+ * @throws LoaderException if there is a problem creating the ObjectFactory
+ */
+ <T> ObjectFactory<T> createObjectFactory(Property<T> property, PropertyValue<T> propertyValue)
+ throws LoaderException;
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/ReferenceMultiplicityViolationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/ReferenceMultiplicityViolationException.java
new file mode 100644
index 0000000000..ce9acb8750
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/ReferenceMultiplicityViolationException.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.spi.loader;
+
+import org.apache.tuscany.spi.model.Multiplicity;
+
+/**
+ * Denote the violation of multiplicity declaration for a reference
+ *
+ * @version $Rev $Date
+ */
+public class ReferenceMultiplicityViolationException extends LoaderException {
+ private static final long serialVersionUID = -4049116356211578827L;
+
+ private final Multiplicity multiplicity;
+ private final int numberOfTargets;
+
+ /**
+ * @param message
+ * @param identifier
+ * @param multiplicity
+ * @param numberOfTargets
+ */
+ public ReferenceMultiplicityViolationException(String message,
+ String identifier,
+ Multiplicity multiplicity,
+ int numberOfTargets) {
+ super(message, identifier);
+ this.multiplicity = multiplicity;
+ this.numberOfTargets = numberOfTargets;
+ }
+
+ /**
+ * @param identifier
+ * @param multiplicity
+ * @param numberOfTargets
+ */
+ public ReferenceMultiplicityViolationException(String identifier, Multiplicity multiplicity, int numberOfTargets) {
+ this("Multiplicity is violated", identifier, multiplicity, numberOfTargets);
+ }
+
+ /**
+ * Get the multiplicity for the reference definition
+ *
+ * @return multiplicity of the reference definition
+ */
+ public Multiplicity getMultiplicity() {
+ return multiplicity;
+ }
+
+ /**
+ * Get the number of targets defined for this reference
+ * @return number of targets for this reference
+ */
+ public int getNumberOfTargets() {
+ return numberOfTargets;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/StAXElementLoader.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/StAXElementLoader.java
new file mode 100644
index 0000000000..9f0ad909f9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/StAXElementLoader.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.spi.loader;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * A loader that creates a model object from a StAX input stream.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface StAXElementLoader<T extends ModelObject> {
+ /**
+ * Create the model object for an element in an XML stream. When this method returns the stream will be positioned
+ * on the corresponding END_ELEMENT.
+ *
+ * @param object the model object to load configuration data into. An implementation may choose to return a
+ * different model object than the one passed in, in which case it is responsible for copying data.
+ * If null, the loader is responsible for creating a model object itself
+ * @param reader the XML stream reader positioned on the applicable START_ELEMENT
+ * @param context the context for the load operation
+ * @return the model object for that element
+ */
+ T load(ModelObject object, XMLStreamReader reader, DeploymentContext context)
+ throws XMLStreamException, LoaderException;
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UndefinedPropertyException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UndefinedPropertyException.java
new file mode 100644
index 0000000000..bf3aa205d2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UndefinedPropertyException.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.spi.loader;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class UndefinedPropertyException extends LoaderException {
+ public UndefinedPropertyException(String name) {
+ super("Property not found on implementation", name);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UndefinedReferenceException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UndefinedReferenceException.java
new file mode 100644
index 0000000000..f9aa8812ac
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UndefinedReferenceException.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.spi.loader;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class UndefinedReferenceException extends LoaderException {
+ private static final long serialVersionUID = -2897448857974015706L;
+
+ public UndefinedReferenceException(String name) {
+ super("Reference not found on implementation", name);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UnrecognizedComponentTypeException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UnrecognizedComponentTypeException.java
new file mode 100644
index 0000000000..750762d839
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UnrecognizedComponentTypeException.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.spi.loader;
+
+/**
+ * Exception that indicates an component type was encountered that could not be handled.
+ *
+ * @version $Rev$ $Date$
+ */
+public class UnrecognizedComponentTypeException extends LoaderException {
+ private final Class<?> type;
+
+ /**
+ * Constructor that indicates which component type loader could not be found.
+ *
+ * @param type the component type type that could not be handled
+ */
+ public UnrecognizedComponentTypeException(Class<?> type) {
+ super("Unrecognized element", type.getName());
+ this.type = type;
+ }
+
+ public Class<?> getType() {
+ return type;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UnrecognizedElementException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UnrecognizedElementException.java
new file mode 100644
index 0000000000..7991105da8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/loader/UnrecognizedElementException.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.spi.loader;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Exception that indicates an element was encountered that could not be handled.
+ *
+ * @version $Rev$ $Date$
+ */
+public class UnrecognizedElementException extends LoaderException {
+ private static final long serialVersionUID = 2549543622209829032L;
+ private final QName element;
+
+ /**
+ * Constructor that indicates which resource could not be found. The supplied parameter is also returned as the
+ * message.
+ *
+ * @param element the element that could not be handled
+ */
+ public UnrecognizedElementException(QName element) {
+ super("Unrecognized element", element.toString());
+ this.element = element;
+ }
+
+ public QName getElement() {
+ return element;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/MarshalException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/MarshalException.java
new file mode 100644
index 0000000000..0cdf5d399a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/MarshalException.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.spi.marshaller;
+
+import org.apache.tuscany.api.TuscanyException;
+
+/**
+ * Super class for all marshalling/unmarshalling exceptions.
+ *
+ * @version $Rev$ $Date$
+ */
+@SuppressWarnings("serial")
+public class MarshalException extends TuscanyException {
+
+ /**
+ * Initializes the exception message.
+ *
+ * @param message Message for the exception.
+ */
+ public MarshalException(String message) {
+ super(message);
+ }
+
+ /**
+ * Initializes the root cause.
+ *
+ * @param cause Root cause for the exception.
+ */
+ public MarshalException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/ModelMarshaller.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/ModelMarshaller.java
new file mode 100644
index 0000000000..4827112c94
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/ModelMarshaller.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.spi.marshaller;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * Interface for marshalling/unmarshalling internal physical component definitions.
+ *
+ * @version $Rev$ $Date$
+ *
+ */
+public interface ModelMarshaller<MD extends ModelObject> {
+
+ /**
+ * Marshalls the physical component definition to the specified stream writer.
+ *
+ * @param modelObject Physical component definition to be serialized.
+ * @param writer Stream writer to which the infoset is serialized.
+ * @throws MarshalException In case of any marshalling error.
+ */
+ void marshal(MD modelObject, XMLStreamWriter writer) throws MarshalException;
+
+ /**
+ * Unmarshalls an XML stream to a model object.
+ *
+ * @param reader XML stream from where the marshalled XML is read.
+ * @return Physical component definition.
+ * @throws MarshalException In case of any unmarshalling error.
+ */
+ MD unmarshal(XMLStreamReader reader) throws MarshalException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/ModelMarshallerRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/ModelMarshallerRegistry.java
new file mode 100644
index 0000000000..9174884c30
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/ModelMarshallerRegistry.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.spi.marshaller;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * A registry for model object marshallers.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ModelMarshallerRegistry {
+
+ /**
+ * Registers a model object marshaller.
+ *
+ * @param <MD> Model object type.
+ * @param modelClass Model obejct class.
+ * @param qname Qualified name of the root element of the marshalled XML.
+ * @param marshaller Model object marshaller.
+ */
+ <MD extends ModelObject> void registerMarshaller(Class<MD> modelClass, QName qname, ModelMarshaller<MD> marshaller);
+
+ /**
+ * Marshalls a model object.
+ *
+ * @param modelObject Model object to be marshalled.
+ * @param writer Writer to which marshalled information is written.
+ */
+ void marshall(ModelObject modelObject, XMLStreamWriter writer) throws MarshalException;
+
+ /**
+ * Unmarshalls an XML stream to a model object.
+ *
+ * @param reader Reader from which marshalled information is read.
+ * @return Model object from the marshalled stream.
+ */
+ ModelObject unmarshall(XMLStreamReader reader) throws MarshalException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/AtomicImplementation.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/AtomicImplementation.java
new file mode 100644
index 0000000000..8e12e970ae
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/AtomicImplementation.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.spi.model;
+
+/**
+ * The base representation of an atomic component implementation
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class AtomicImplementation<T extends ComponentType> extends Implementation<T> {
+ protected AtomicImplementation() {
+ }
+
+ protected AtomicImplementation(T componentType) {
+ super(componentType);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/BindingDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/BindingDefinition.java
new file mode 100644
index 0000000000..4b17181442
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/BindingDefinition.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.spi.model;
+
+import java.net.URI;
+
+/**
+ * The base representation of a binding specified in an assembly
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class BindingDefinition extends ModelObject {
+ private URI targetUri;
+
+ protected BindingDefinition() {
+ }
+
+ public BindingDefinition(URI targetUri) {
+ this.targetUri = targetUri;
+ }
+
+ public URI getTargetUri() {
+ return targetUri;
+ }
+
+ public void setTargetUri(URI targetUri) {
+ this.targetUri = targetUri;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ComponentDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ComponentDefinition.java
new file mode 100644
index 0000000000..233376a645
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ComponentDefinition.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.spi.model;
+
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Represents a component. <p>A component is a configured instance of an implementation. The services provided and
+ * consumed and the available configuration properties are defined by the implementation (represented by its
+ * componentType).</p> <p>Every component has a name which uniquely identifies it within the scope of the composite that
+ * contains it; the name must be different from the names of all other components, services and references immediately
+ * contained in the composite (directly or through an &lt;include&gt; element).</p> <p>A component may define a {@link
+ * PropertyValue} that overrides the default value of a {@link Property} defined in the componentType.</p> <p>It may
+ * also define a {@link ReferenceTarget} for a {@link ReferenceDefinition} defined in the componentType. The
+ * ReferenceTarget must resolve to another component or a reference in the enclosing composite.</p> <p>Components may
+ * specify an initialization level that will determine the order in which it will be eagerly initialized relative to
+ * other components from the enclosing composite that are in the same scope. This can be used to define a startup
+ * sequence for components that are otherwise independent. Any initialization required to resolve references between
+ * components will override this initialization order.</p>
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentDefinition<I extends Implementation<?>> extends ModelObject {
+ private URI uri;
+ private URI runtimeId;
+ private boolean autowire;
+ private Integer initLevel;
+ private final I implementation;
+ private final Map<String, ReferenceTarget> referenceTargets = new HashMap<String, ReferenceTarget>();
+ private final Map<String, PropertyValue<?>> propertyValues = new HashMap<String, PropertyValue<?>>();
+
+ /**
+ * Constructor specifying the component's name and implementation.
+ *
+ * @param uri the name of this component
+ * @param implementation the implementation of this component
+ */
+ public ComponentDefinition(URI uri, I implementation) {
+ this.uri = uri;
+ this.implementation = implementation;
+ }
+
+ /**
+ * Constructor specifying the implementation of this component.
+ *
+ * @param implementation the implementation of this component
+ */
+ public ComponentDefinition(I implementation) {
+ this.implementation = implementation;
+ }
+
+ /**
+ * Returns the {@link Implementation} of this component.
+ *
+ * @return the implementation of this component
+ */
+ public I getImplementation() {
+ return implementation;
+ }
+
+ /**
+ * Returns the name of this component.
+ *
+ * @return the name of this component
+ */
+ public URI getUri() {
+ return uri;
+ }
+
+ /**
+ * Sets the name of this component.
+ *
+ * @param uri the name of this component
+ */
+ public void setUri(URI uri) {
+ this.uri = uri;
+ }
+
+ /**
+ * Returns the id of the node the component is to be provisioned to.
+ *
+ * @return the id of the node the component is to be provisioned to
+ */
+ public URI getRuntimeId() {
+ return runtimeId;
+ }
+
+ /**
+ * Sets the id of the node the component is to be provisioned to.
+ *
+ * @param id the id of the node the component is to be provisioned to
+ */
+ public void setRuntimeId(URI id) {
+ this.runtimeId = id;
+ }
+
+ /**
+ * Returns true if autowire is enabled for the component.
+ *
+ * @return true if autowire is enabled for the component.
+ */
+ public boolean getAutowire() {
+ return autowire;
+ }
+
+ /**
+ * Sets autowire enablement for the component.
+ *
+ * @param autowire true if autowire is enabled.
+ */
+ public void setAutowire(boolean autowire) {
+ this.autowire = autowire;
+ }
+
+ /**
+ * Returns the initialization level of this component.
+ *
+ * @return the initialization level of this component
+ */
+ public Integer getInitLevel() {
+ return initLevel;
+ }
+
+ /**
+ * Sets the initialization level of this component. If set to null then the level from the componentType is used. If
+ * set to zero or a negative value then the component will not be eagerly initialized.
+ *
+ * @param initLevel the initialization level of this component
+ */
+ public void setInitLevel(Integer initLevel) {
+ this.initLevel = initLevel;
+ }
+
+ /**
+ * Returns a live Map of the {@link ReferenceTarget targets} configured by this component definition.
+ *
+ * @return the reference targets configured by this component
+ */
+ public Map<String, ReferenceTarget> getReferenceTargets() {
+ return referenceTargets;
+ }
+
+ /**
+ * Add a reference target configuration to this component. Any existing configuration for the reference named in the
+ * target is replaced.
+ *
+ * @param target the target to add
+ */
+ public void add(ReferenceTarget target) {
+ referenceTargets.put(target.getReferenceName().getFragment(), target);
+ }
+
+ /**
+ * Returns a live Map of {@link PropertyValue property values} configured by this component definition.
+ *
+ * @return the property values configured by this component
+ */
+ public Map<String, PropertyValue<?>> getPropertyValues() {
+ return propertyValues;
+ }
+
+ /**
+ * Add a property value configuration to this component. Any existing configuration for the property names in the
+ * property value is replaced.
+ *
+ * @param value the property value to add
+ */
+ public void add(PropertyValue<?> value) {
+ propertyValues.put(value.getName(), value);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ComponentType.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ComponentType.java
new file mode 100644
index 0000000000..b4e2db485e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ComponentType.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.spi.model;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * <p>The definition of the configurable aspects of an implementation in terms of the services it exposes, the services
+ * it references, and properties that can be used to configure it.</p> <p>A service represents an addressable interface
+ * provided by the implementation. Such a service may be the target of a wire from another component.</p> <p>A reference
+ * represents a requirement that an implementation has on a service provided by another component or by a resource
+ * outside the SCA system. Such a reference may be the source of a wire to another component.</p> <p>A property allows
+ * the behaviour of the implementation to be configured through externally set values.</p> <p>A component type may also
+ * declare that it wishes to be initialized upon activation of the scope that contains it and may specify an order
+ * relative to other eagerly initializing components. For example, an implementation that pre-loads some form of cache
+ * could declare that it should be eagerly initialized at the start of the scope so that the cache load occured on
+ * startup rather than first use.</p>
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentType<S extends ServiceDefinition, R extends ReferenceDefinition, P extends Property<?>>
+ extends ModelObject {
+ protected Scope implementationScope = Scope.UNDEFINED;
+ private int initLevel;
+ private long maxAge = -1;
+ private long maxIdleTime = -1;
+ private final Map<String, S> services = new HashMap<String, S>();
+ private final Map<String, R> references = new HashMap<String, R>();
+ private final Map<String, P> properties = new HashMap<String, P>();
+
+ /**
+ * Returns the component implementation scope
+ */
+ public Scope getImplementationScope() {
+ return implementationScope;
+ }
+
+ /**
+ * Sets the component implementation scope
+ */
+ public void setImplementationScope(Scope implementationScope) {
+ this.implementationScope = implementationScope;
+ }
+
+ /**
+ * Returns the default initialization level for components of this type. A value greater than zero indicates that
+ * components should be eagerly initialized.
+ *
+ * @return the default initialization level
+ */
+ public int getInitLevel() {
+ return initLevel;
+ }
+
+ /**
+ * Sets the default initialization level for components of this type. A value greater than zero indicates that
+ * components should be eagerly initialized.
+ *
+ * @param initLevel default initialization level for components of this type
+ */
+ public void setInitLevel(int initLevel) {
+ this.initLevel = initLevel;
+ }
+
+ /**
+ * Returns true if this component should be eagerly initialized.
+ *
+ * @return true if this component should be eagerly initialized
+ */
+ public boolean isEagerInit() {
+ return initLevel > 0;
+ }
+
+ /**
+ * Returns the idle time allowed between operations in milliseconds if the implementation is conversational
+ *
+ * @return the idle time allowed between operations in milliseconds if the implementation is conversational
+ */
+ public long getMaxIdleTime() {
+ return maxIdleTime;
+ }
+
+ /**
+ * Sets the idle time allowed between operations in milliseconds if the implementation is conversational
+ */
+ public void setMaxIdleTime(long maxIdleTime) {
+ this.maxIdleTime = maxIdleTime;
+ }
+
+ /**
+ * Returns the maximum age a conversation may remain active in milliseconds if the implementation is conversational
+ *
+ * @return the maximum age a conversation may remain active in milliseconds if the implementation is conversational
+ */
+ public long getMaxAge() {
+ return maxAge;
+ }
+
+ /**
+ * Sets the maximum age a conversation may remain active in milliseconds if the implementation is conversational
+ */
+ public void setMaxAge(long maxAge) {
+ this.maxAge = maxAge;
+ }
+
+ /**
+ * Returns a live Map of the services provided by the implementation.
+ *
+ * @return a live Map of the services provided by the implementation
+ */
+ public Map<String, S> getServices() {
+ return services;
+ }
+
+ /**
+ * Add a service to those provided by the implementation. Any existing service with the same name is replaced.
+ *
+ * @param service a service provided by the implementation
+ */
+ public void add(S service) {
+ services.put(service.getUri().getFragment(), service);
+ }
+
+ /**
+ * Returns a live Map of references to services consumed by the implementation.
+ *
+ * @return a live Map of references to services consumed by the implementation
+ */
+ public Map<String, R> getReferences() {
+ return references;
+ }
+
+ /**
+ * Add a reference to a service consumed by the implementation. Any existing reference with the same name is
+ * replaced.
+ *
+ * @param reference a reference to a service consumed by the implementation
+ */
+ public void add(R reference) {
+ references.put(reference.getUri().getFragment(), reference);
+ }
+
+ /**
+ * Returns a live Map of properties that can be used to configure the implementation.
+ *
+ * @return a live Map of properties that can be used to configure the implementation
+ */
+ public Map<String, P> getProperties() {
+ return properties;
+ }
+
+ /**
+ * Add a property that can be used to configure the implementation. Any existing property with the same name is
+ * replaced.
+ *
+ * @param property a property that can be used to configure the implementation
+ */
+ public void add(P property) {
+ properties.put(property.getName(), property);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/CompositeComponentType.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/CompositeComponentType.java
new file mode 100644
index 0000000000..464b5758b7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/CompositeComponentType.java
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.model;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.util.UriHelper;
+
+/**
+ * A specialization of component type for composite components.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeComponentType<S extends ServiceDefinition,
+ R extends ReferenceDefinition,
+ P extends Property<?>> extends ComponentType<S, R, P> {
+
+ private QName name;
+ private boolean autowire;
+ private final Map<String, ComponentDefinition<? extends Implementation<?>>> components =
+ new HashMap<String, ComponentDefinition<? extends Implementation<?>>>();
+ private final Map<String, Include> includes = new HashMap<String, Include>();
+ private final List<WireDefinition> wires = new ArrayList<WireDefinition>();
+
+ public CompositeComponentType() {
+ implementationScope = Scope.SYSTEM;
+ }
+
+ /**
+ * Constructor defining the composite name.
+ *
+ * @param name the qualified name of this composite
+ */
+ public CompositeComponentType(QName name) {
+ this();
+ this.name = name;
+ }
+
+ /**
+ * Returns the qualified name of this composite.
+ * The namespace portion of this name is the targetNamespace for other qualified names used in the composite.
+ *
+ * @return the qualified name of this composite
+ */
+ public QName getName() {
+ return name;
+ }
+
+ /**
+ * Set the qualified name of this composite.
+ *
+ * @param name the qualified name of this composite
+ */
+ public void setName(QName name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns if autowire is set of for composite
+ *
+ * @return true if autowire is set for the composite
+ */
+ public boolean isAutowire() {
+ return autowire;
+ }
+
+ /**
+ * Sets autowire for the composite
+ *
+ * @param autowire true if autowire is enabled for the composite
+ */
+ public void setAutowire(boolean autowire) {
+ this.autowire = autowire;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ /**
+ * Get all properties including the ones are from included composites
+ * @return
+ */
+ public Map<String, P> getProperties() {
+ Map<String, P> view = new HashMap<String, P>(super.getProperties());
+ for (Include i : includes.values()) {
+ view.putAll(i.getIncluded().getProperties());
+ }
+ return Collections.unmodifiableMap(view);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ /**
+ * Get all references including the ones are from included composites
+ * @return
+ */
+ public Map<String, R> getReferences() {
+ Map<String, R> view = new HashMap<String, R>(super.getReferences());
+ for (Include i : includes.values()) {
+ view.putAll(i.getIncluded().getReferences());
+ }
+ return Collections.unmodifiableMap(view);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ /**
+ * Get all services including the ones are from included composites
+ * @return
+ */
+ public Map<String, S> getServices() {
+ Map<String, S> view = new HashMap<String, S>(super.getServices());
+ for (Include i : includes.values()) {
+ view.putAll(i.getIncluded().getServices());
+ }
+ return Collections.unmodifiableMap(view);
+ }
+
+ /**
+ * Get all components including the ones are from included composites
+ */
+ @SuppressWarnings("unchecked")
+ public Map<String, ComponentDefinition<? extends Implementation<?>>> getComponents() {
+ Map<String, ComponentDefinition<? extends Implementation<?>>> view =
+ new HashMap<String, ComponentDefinition<? extends Implementation<?>>>(components);
+ for (Include i : includes.values()) {
+ view.putAll(i.getIncluded().getComponents());
+ }
+ return Collections.unmodifiableMap(view);
+ }
+
+
+ /**
+ * Get all wires including the ones are from included composites
+ */
+ @SuppressWarnings("unchecked")
+ public List<WireDefinition> getWires() {
+ List<WireDefinition> view =
+ new ArrayList<WireDefinition>(wires);
+ for (Include i : includes.values()) {
+ view.addAll(i.getIncluded().getWires());
+ }
+ return Collections.unmodifiableList(view);
+ }
+
+ /**
+ * Get declared properties in this composite type, included doesn't count
+ */
+ public Map<String, P> getDeclaredProperties() {
+ return super.getProperties();
+ }
+
+ /**
+ * Get declared references in this composite type, included doesn't count
+ */
+ public Map<String, R> getDeclaredReferences() {
+ return super.getReferences();
+ }
+
+ /**
+ * Get declared services in this composite type, included doesn't count
+ */
+ public Map<String, S> getDeclaredServices() {
+ return super.getServices();
+ }
+
+ /**
+ * Get declared components in this composite type, included doesn't count
+ */
+ public Map<String, ComponentDefinition<? extends Implementation<?>>> getDeclaredComponents() {
+ return components;
+ }
+
+ /**
+ * Get declared wires in this composite type, included doesn't count
+ */
+ public List<WireDefinition> getDeclaredWires() {
+ return wires;
+ }
+
+ public void add(WireDefinition wireDefn) {
+ wires.add(wireDefn);
+ }
+
+
+ public void add(ComponentDefinition<? extends Implementation<?>> componentDefinition) {
+ components.put(UriHelper.getBaseName(componentDefinition.getUri()), componentDefinition);
+ }
+
+ public Map<String, Include> getIncludes() {
+ return includes;
+ }
+
+ public void add(Include include) {
+ includes.put(include.getName(), include);
+ }
+
+
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ CompositeComponentType that = (CompositeComponentType) o;
+ return name.equals(that.name);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/CompositeImplementation.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/CompositeImplementation.java
new file mode 100644
index 0000000000..6948c52286
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/CompositeImplementation.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.spi.model;
+
+import java.net.URL;
+
+/**
+ * A specialization of an implementation associated with composite components
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeImplementation extends Implementation<CompositeComponentType> {
+ private String name;
+ private URL scdlLocation;
+ private ClassLoader classLoader;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public URL getScdlLocation() {
+ return scdlLocation;
+ }
+
+ public void setScdlLocation(URL scdlLocation) {
+ this.scdlLocation = scdlLocation;
+ }
+
+ public ClassLoader getClassLoader() {
+ return classLoader;
+ }
+
+ public void setClassLoader(ClassLoader classLoader) {
+ this.classLoader = classLoader;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Contribution.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Contribution.java
new file mode 100644
index 0000000000..374f441ea3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Contribution.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.spi.model;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+/**
+ * The representation of a deployed contribution
+ *
+ * @version $Rev$ $Date$
+ */
+public class Contribution extends DeployedArtifact {
+ public static final String SCA_CONTRIBUTION_META = "META-INF/sca-contribution.xml";
+ public static final String SCA_CONTRIBUTION_GENERATED_META = "META-INF/sca-contribution-generated.xml";
+
+ protected List<String> exports = new ArrayList<String>();
+ protected List<ContributionImport> imports = new ArrayList<ContributionImport>();
+ protected List<QName> deployables = new ArrayList<QName>();
+
+ /**
+ * A list of artifacts in the contribution
+ */
+ protected Map<URI, DeployedArtifact> artifacts = new HashMap<URI, DeployedArtifact>();
+
+ public Contribution() {
+ super();
+ }
+
+ /**
+ * @param uri
+ */
+ public Contribution(URI uri) {
+ super(uri);
+ if (uri != null) {
+ artifacts.put(uri, this);
+ }
+ }
+
+ public URI getUri() {
+ return uri;
+ }
+
+ public void setURI(URI uri) {
+ super.setUri(uri);
+ if (uri != null) {
+ artifacts.put(uri, this);
+ }
+ }
+
+ public List<String> getExports() {
+ return exports;
+ }
+
+ public List<ContributionImport> getImports() {
+ return imports;
+ }
+
+ public List<QName> getDeployables() {
+ return deployables;
+ }
+
+ public Map<URI, DeployedArtifact> getArtifacts() {
+ return Collections.unmodifiableMap(artifacts);
+ }
+
+ public void addArtifact(DeployedArtifact artifact) {
+ artifact.setContribution(this);
+ artifacts.put(artifact.getUri(), artifact);
+ }
+
+ public DeployedArtifact getArtifact(URI uri) {
+ return artifacts.get(uri);
+ }
+
+ /**
+ * @return the location
+ */
+ public URL getLocation() {
+ return location;
+ }
+
+ /**
+ * @param location the location to set
+ */
+ public void setLocation(URL location) {
+ this.location = location;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ContributionImport.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ContributionImport.java
new file mode 100644
index 0000000000..a678adbdc8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ContributionImport.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.spi.model;
+
+import java.net.URI;
+
+/**
+ * The representation of an import for the contribution
+ *
+ * @version $Rev$ $Date$
+ */
+public class ContributionImport extends ModelObject {
+ private String namespace; // The namespace to be imported
+ private URI location; // Optional location to hint the where it should be imported
+
+ // TODO: We might need the field to point to the imported artifact/model
+
+ public URI getLocation() {
+ return location;
+ }
+
+ public void setLocation(URI location) {
+ this.location = location;
+ }
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/DataType.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/DataType.java
new file mode 100644
index 0000000000..72effb52e2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/DataType.java
@@ -0,0 +1,249 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.model;
+
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Representation of the type of data associated with an operation. Data is represented in two forms: the physical form
+ * used by the runtime and a logical form used by the assembly. The physical form is a Java Type because the runtime is
+ * written in Java. This may be the same form used by the application but it may not; for example, an application that
+ * is performing stream processing may want a physical form such as an {@link java.io.InputStream InputStream} to
+ * semantially operate on application data such as a purchase order. The logical description is that used by the
+ * assembly model and is an identifier into some well-known type space; examples may be a Java type represented by its
+ * Class or an XML type represented by its QName. Every data type may also contain metadata describing the expected
+ * data; for example, it could specify a preferred data binding technology or the size of a typical instance.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataType<L> extends ModelObject implements Cloneable {
+ private String dataBinding;
+
+ private final Type physical;
+
+ private L logical;
+
+ private Map<String, Object> metadata = new HashMap<String, Object>();
+
+ private Operation operation;
+
+ /**
+ * Construct a data type specifying the physical and logical types.
+ *
+ * @param physical the physical class used by the runtime
+ * @param logical the logical type
+ * @see #getLogical()
+ */
+ public DataType(Type physical, L logical) {
+ this.physical = physical;
+ this.logical = logical;
+ if (physical instanceof Class) {
+ this.dataBinding = ((Class) physical).getName();
+ }
+ }
+
+ public DataType(String dataBinding, Type physical, L logical) {
+ this.dataBinding = dataBinding;
+ this.physical = physical;
+ this.logical = logical;
+ }
+
+ /**
+ * Returns the physical type used by the runtime.
+ *
+ * @return the physical type used by the runtime
+ */
+ public Type getPhysical() {
+ return physical;
+ }
+
+ /**
+ * Returns the logical identifier used by the assembly. The type of this value identifies the logical type system in
+ * use. Known values are: <ul> <li>a java.lang.reflect.Type identifies a Java type by name and ClassLoader; this
+ * includes Java Classes as they are specializations of Type</li> <li>a javax.xml.namespace.QName identifies an XML
+ * type by local name and namespace</li> </ul>
+ *
+ * @return the logical type name
+ */
+ public L getLogical() {
+ return logical;
+ }
+
+ /**
+ * Returns all metadata about this type.
+ *
+ * @return all metadata about this type
+ */
+ public Map<String, ?> getMetadata() {
+ return metadata;
+ }
+
+ /**
+ * Returns the specified metadata item or null if not present.
+ *
+ * @param name the name of the metadata item
+ * @return the value, or null if not present
+ */
+ public Object getMetadata(String name) {
+ return metadata.get(name);
+ }
+
+ /**
+ * Sets the specified metadata value. A null value undefines it.
+ *
+ * @param name the name of the metadata item
+ * @param value the value, or null to undefine
+ * @return the old value for the item, or null if not present
+ */
+ public Object setMetadata(String name, Object value) {
+ if (value == null) {
+ return metadata.remove(name);
+ } else {
+ return metadata.put(name, value);
+ }
+ }
+
+ public String getDataBinding() {
+ if (dataBinding == null) {
+ // databinding is not set at the DataType level, check the operation
+ Operation<?> operation = (Operation<?>) getOperation();
+ if (operation != null) {
+ return operation.getDataBinding();
+ }
+ }
+ return dataBinding;
+ }
+
+ /**
+ * @param dataBinding the dataBinding to set
+ */
+ public void setDataBinding(String dataBinding) {
+ this.dataBinding = dataBinding;
+ }
+
+ public int hashCode() {
+ int result;
+ result = dataBinding != null ? dataBinding.hashCode() : 0;
+ result = 29 * result + (physical != null ? physical.hashCode() : 0);
+ result = 29 * result + (logical != null ? logical.hashCode() : 0);
+ // Commented the following line out since it causes infinite loop from Operation.hashCode()
+ // if the metadata map contains the Operation
+ // result = 29 * result + (metadata != null ? metadata.hashCode() : 0);
+ return result;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ final DataType dataType = (DataType) o;
+
+ if (dataBinding != null ? !dataBinding.equals(dataType.dataBinding) : dataType.dataBinding != null) {
+ return false;
+ }
+ if (logical != null ? !logical.equals(dataType.logical) : dataType.logical != null) {
+ return false;
+ }
+ return !(physical != null ? !physical.equals(dataType.physical) : dataType.physical != null);
+
+ }
+
+// @SuppressWarnings("unchecked")
+// public boolean equals(Object o) {
+// if (this == o) {
+// return true;
+// }
+// if (o == null || getClass() != o.getClass()) {
+// return false;
+// }
+//
+// final DataType dataType = (DataType) o;
+//
+// if (logical instanceof Class && dataType.logical instanceof Class) {
+// Class<?> logicalClass = (Class<?>) logical;
+// Class<?> targetLogicalClass = (Class<?>) dataType.logical;
+// if (!logicalClass.isAssignableFrom(targetLogicalClass)) {
+// return false;
+// }
+// } else {
+// if (logical != null ? !logical.equals(dataType.logical) : dataType.logical != null) {
+// return false;
+// }
+// }
+// if (physical instanceof Class && dataType.physical instanceof Class) {
+// Class<?> physicalClass = (Class<?>) physical;
+// Class<?> physicalTargetClass = (Class<?>) dataType.physical;
+// if (dataBinding != null
+// && dataType.dataBinding != null
+// && dataBinding.equals(physicalClass.getName())
+// && dataType.dataBinding.equals(physicalTargetClass.getName())) {
+// return physicalClass.isAssignableFrom(physicalTargetClass);
+// }
+// if (!physicalClass.isAssignableFrom(physicalTargetClass)) {
+// return false;
+// }
+// return !(dataBinding != null ? !dataBinding.equals(dataType.dataBinding) : dataType.dataBinding != null);
+//
+//
+// }
+//
+// if (dataBinding != null ? !dataBinding.equals(dataType.dataBinding) : dataType.dataBinding != null) {
+// return false;
+// }
+//
+// return !(physical != null ? !physical.equals(dataType.physical) : dataType.physical != null);
+// }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append(physical).append(" ").append(dataBinding).append(" ").append(logical);
+ return sb.toString();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ DataType<L> copy = (DataType<L>) super.clone();
+ assert this.metadata instanceof HashMap;
+ copy.metadata = (HashMap<String, Object>) ((HashMap) this.metadata).clone();
+ return copy;
+ }
+
+ public Operation getOperation() {
+ return operation;
+ }
+
+ public void setOperation(Operation operation) {
+ this.operation = operation;
+ }
+
+ /**
+ * @param logical the logical to set
+ */
+ public void setLogical(L logical) {
+ this.logical = logical;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/DeployedArtifact.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/DeployedArtifact.java
new file mode 100644
index 0000000000..60722d4ad6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/DeployedArtifact.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.spi.model;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Representation of a deployed artifact
+ *
+ * @version $Rev$ $Date$
+ */
+public class DeployedArtifact extends ModelObject {
+ protected Contribution contribution;
+ protected URI uri;
+ protected URL location;
+ /**
+ * The map keeps all the model objects loaded/introspected from this artifact. The objects
+ * are keyed by the java type of the model such as javax.wsdl.ModelObject. The value is also
+ * a map with namespace as the key and the model object as the value.
+ */
+ protected Map<Class, Map<String, Object>> modelObjects = new HashMap<Class, Map<String, Object>>();
+
+ public DeployedArtifact() {
+ super();
+ }
+ /**
+ * @param uri the artifact uri
+ */
+ public DeployedArtifact(URI uri) {
+ super();
+ this.uri = uri;
+ }
+ /**
+ * Get the absolute URI as the unique id for the artifact
+ * @return
+ */
+ public URI getUri() {
+ return uri;
+ }
+
+ public void setUri(URI uri) {
+ this.uri = uri;
+ }
+
+ /**
+ * @return the location
+ */
+ public URL getLocation() {
+ return location;
+ }
+
+ /**
+ * @param location the location to set
+ */
+ public void setLocation(URL location) {
+ this.location = location;
+ }
+
+ public Contribution getContribution() {
+ return contribution;
+ }
+
+ public void setContribution(Contribution contribution) {
+ this.contribution = contribution;
+ }
+ public Map<Class, Map<String, Object>> getModelObjects() {
+ return modelObjects;
+ }
+
+ public Map<String, Object> getModelObjects(Class type) {
+ return modelObjects.get(type);
+ }
+
+ public Object getModelObject(Class type, String namespace) {
+ Map<String, Object> map = modelObjects.get(type);
+ if (map == null) {
+ return null;
+ } else {
+ return map.get(namespace);
+ }
+ }
+
+ public void addModelObject(Class type, String namespace, Object modelObject) {
+ Map<String, Object> map = modelObjects.get(type);
+ if (map == null) {
+ map = new HashMap<String, Object>();
+ modelObjects.put(type, map);
+ }
+ map.put(namespace, modelObject);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ElementInfo.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ElementInfo.java
new file mode 100644
index 0000000000..31c2f9428f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ElementInfo.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.spi.model;
+
+import javax.xml.namespace.QName;
+
+/**
+ * An abstraction of XML schema elements
+ */
+public class ElementInfo {
+ private QName name;
+ private TypeInfo type;
+
+ /**
+ * @param name
+ * @param type
+ */
+ public ElementInfo(QName name, TypeInfo type) {
+ super();
+ this.name = name;
+ this.type = type;
+ }
+
+ /**
+ * @return the name
+ */
+ public QName getQName() {
+ return name;
+ }
+
+ /**
+ * @return the type
+ */
+ public TypeInfo getType() {
+ return type;
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("Element: ").append(name).append(" ").append(type);
+ return sb.toString();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Implementation.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Implementation.java
new file mode 100644
index 0000000000..8520ab49e8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Implementation.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.spi.model;
+
+/**
+ * Represents a component implementation
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class Implementation<T extends ComponentType> extends ModelObject {
+ private T componentType;
+
+ protected Implementation() {
+ }
+
+ protected Implementation(T componentType) {
+ this.componentType = componentType;
+ }
+
+ public T getComponentType() {
+ return componentType;
+ }
+
+ public void setComponentType(T componentType) {
+ this.componentType = componentType;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Include.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Include.java
new file mode 100644
index 0000000000..ac320a2b5c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Include.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.spi.model;
+
+import java.net.URL;
+
+/**
+ * Model object that represents the include of a composite by value.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Include extends ModelObject {
+ private String name;
+ private URL scdlLocation;
+ private CompositeComponentType included;
+
+ /**
+ * Returns the name of the composite that is being included.
+ * @return the name of the composite that is being included
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name of the composite that is being included.
+ * @param name the name of the composite that is being included
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns the location of the SCDL for composite being included.
+ * @return the location of the SCDL for composite being included
+ */
+ public URL getScdlLocation() {
+ return scdlLocation;
+ }
+
+ /**
+ * Sets the location of the SCDL for composite being included.
+ * @param scdlLocation the location of the SCDL for composite being included
+ */
+ public void setScdlLocation(URL scdlLocation) {
+ this.scdlLocation = scdlLocation;
+ }
+
+ /**
+ * Returns the composite that was included.
+ * @return the composite that was included
+ */
+ public CompositeComponentType getIncluded() {
+ return included;
+ }
+
+ /**
+ * Sets the composite that was included.
+ * @param included the composite that was included
+ */
+ public void setIncluded(CompositeComponentType included) {
+ this.included = included;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Intent.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Intent.java
new file mode 100644
index 0000000000..9f3ee78a23
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Intent.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.spi.model;
+
+import java.util.ArrayList;
+import static java.util.Collections.unmodifiableList;
+import java.util.List;
+import javax.xml.namespace.QName;
+
+/**
+ * Model representation for intent. This class is used by intent loader only, other SCA model classes will not reference
+ * this class directly.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Intent {
+
+ /**
+ * name of intent.
+ */
+ protected IntentName name;
+
+ /**
+ * Description for this intent
+ */
+ protected String description;
+
+ /**
+ * QNames of artifacts this intent can apply to
+ */
+ protected List<QName> appliedArtifacts = new ArrayList<QName>();
+
+ /**
+ * intents required by this intent, only useful when this intent is a profile intent
+ */
+ protected List<IntentName> requriedIntents = new ArrayList<IntentName>();
+
+ /**
+ * Create a policy intent.
+ *
+ * @param name name of the intent.
+ * @param description description of the intent.
+ */
+ public Intent(IntentName name, String description) {
+ this.name = name;
+ this.description = description;
+ }
+
+ public List<QName> getAppliedArtifacts() {
+ return unmodifiableList(appliedArtifacts);
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public IntentName getName() {
+ return name;
+ }
+
+ public List<IntentName> getRequriedIntents() {
+ return unmodifiableList(requriedIntents);
+ }
+
+ public void addRequriedIntents(IntentName intent) {
+ requriedIntents.add(intent);
+ }
+
+ public void addAppliedArtifacts(QName artifactName) {
+ appliedArtifacts.add(artifactName);
+ }
+
+ public boolean isProfileIntent() {
+ return !requriedIntents.isEmpty();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentDefinition.java
new file mode 100644
index 0000000000..35d55a3153
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentDefinition.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.spi.model;
+
+/**
+ * Base model class for intent meta-data
+ *
+ * @version $Rev$ $Date$
+ */
+public class IntentDefinition extends ModelObject {
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentMap.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentMap.java
new file mode 100644
index 0000000000..cbfba86dfe
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentMap.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.spi.model;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import static java.util.Collections.unmodifiableCollection;
+
+/**
+ * Represents an IntentMap within PolicySet.
+ *
+ * @version $Rev$ $Date$
+ */
+public class IntentMap extends PolicyModel {
+
+ /* Name of default intent provied by this IntentMap */
+ private String defaultProvideIntent;
+
+ /* Name of intent provided by this IntentMap */
+ private Collection<String> provideIntents = new ArrayList<String>();
+
+ /* Qualifiers of this IntentMap */
+ private Collection<Qualifier> qualifiers = new ArrayList<Qualifier>();
+
+ public IntentMap(String defaultProvideIntent, Collection<String> provideIntents) {
+ super();
+ this.defaultProvideIntent = defaultProvideIntent;
+ this.provideIntents.addAll(provideIntents);
+ }
+
+ public Collection<String> getProvideIntents() {
+ return unmodifiableCollection(provideIntents);
+ }
+
+ public void addQualifier(Qualifier qualifier) {
+ qualifiers.add(qualifier);
+ }
+
+ public Collection<Qualifier> getQualifiers() {
+ return unmodifiableCollection(qualifiers);
+ }
+
+ public String getDefaultProvideIntent() {
+ return defaultProvideIntent;
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentName.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentName.java
new file mode 100644
index 0000000000..eb69b44b37
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/IntentName.java
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.model;
+
+import java.util.Arrays;
+
+/**
+ * Model class represents a name of a intent. An intent name has a domain name and one or more qualified names. For
+ * example, in "sec.confidentiality/message/body", the domain name is sec, and the qualified names are confidentiality,
+ * message and body
+ */
+@SuppressWarnings({"SerializableHasSerializationMethods"})
+public class IntentName implements java.io.Serializable {
+ private static final String QUALIFIED_SEPARATOR = "/";
+ private static final String DOMAIN_SEPARATOR = ".";
+ private static final long serialVersionUID = -7030021353149084879L;
+
+ /**
+ * domain of the intent
+ */
+ private String domain;
+
+ private String[] qualifiedNames;
+
+ /**
+ * Construct a IntentName from a string representation.
+ *
+ * @param intent string representation for a intent.
+ */
+ public IntentName(String intent) {
+ parse(intent);
+ }
+
+ /**
+ * Construct a IntentName from domain name and qualified names
+ *
+ * @param domain domain name of the intent
+ * @param qualifiedNames qualified names of the intent
+ */
+ public IntentName(String domain, String[] qualifiedNames) {
+ this.domain = domain;
+ this.qualifiedNames = qualifiedNames;
+ }
+
+ public String getDomain() {
+ return domain;
+ }
+
+ public String[] getQualifiedNames() {
+ String[] results = new String[qualifiedNames.length];
+ System.arraycopy(qualifiedNames, 0, results, 0, qualifiedNames.length);
+ return results;
+ }
+
+ @Override
+ public String toString() {
+ return getName();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final IntentName other = (IntentName) obj;
+ if (domain == null) {
+ if (other.domain != null) {
+ return false;
+ }
+ } else if (!domain.equals(other.domain)) {
+ return false;
+ }
+ return Arrays.equals(qualifiedNames, other.qualifiedNames);
+ }
+
+ @Override
+ public int hashCode() {
+ final int PRIME = 17;
+ int result = 1;
+ result = PRIME * result + ((domain == null) ? 0 : domain.hashCode());
+ result = PRIME * result + Arrays.hashCode(qualifiedNames);
+ return result;
+ }
+
+ private String getName() {
+ StringBuilder sbd = new StringBuilder(domain);
+ for (int i = 0; i < qualifiedNames.length; i++) {
+ if (i == 0) {
+ sbd.append(DOMAIN_SEPARATOR);
+ } else {
+ sbd.append(QUALIFIED_SEPARATOR);
+ }
+ sbd.append(qualifiedNames[i]);
+ }
+
+ return sbd.toString();
+ }
+
+ /**
+ * Parse a string representation of intent.
+ *
+ * @param intent string representation of intent
+ */
+ private void parse(String intent) {
+ String iname = validateFormat(intent);
+ int domainIdx = iname.indexOf(DOMAIN_SEPARATOR);
+ domain = iname.substring(0, domainIdx);
+ String qualifNamesStr = iname.substring(domainIdx + 1);
+ qualifiedNames = qualifNamesStr.split(QUALIFIED_SEPARATOR);
+
+ }
+
+ private String validateFormat(String intent) {
+ // TODO validate and canonicalize intent name
+ return intent;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ModelObject.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ModelObject.java
new file mode 100644
index 0000000000..2d5a0802e6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ModelObject.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.spi.model;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * The base class for assembly model subtypes
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class ModelObject {
+ private final Map<Object, Object> extensions = new HashMap<Object, Object>();
+
+ protected ModelObject() {
+ }
+
+ public Map<Object, Object> getExtensions() {
+ return extensions;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Multiplicity.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Multiplicity.java
new file mode 100644
index 0000000000..f7ec8759f8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Multiplicity.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.spi.model;
+
+/**
+ * Enumeration for multiplicity.
+ */
+public enum Multiplicity {
+ /**
+ * Indicates a relationship that is optionally connected to the requestor and which, if supplied, must be connected
+ * to exactly one provider.
+ */
+ ZERO_ONE,
+
+ /**
+ * Indicates a relationship that must be connected between exactly one requestor and exactly one provider.
+ */
+ ONE_ONE,
+
+ /**
+ * Indicates a relationship that is optionally connects the requestor to zero to unbounded providers.
+ */
+ ZERO_N,
+
+ /**
+ * Indicates a relationship that must be connected at the requestor and which connects it to zero to unbounded
+ * providers.
+ */
+ ONE_N
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Operation.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Operation.java
new file mode 100644
index 0000000000..70c309609f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Operation.java
@@ -0,0 +1,406 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.model;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * Represents an operation that is part of a service contract. The type paramter of this operation identifies the
+ * logical type system for all data types.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Operation<T> extends ModelObject implements Cloneable {
+ public static final int NO_CONVERSATION = -1;
+ public static final int CONVERSATION_CONTINUE = 1;
+ public static final int CONVERSATION_END = 2;
+
+ protected Map<String, Object> metaData;
+ private final String name;
+ private ServiceContract<T> contract;
+ private DataType<T> outputType;
+ private DataType<List<DataType<T>>> inputType;
+ private List<DataType<T>> faultTypes;
+ private String dataBinding;
+ private boolean wrapperStyle;
+ private WrapperInfo wrapper;
+ private boolean callback;
+ private boolean nonBlocking;
+ private int conversationSequence = NO_CONVERSATION;
+
+ /**
+ * Construct a minimally-specified operation
+ *
+ * @param name the name of the operation
+ * @param inputType the data types of parameters passed to the operation
+ * @param outputType the data type returned by the operation
+ * @param faultTypes the data type of faults raised by the operation
+ */
+ public Operation(String name,
+ DataType<List<DataType<T>>> inputType,
+ DataType<T> outputType,
+ List<DataType<T>> faultTypes) {
+ this(name, inputType, outputType, faultTypes, false, null, NO_CONVERSATION);
+ }
+
+ /**
+ * Construct an operation
+ *
+ * @param name the name of the operation
+ * @param inputType the data types of parameters passed to the operation
+ * @param outputType the data type returned by the operation
+ * @param faultTypes the data type of faults raised by the operation
+ * @param nonBlocking if the operation is non-blocking
+ * @param dataBinding the data-binding type required by the operation
+ * @param sequence the conversational attributes of the operation, {@link NO_CONVERSATION}, {@link
+ * CONVERSATION_CONTINUE}, or {@link CONVERSATION_END}
+ */
+ public Operation(final String name,
+ final DataType<List<DataType<T>>> inputType,
+ final DataType<T> outputType,
+ final List<DataType<T>> faultTypes,
+ boolean nonBlocking,
+ String dataBinding,
+ int sequence) {
+ super();
+ this.name = name;
+ List<DataType<T>> types = Collections.emptyList();
+ this.inputType = (inputType != null) ? inputType : new DataType<List<DataType<T>>>(Object[].class, types);
+ this.outputType = (outputType != null) ? outputType : new DataType<T>(void.class, null);
+ this.faultTypes = (faultTypes == null) ? types : faultTypes;
+ this.nonBlocking = nonBlocking;
+ this.dataBinding = dataBinding;
+ this.conversationSequence = sequence;
+ // Register the operation with the types
+ this.inputType.setOperation(this);
+ for (DataType<?> d : this.inputType.getLogical()) {
+ d.setOperation(this);
+ }
+ this.outputType.setOperation(this);
+ for (DataType<?> d : this.faultTypes) {
+ d.setOperation(this);
+ }
+ }
+
+ /**
+ * Returns the service contract the operation is part of.
+ *
+ * @return the service contract the operation is part of.
+ */
+ public ServiceContract<T> getServiceContract() {
+ return contract;
+ }
+
+ /**
+ * Sets the service contract the operation is part of.
+ *
+ * @param contract the service contract the operation is part of.
+ */
+ public void setServiceContract(ServiceContract<T> contract) {
+ this.contract = contract;
+ }
+
+ /**
+ * Returns true if the operation is part of the callback contract.
+ *
+ * @return true if the operation is part of the callback contract.
+ */
+ public boolean isCallback() {
+ return callback;
+ }
+
+ /**
+ * Sets whether the operation is part of the callback contract.
+ *
+ * @param callback whether the operation is part of the callback contract.
+ */
+ public void setCallback(boolean callback) {
+ this.callback = callback;
+ }
+
+ /**
+ * Returns the name of the operation.
+ *
+ * @return the name of the operation
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Returns the data type returned by the operation.
+ *
+ * @return the data type returned by the operation
+ */
+ public DataType<T> getOutputType() {
+ return outputType;
+ }
+
+ /**
+ * Returns the data types of the parameters passed to the operation.
+ * <p/>
+ * The inputType's logical type is a list of DataTypes which describes the parameter types
+ *
+ * @return the data types of the parameters passed to the operation
+ */
+ public DataType<List<DataType<T>>> getInputType() {
+ return inputType;
+ }
+
+ /**
+ * Returns the data types of the faults raised by the operation.
+ *
+ * @return the data types of the faults raised by the operation
+ */
+ public List<DataType<T>> getFaultTypes() {
+ if (faultTypes == null) {
+ return Collections.emptyList();
+ }
+ return faultTypes;
+ }
+
+ /**
+ * Returns true if the operation is non-blocking. A non-blocking operation may not have completed execution at the
+ * time an invocation of the operation returns.
+ *
+ * @return true if the operation is non-blocking
+ */
+ public boolean isNonBlocking() {
+ return nonBlocking;
+ }
+
+ /**
+ * Sets if the operation is non-blocking
+ */
+ public void setNonBlocking(boolean nonBlocking) {
+ this.nonBlocking = nonBlocking;
+ }
+
+ /**
+ * Returns the sequence the operation is called in a conversation, {@link NO_CONVERSATION}, {@link
+ * CONVERSATION_CONTINUE}, or {@link CONVERSATION_END}
+ *
+ * @return the sequence the operation is called in a conversation
+ */
+ public int getConversationSequence() {
+ return conversationSequence;
+ }
+
+ /**
+ * Sets the sequence the operation is called in a conversation, {@link NO_CONVERSATION}, {@link
+ * CONVERSATION_CONTINUE}, or {@link CONVERSATION_END}
+ */
+ public void setConversationSequence(int conversationSequence) {
+ this.conversationSequence = conversationSequence;
+ }
+
+ /**
+ * Returns the data binding type specified for the operation or null.
+ *
+ * @return the data binding type specified for the operation or null.
+ */
+ public String getDataBinding() {
+ return (dataBinding == null && contract != null) ? contract.getDataBinding() : dataBinding;
+ }
+
+ /**
+ * Set the databinding for this operation
+ *
+ * @param dataBinding The databinding
+ */
+ public void setDataBinding(String dataBinding) {
+ this.dataBinding = dataBinding;
+ }
+
+ /**
+ * Returns a map of metadata key to value mappings for the operation.
+ *
+ * @return a map of metadata key to value mappings for the operation.
+ */
+ public Map<String, Object> getMetaData() {
+ if (metaData == null) {
+ return Collections.emptyMap();
+ }
+ return metaData;
+ }
+
+ /**
+ * Adds metadata associated with the operation.
+ *
+ * @param key the metadata key
+ * @param val the metadata value
+ */
+ public void setMetaData(String key, Object val) {
+ if (metaData == null) {
+ metaData = new HashMap<String, Object>();
+ }
+ metaData.put(key, val);
+ }
+
+ public String toString() {
+ return name;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ final Operation operation = (Operation) o;
+
+ if (name != null ? !name.equals(operation.name) : operation.name != null) {
+ return false;
+ }
+
+ // HACK: If the operation is mappable, then the equality test is relaxed
+ if (isMappable()) {
+ return true;
+ }
+
+ // FIXME: TUSCANY-1111, currently comparing different IDLs fail
+ if (contract != null && contract.getClass() != operation.getServiceContract().getClass()) {
+ return true;
+ }
+
+ if (faultTypes == null && operation.faultTypes != null) {
+ return false;
+ } else if (faultTypes != null
+ && operation.faultTypes != null
+ && faultTypes.size() != 0
+ && operation.faultTypes.size() != 0) {
+ if (faultTypes.size() < operation.faultTypes.size()) {
+ return false;
+ } else {
+ //noinspection ForLoopReplaceableByForEach
+ for (int i = 0; i < operation.faultTypes.size(); i++) {
+ if (!faultTypes.get(i).equals(operation.faultTypes.get(i))) {
+ return false;
+ }
+ }
+ }
+ }
+
+ if (inputType != null ? !inputType.equals(operation.inputType) : operation.inputType != null) {
+ return false;
+ }
+ return !(outputType != null ? !outputType.equals(operation.outputType) : operation.outputType != null);
+ }
+
+ public int hashCode() {
+ int result;
+ result = name != null ? name.hashCode() : 0;
+ // HACK:
+ if (isMappable()) {
+ return result;
+ }
+ result = 29 * result + (outputType != null ? outputType.hashCode() : 0);
+ result = 29 * result + (inputType != null ? inputType.hashCode() : 0);
+ result = 29 * result + (faultTypes != null ? faultTypes.hashCode() : 0);
+ return result;
+ }
+
+ /**
+ * Returns true if the operation may be mapped to another target operation through an mediation
+ */
+ private boolean isMappable() {
+ if (contract != null) {
+ return contract.isRemotable();
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Returns true if the operation is wrapper style
+ *
+ * @return the wrapperStyle
+ */
+ public boolean isWrapperStyle() {
+ return wrapperStyle;
+ }
+
+ /**
+ * Return the Wrapper information for this operation is it's wrapper style
+ *
+ * @return The Wrapper
+ */
+ public WrapperInfo getWrapper() {
+ if (!isWrapperStyle()) {
+ throw new IllegalStateException("The operation is not wrapper style.");
+ } else {
+ return wrapper;
+ }
+ }
+
+ /**
+ * @param wrapper the wrapper to set
+ */
+ public void setWrapper(WrapperInfo wrapper) {
+ this.wrapper = wrapper;
+ }
+
+ /**
+ * @param wrapperStyle the wrapperStyle to set
+ */
+ public void setWrapperStyle(boolean wrapperStyle) {
+ this.wrapperStyle = wrapperStyle;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Operation<T> clone() throws CloneNotSupportedException {
+ Operation<T> copy = (Operation<T>) super.clone();
+ final List<DataType<T>> clonedFaultTypes = new ArrayList<DataType<T>>(this.faultTypes.size());
+ for (DataType<T> t : this.faultTypes) {
+ clonedFaultTypes.add((DataType<T>) t.clone());
+ }
+
+ List<DataType<T>> clonedTypes = new ArrayList<DataType<T>>();
+ for (DataType<T> t : inputType.getLogical()) {
+ DataType<T> type = (DataType<T>) t.clone();
+ clonedTypes.add(type);
+ }
+
+ DataType<List<DataType<T>>> clonedInputType =
+ new DataType<List<DataType<T>>>(inputType.getPhysical(), clonedTypes);
+ clonedInputType.setDataBinding(inputType.getDataBinding());
+
+ DataType<T> clonedOutputType = (DataType<T>) this.outputType.clone();
+
+ copy.inputType = clonedInputType;
+ copy.outputType = clonedOutputType;
+ copy.faultTypes = clonedFaultTypes;
+
+ if (this.metaData != null) {
+ assert this.metaData instanceof HashMap;
+ copy.metaData = (HashMap) ((HashMap) this.metaData).clone();
+ }
+ return copy;
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachable.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachable.java
new file mode 100644
index 0000000000..fee13f7205
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachable.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.spi.model;
+
+import java.util.Collection;
+/**
+*
+* Represents capability of being attached with Intent and PolicySet.
+*
+*/
+public interface PolicyAttachable {
+ /**
+ * Get the name of PolicySet attached
+ * @return the name of PolicySet
+ */
+ String getPolicySet();
+ /**
+ * Get collection contains <code>IntentName</code> required.
+ * @return collection contains <code>IntentName</code> required.
+ */
+ Collection<IntentName> getRequiredIntents();
+
+} \ No newline at end of file
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachableModel.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachableModel.java
new file mode 100644
index 0000000000..3ebbfb16d7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyAttachableModel.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.spi.model;
+
+import java.util.Collection;
+
+/**
+ * Base class for model classes which can be associated with Intent and PolicySet by specifing requires and policySet
+ * attributes on xml element.
+ */
+
+public abstract class PolicyAttachableModel extends ModelObject implements PolicyAttachable {
+ protected Collection<IntentName> requiredIntent;
+ protected String policySet;
+
+ public String getPolicySet() {
+ return policySet;
+ }
+
+ public void setPolicySet(String policySet) {
+ this.policySet = policySet;
+ }
+
+ public Collection<IntentName> getRequiredIntents() {
+ return requiredIntent;
+ }
+
+ public void addRequiredIntent(IntentName requiredIntent) {
+ this.requiredIntent.add(requiredIntent);
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyContentModel.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyContentModel.java
new file mode 100644
index 0000000000..7d2412ee8d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyContentModel.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.spi.model;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import static java.util.Collections.unmodifiableCollection;
+
+/**
+ * PolicyModel which contains concrete policy content in form of WSPolicyAttachment or other extensions.
+ */
+public abstract class PolicyContentModel extends PolicyModel {
+ /* WSPolicyAttachment contained in this Model */
+ protected Collection<WSPolicyAttachment> wsPolicyAttachments = new ArrayList<WSPolicyAttachment>();
+ /* Any policy model extensions besides standard intentMap, ws-policyattachment, etc. */
+ protected Collection<PolicyModel> extensions = new ArrayList<PolicyModel>();
+
+ public Collection<PolicyModel> getPolicyExtensions() {
+ return extensions;
+ }
+
+ public Collection<WSPolicyAttachment> getWsPolicyAttachments() {
+ return unmodifiableCollection(wsPolicyAttachments);
+ }
+
+ public void addWsPolicyAttachment(WSPolicyAttachment attachment) {
+ wsPolicyAttachments.add(attachment);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyModel.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyModel.java
new file mode 100644
index 0000000000..17bd8f0b7e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicyModel.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.spi.model;
+
+
+/**
+ * An abstract base class for all policy model representations.
+ * <p/>
+ * $Version$ $Date$
+ */
+public abstract class PolicyModel extends ModelObject {
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicySet.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicySet.java
new file mode 100644
index 0000000000..7545f234e1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicySet.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.spi.model;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import static java.util.Collections.unmodifiableCollection;
+import static java.util.Collections.unmodifiableList;
+import java.util.List;
+import javax.xml.namespace.QName;
+
+/**
+ * Model representation for PolicySet.
+ * <p/>
+ * $Rev$ $Date$
+ */
+public class PolicySet extends PolicyContentModel {
+
+ /**
+ * QNames of artifacts to which this Policy can apply
+ */
+ protected List<QName> appliedArtifacts = new ArrayList<QName>();
+
+ /**
+ * IntentMap contained in this PolicySet
+ */
+ private Collection<IntentMap> intentMaps = new ArrayList<IntentMap>();
+
+ /**
+ * Name for PolicySet, corresponding to name attribute of PolicySet element in SCDL
+ */
+ private QName name;
+
+ /**
+ * References to other PolicySet
+ */
+ private Collection<PolicySetReference> policySetReferences = new ArrayList<PolicySetReference>();
+
+ /**
+ * Name of intents provided by this PolicySet
+ */
+ private Collection<IntentName> provideIntents = new ArrayList<IntentName>();
+
+ public PolicySet(QName name, List<IntentName> providesIntent) {
+ super();
+ this.name = name;
+ this.provideIntents.addAll(providesIntent);
+ }
+
+
+ public void addPolicySetReference(PolicySetReference ref) {
+ policySetReferences.add(ref);
+ }
+
+ public void addAppliedArtifacts(QName artifactName) {
+ appliedArtifacts.add(artifactName);
+ }
+
+ public List<QName> getAppliedArtifacts() {
+ return unmodifiableList(appliedArtifacts);
+ }
+
+ public void addIntentMap(IntentMap intentMap) {
+ intentMaps.add(intentMap);
+ }
+
+ public Collection<IntentMap> getIntentMaps() {
+ return unmodifiableCollection(intentMaps);
+ }
+
+ public QName getName() {
+ return name;
+ }
+
+ public Collection<PolicySetReference> getPolicySetReferences() {
+ return unmodifiableCollection(policySetReferences);
+ }
+
+ public Collection<IntentName> getProvideIntents() {
+ return unmodifiableCollection(provideIntents);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicySetReference.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicySetReference.java
new file mode 100644
index 0000000000..46924910d0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PolicySetReference.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.spi.model;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Presents a PolicySetReference.
+ */
+public class PolicySetReference extends PolicyModel {
+
+ private QName reference;
+
+ public PolicySetReference(QName reference) {
+ super();
+ this.reference = reference;
+ }
+
+ public QName getReference() {
+ return reference;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Property.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Property.java
new file mode 100644
index 0000000000..9b6e192c17
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Property.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.spi.model;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Document;
+
+import org.apache.tuscany.spi.ObjectFactory;
+
+/**
+ * A component property
+ *
+ * @version $Rev$ $Date$
+ */
+public class Property<T> extends ModelObject {
+ private String name;
+ private boolean required;
+ private ObjectFactory<T> defaultValueFactory;
+ private QName xmlType;
+ private Class<T> javaType;
+ private boolean many;
+ private Document defaultValue;
+
+ public Property() {
+ }
+
+ public Property(String name, QName xmlType, Class<T> javaType) {
+ this.name = name;
+ this.xmlType = xmlType;
+ this.javaType = javaType;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public boolean isRequired() {
+ return required;
+ }
+
+ public void setRequired(boolean required) {
+ this.required = required;
+ }
+
+ public ObjectFactory<T> getDefaultValueFactory() {
+ return defaultValueFactory;
+ }
+
+ public void setDefaultValueFactory(ObjectFactory<T> factory) {
+ this.defaultValueFactory = factory;
+ }
+
+ public QName getXmlType() {
+ return xmlType;
+ }
+
+ public void setXmlType(QName xmlType) {
+ this.xmlType = xmlType;
+ }
+
+ public Class<T> getJavaType() {
+ return javaType;
+ }
+
+ public void setJavaType(Class<T> javaType) {
+ this.javaType = javaType;
+ }
+
+ public boolean isMany() {
+ return many;
+ }
+
+ public void setMany(boolean many) {
+ this.many = many;
+ }
+
+ public Document getDefaultValue() {
+ return defaultValue;
+ }
+
+ public void setDefaultValue(Document defaultValue) {
+ this.defaultValue = defaultValue;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PropertyValue.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PropertyValue.java
new file mode 100644
index 0000000000..93eaa74f52
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/PropertyValue.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.spi.model;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.w3c.dom.Document;
+
+/**
+ * Represents a configured component property
+ *
+ * @version $Rev$ $Date$
+ */
+public class PropertyValue<T> extends ModelObject {
+ private String name;
+ private String source;
+ private String file;
+ private Document value;
+ private ObjectFactory<T> valueFactory;
+
+ public PropertyValue() {
+ }
+
+ /**
+ * Constructor specifying the name of a property and the XPath source expression.
+ *
+ * @param name the name of the property which this value is for
+ * @param source an XPath expression whose result will be the actual value
+ * @param file A URI that the property value can be loaded from
+ */
+ public PropertyValue(String name, String source, String file) {
+ this.name = name;
+ this.source = source;
+ this.file = file;
+ }
+
+ /**
+ * @param name
+ * @param value
+ */
+ public PropertyValue(String name, Document value) {
+ this.name = name;
+ this.value = value;
+ }
+
+ public PropertyValue(String name, ObjectFactory<T> valueFactory) {
+ this.name = name;
+ this.valueFactory = valueFactory;
+ }
+
+ /**
+ * Returns the name of the property that this value is for.
+ * @return the name of the property that this value is for
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name of the property that this value is for.
+ * @param name the name of the property that this value is for
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns an XPath expression that should be evaluated to get the actual property value.
+ *
+ * @return an XPath expression that should be evaluated to get the actual property value
+ */
+ public String getSource() {
+ return source;
+ }
+
+ /**
+ * Sets an XPath expression that should be evaluated to get the actual property value.
+ * @param source an XPath expression that should be evaluated to get the actual property value
+ */
+ public void setSource(String source) {
+ this.source = source;
+ }
+
+ public ObjectFactory<T> getValueFactory() {
+ return valueFactory;
+ }
+
+ public void setValueFactory(ObjectFactory<T> valueFactory) {
+ this.valueFactory = valueFactory;
+ }
+
+ public Document getValue() {
+ return value;
+ }
+
+ public void setValue(Document value) {
+ this.value = value;
+ }
+
+ /**
+ * @return the file
+ */
+ public String getFile() {
+ return file;
+ }
+
+ /**
+ * @param file the file to set
+ */
+ public void setFile(String file) {
+ this.file = file;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Qualifier.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Qualifier.java
new file mode 100644
index 0000000000..8a7d709bd9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Qualifier.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.spi.model;
+
+/**
+ * Model reprentation for qualifier
+ */
+
+public class Qualifier extends PolicyContentModel {
+
+ private String name;
+
+ /**
+ * IntentMap contained in this Qualifier
+ */
+ private IntentMap intentMap;
+
+ public Qualifier(String name) {
+ super();
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public IntentMap getIntentMap() {
+ return intentMap;
+ }
+
+ public void setIntentMap(IntentMap intentMap) {
+ this.intentMap = intentMap;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ReferenceDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ReferenceDefinition.java
new file mode 100644
index 0000000000..46dfd8e0a0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ReferenceDefinition.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.spi.model;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Represents a component reference
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReferenceDefinition extends ModelObject {
+ private URI uri;
+ private ServiceContract serviceContract;
+ private Multiplicity multiplicity;
+ private boolean required;
+ private List<BindingDefinition> bindings;
+
+ public ReferenceDefinition() {
+ multiplicity = Multiplicity.ONE_ONE;
+ bindings = new ArrayList<BindingDefinition>();
+ }
+
+ public ReferenceDefinition(URI uri, ServiceContract serviceContract) {
+ this.uri = uri;
+ this.serviceContract = serviceContract;
+ bindings = new ArrayList<BindingDefinition>();
+ multiplicity = Multiplicity.ONE_ONE;
+ }
+
+ public ReferenceDefinition(URI uri, ServiceContract serviceContract, Multiplicity multiplicity) {
+ this.uri = uri;
+ this.serviceContract = serviceContract;
+ this.multiplicity = multiplicity;
+ bindings = new ArrayList<BindingDefinition>();
+ }
+
+ public URI getUri() {
+ return uri;
+ }
+
+ public void setUri(URI uri) {
+ this.uri = uri;
+ }
+
+ public ServiceContract<?> getServiceContract() {
+ return serviceContract;
+ }
+
+ public void setServiceContract(ServiceContract serviceContract) {
+ this.serviceContract = serviceContract;
+ }
+
+ public Multiplicity getMultiplicity() {
+ return multiplicity;
+ }
+
+ public void setMultiplicity(Multiplicity multiplicity) {
+ this.multiplicity = multiplicity;
+ }
+
+ public boolean isRequired() {
+ return required;
+ }
+
+ public void setRequired(boolean required) {
+ this.required = required;
+ }
+
+ public List<BindingDefinition> getBindings() {
+ return Collections.unmodifiableList(bindings);
+ }
+
+ public void addBinding(BindingDefinition binding) {
+ this.bindings.add(binding);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ReferenceTarget.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ReferenceTarget.java
new file mode 100644
index 0000000000..bc721ea02c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ReferenceTarget.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.spi.model;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents the set of targets configured on a reference
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReferenceTarget extends ModelObject {
+ private URI referenceName;
+ private boolean autowire;
+ private List<URI> targets = new ArrayList<URI>();
+
+ public URI getReferenceName() {
+ return referenceName;
+ }
+
+ public void setReferenceName(URI referenceName) {
+ this.referenceName = referenceName;
+ }
+
+ /**
+ * Returns true if autowire is enabled for the reference.
+ *
+ * @return true if autowire is enabled for the reference.
+ */
+ public boolean isAutowire() {
+ return autowire;
+ }
+
+ /**
+ * Sets autowire enablement for the reference.
+ *
+ * @param autowire true if autowire is enabled.
+ */
+ public void setAutowire(boolean autowire) {
+ this.autowire = autowire;
+ }
+
+ public List<URI> getTargets() {
+ return targets;
+ }
+
+ public void addTarget(URI target) {
+ targets.add(target);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ResourceDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ResourceDefinition.java
new file mode 100644
index 0000000000..02da577656
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ResourceDefinition.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.spi.model;
+
+/**
+ * Represents a resource definition. Resources are provisioned to runtime nodes.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ResourceDefinition {
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Scope.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Scope.java
new file mode 100644
index 0000000000..450839dd03
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/Scope.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.spi.model;
+
+/**
+ * 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;
+ }
+
+ @SuppressWarnings({"StringEquality"})
+ 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/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ServiceContract.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ServiceContract.java
new file mode 100644
index 0000000000..d2c7df55ff
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ServiceContract.java
@@ -0,0 +1,283 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.model;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Base class representing service contract information
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class ServiceContract<T> extends ModelObject implements Cloneable {
+ protected boolean conversational;
+ protected boolean remotable;
+ protected Class<?> interfaceClass;
+ protected String interfaceName;
+ protected String callbackName;
+ protected Class<?> callbackClass;
+ protected Map<String, Operation<T>> operations;
+ protected Map<String, Operation<T>> callbackOperations;
+ protected String dataBinding;
+ protected Map<String, Object> metaData;
+
+ protected ServiceContract() {
+ }
+
+ protected ServiceContract(Class<?> interfaceClass) {
+ this.interfaceClass = interfaceClass;
+ }
+
+ protected ServiceContract(String interfaceName) {
+ this.interfaceName = interfaceName;
+ }
+
+ /**
+ * Returns the interface name for the contract
+ *
+ * @return the interface name for the contract
+ */
+ public String getInterfaceName() {
+ return interfaceName;
+ }
+
+ /**
+ * Sets the interface name for the contract
+ */
+ public void setInterfaceName(String interfaceName) {
+ this.interfaceName = interfaceName;
+ }
+
+ /**
+ * Returns the class used to represent the service contract
+ */
+ public Class<?> getInterfaceClass() {
+ return interfaceClass;
+ }
+
+ /**
+ * Sets the class used to represent the service contract
+ */
+ public void setInterfaceClass(Class<?> interfaceClass) {
+ this.interfaceClass = interfaceClass;
+ }
+
+ /**
+ * Returns true if the service contract is conversational
+ *
+ * @return true if the service contract is conversational
+ */
+ public boolean isConversational() {
+ return conversational;
+ }
+
+ /**
+ * Sets if the service contract is conversational
+ *
+ * @param conversational the conversational attribute
+ */
+ public void setConversational(boolean conversational) {
+ this.conversational = conversational;
+ }
+
+ /**
+ * @return the remotable
+ */
+ public boolean isRemotable() {
+ return remotable;
+ }
+
+ /**
+ * @param remotable the remotable to set
+ */
+ public void setRemotable(boolean remotable) {
+ this.remotable = remotable;
+ }
+
+ /**
+ * Returns the name of the callback or null if the contract is unidirectional
+ */
+ public String getCallbackName() {
+ return callbackName;
+ }
+
+ /**
+ * Sets the name of the callback service
+ */
+ public void setCallbackName(String callbackName) {
+ this.callbackName = callbackName;
+ }
+
+ /**
+ * Returns the name of the callback service
+ */
+ public Class<?> getCallbackClass() {
+ return callbackClass;
+ }
+
+ public void setCallbackClass(Class<?> callbackClass) {
+ this.callbackClass = callbackClass;
+ }
+
+ public Operation getOperation(String name) {
+ return operations == null ? null : operations.get(name);
+ }
+
+ public Map<String, Operation<T>> getOperations() {
+ if (operations == null) {
+ return Collections.emptyMap();
+ }
+ return Collections.unmodifiableMap(operations);
+ }
+
+ public void setOperations(Map<String, Operation<T>> operations) {
+ for (Operation<T> operation : operations.values()) {
+ operation.setServiceContract(this);
+ }
+ this.operations = operations;
+ }
+
+ public Map<String, Operation<T>> getCallbackOperations() {
+ if (callbackOperations == null) {
+ return Collections.emptyMap();
+ }
+ return Collections.unmodifiableMap(callbackOperations);
+ }
+
+ public void setCallbackOperations(Map<String, Operation<T>> callbacksOperations) {
+ for (Operation<T> operation : callbacksOperations.values()) {
+ operation.setServiceContract(this);
+ operation.setCallback(true);
+ }
+ this.callbackOperations = callbacksOperations;
+ }
+
+ public String getDataBinding() {
+ return dataBinding;
+ }
+
+ public void setDataBinding(String dataBinding) {
+ this.dataBinding = dataBinding;
+ }
+
+ /**
+ * Returns a map of metadata key to value mappings for the operation.
+ *
+ * @return a map of metadata key to value mappings for the operation.
+ */
+ public Map<String, Object> getMetaData() {
+ if (metaData == null) {
+ return Collections.emptyMap();
+ }
+ return metaData;
+ }
+
+ /**
+ * Adds metadata associated with the operation.
+ *
+ * @param key the metadata key
+ * @param val the metadata value
+ */
+ public void setMetaData(String key, Object val) {
+ if (metaData == null) {
+ metaData = new HashMap<String, Object>();
+ }
+ metaData.put(key, val);
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ final ServiceContract that = (ServiceContract) o;
+
+ if (callbackName != null ? !callbackName.equals(that.callbackName) : that.callbackName != null) {
+ return false;
+ }
+ if (callbackOperations != null ? !callbackOperations.equals(that.callbackOperations)
+ : that.callbackOperations != null) {
+ return false;
+ }
+ if (interfaceClass != null ? !interfaceClass.equals(that.interfaceClass) : that.interfaceClass != null) {
+ return false;
+ }
+ if (interfaceName != null ? !interfaceName.equals(that.interfaceName) : that.interfaceName != null) {
+ return false;
+ }
+ return !(operations != null ? !operations.equals(that.operations) : that.operations != null);
+
+ }
+
+ public int hashCode() {
+ int result;
+ result = interfaceClass != null ? interfaceClass.hashCode() : 0;
+ result = 29 * result + (interfaceName != null ? interfaceName.hashCode() : 0);
+ result = 29 * result + (callbackName != null ? callbackName.hashCode() : 0);
+ result = 29 * result + (operations != null ? operations.hashCode() : 0);
+ result = 29 * result + (callbackOperations != null ? callbackOperations.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ if (interfaceName != null) {
+ return new StringBuilder().append("ServiceContract[").append(interfaceName).append("]").toString();
+ } else if (interfaceClass != null) {
+ return new StringBuilder().append("ServiceContract[").append(interfaceClass.getName()).append("]")
+ .toString();
+ } else {
+ return super.toString();
+ }
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ ServiceContract<T> copy = (ServiceContract<T>) super.clone();
+
+ if (operations != null) {
+ Map<String, Operation<T>> clonedOperations = new HashMap<String, Operation<T>>();
+ for (Operation<T> o : operations.values()) {
+ clonedOperations.put(o.getName(), (Operation<T>)o.clone());
+ }
+ copy.setOperations(clonedOperations);
+ }
+
+ if (callbackOperations != null) {
+ Map<String, Operation<T>> clonedCallbackOperations = new HashMap<String, Operation<T>>();
+ for (Operation<T> o : callbackOperations.values()) {
+ clonedCallbackOperations.put(o.getName(), (Operation<T>)o.clone());
+ }
+ copy.setCallbackOperations(clonedCallbackOperations);
+ }
+
+ if (this.metaData != null) {
+ assert this.metaData instanceof HashMap;
+ copy.metaData = (HashMap) ((HashMap) this.metaData).clone();
+ }
+
+ return copy;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ServiceDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ServiceDefinition.java
new file mode 100644
index 0000000000..25c1beffe1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/ServiceDefinition.java
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.model;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Represents a service offered by a component
+ *
+ * @version $Rev$ $Date$
+ */
+public class ServiceDefinition extends ModelObject {
+ private URI uri;
+ private ServiceContract serviceContract;
+ private boolean remotable;
+ private String callbackRefName;
+ private List<BindingDefinition> bindings;
+ private URI target;
+
+ public ServiceDefinition() {
+ bindings = new ArrayList<BindingDefinition>();
+ }
+
+ public ServiceDefinition(URI uri, ServiceContract serviceContract, boolean remotable) {
+ bindings = new ArrayList<BindingDefinition>();
+ this.uri = uri;
+ this.serviceContract = serviceContract;
+ this.remotable = remotable;
+ }
+
+ public ServiceDefinition(URI uri, ServiceContract serviceContract, boolean remotable, String callbackRefName) {
+ bindings = new ArrayList<BindingDefinition>();
+ this.uri = uri;
+ this.serviceContract = serviceContract;
+ this.remotable = remotable;
+ this.callbackRefName = callbackRefName;
+ }
+
+ /**
+ * Returns the service name
+ *
+ * @return the service name
+ */
+ public URI getUri() {
+ return uri;
+ }
+
+ /**
+ * Sets the service name
+ *
+ * @param uri the service name
+ */
+ public void setUri(URI uri) {
+ this.uri = uri;
+ }
+
+ /**
+ * Returns the service contract
+ *
+ * @return the service contract
+ */
+ public ServiceContract<?> getServiceContract() {
+ return serviceContract;
+ }
+
+ /**
+ * Sets the service contract
+ *
+ * @param contract the service contract
+ */
+ public void setServiceContract(ServiceContract contract) {
+ this.serviceContract = contract;
+ }
+
+ /**
+ * Returns true if the service is remotable
+ *
+ * @return true if the service is remotable
+ */
+ public boolean isRemotable() {
+ return remotable;
+ }
+
+ /**
+ * Sets if the service is remotable
+ *
+ * @param remotable if the service is remotable
+ */
+ public void setRemotable(boolean remotable) {
+ this.remotable = remotable;
+ }
+
+ /**
+ * Returns the callback name.
+ */
+ public String getCallbackReferenceName() {
+ return callbackRefName;
+ }
+
+ /**
+ * Sets the callback name
+ */
+ public void setCallbackReferenceName(String name) {
+ this.callbackRefName = name;
+ }
+
+ /**
+ * Returns the bindings configured for the service
+ *
+ * @return the bindings configured for the service
+ */
+ public List<BindingDefinition> getBindings() {
+ return Collections.unmodifiableList(bindings);
+ }
+
+ /**
+ * Configures the service with a binding
+ *
+ * @param binding the binding
+ */
+ public void addBinding(BindingDefinition binding) {
+ this.bindings.add(binding);
+ }
+
+ /**
+ * Returns the target URI the service is wired to
+ *
+ * @return the target URI the service is wired to
+ */
+ public URI getTarget() {
+ return target;
+ }
+
+ /**
+ * Sets the target URI the service is wired to
+ *
+ * @param target the target URI the service is wired to
+ */
+ public void setTarget(URI target) {
+ this.target = target;
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/TypeInfo.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/TypeInfo.java
new file mode 100644
index 0000000000..12ea9fa8ce
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/TypeInfo.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.spi.model;
+
+import javax.xml.namespace.QName;
+
+/**
+ * An abstraction of XML schema types
+ */
+public class TypeInfo {
+ private QName name;
+
+ private boolean isSimpleType;
+
+ private TypeInfo baseType;
+
+ /**
+ * @param name
+ * @param isSimpleType
+ */
+ public TypeInfo(QName name, boolean isSimpleType, TypeInfo baseType) {
+ super();
+ this.name = name;
+ this.isSimpleType = isSimpleType;
+ this.baseType = baseType;
+ }
+
+ /**
+ * @return the isSimpleType
+ */
+ public boolean isSimpleType() {
+ return isSimpleType;
+ }
+
+ /**
+ * @return the name
+ */
+ public QName getQName() {
+ return name;
+ }
+
+ /**
+ * @return the baseType
+ */
+ public TypeInfo getBaseType() {
+ return baseType;
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("Type: ").append(name);
+ return sb.toString();
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/WSPolicyAttachment.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/WSPolicyAttachment.java
new file mode 100644
index 0000000000..ff1a6cf791
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/WSPolicyAttachment.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.spi.model;
+
+/*
+ * Presents a ws-policy attachment.
+ */
+public class WSPolicyAttachment<T> extends PolicyModel {
+ private T content;
+
+ public T getContent() {
+ return content;
+ }
+
+ public void setContent(T content) {
+ this.content = content;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/WireDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/WireDefinition.java
new file mode 100644
index 0000000000..7ae91811b6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/WireDefinition.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.spi.model;
+
+import java.net.URI;
+
+/**
+ * Represents a wire specified in an assembly
+ *
+ * @version $Rev$ $Date$
+ */
+public class WireDefinition extends ModelObject {
+ private URI source;
+ private URI target;
+
+ public URI getSource() {
+ return source;
+ }
+
+ public void setSource(URI source) {
+ this.source = source;
+ }
+
+ public URI getTarget() {
+ return target;
+ }
+
+ public void setTarget(URI target) {
+ this.target = target;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/WrapperInfo.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/WrapperInfo.java
new file mode 100644
index 0000000000..acdb5d7deb
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/WrapperInfo.java
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.spi.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * The "Wrapper Style" WSDL operation is defined by The Java API for XML-Based
+ * Web Services (JAX-WS) 2.0 specification, section 2.3.1.2 Wrapper Style. <p/>
+ * A WSDL operation qualifies for wrapper style mapping only if the following
+ * criteria are met:
+ * <ul>
+ * <li>(i) The operation’s input and output messages (if present) each contain
+ * only a single part
+ * <li>(ii) The input message part refers to a global element declaration whose
+ * localname is equal to the operation name
+ * <li>(iii) The output message part refers to a global element declaration
+ * <li>(iv) The elements referred to by the input and output message parts
+ * (henceforth referred to as wrapper elements) are both complex types defined
+ * using the xsd:sequence compositor
+ * <li>(v) The wrapper elements only contain child elements, they must not
+ * contain other structures such as wildcards (element or attribute),
+ * xsd:choice, substitution groups (element references are not permitted) or
+ * attributes; furthermore, they must not be nillable.
+ * </ul>
+ *
+ * @version $Rev$ $Date$
+ */
+public class WrapperInfo {
+ private ElementInfo inputWrapperElement;
+
+ private ElementInfo outputWrapperElement;
+
+ private List<ElementInfo> inputChildElements;
+
+ private List<ElementInfo> outputChildElements;
+
+ private DataType<List<DataType<XMLType>>> unwrappedInputType;
+
+ private DataType<XMLType> unwrappedOutputType;
+
+ private String dataBinding;
+
+ public WrapperInfo(String dataBinding,
+ ElementInfo inputWrapperElement,
+ ElementInfo outputWrapperElement,
+ List<ElementInfo> inputElements,
+ List<ElementInfo> outputElements) {
+ super();
+ this.dataBinding = dataBinding;
+ this.inputWrapperElement = inputWrapperElement;
+ this.outputWrapperElement = outputWrapperElement;
+ this.inputChildElements = inputElements;
+ this.outputChildElements = outputElements;
+ }
+
+ /**
+ * @return the inputElements
+ */
+ public List<ElementInfo> getInputChildElements() {
+ return inputChildElements;
+ }
+
+ /**
+ * @return the inputWrapperElement
+ */
+ public ElementInfo getInputWrapperElement() {
+ return inputWrapperElement;
+ }
+
+ /**
+ * @return the outputElements
+ */
+ public List<ElementInfo> getOutputChildElements() {
+ return outputChildElements;
+ }
+
+ /**
+ * @return the outputWrapperElement
+ */
+ public ElementInfo getOutputWrapperElement() {
+ return outputWrapperElement;
+ }
+
+ /**
+ * @return the unwrappedInputType
+ */
+ public DataType<List<DataType<XMLType>>> getUnwrappedInputType() {
+ if (unwrappedInputType == null) {
+ List<DataType<XMLType>> childTypes = new ArrayList<DataType<XMLType>>();
+ for (ElementInfo element : getInputChildElements()) {
+ DataType<XMLType> type = new DataType<XMLType>(dataBinding, Object.class, new XMLType(element));
+ type.setMetadata(ElementInfo.class.getName(), element);
+ childTypes.add(type);
+ }
+ unwrappedInputType = new DataType<List<DataType<XMLType>>>("idl:unwrapped.input", Object[].class,
+ childTypes);
+ }
+ return unwrappedInputType;
+ }
+
+ /**
+ * @return the unwrappedOutputType
+ */
+ public DataType<XMLType> getUnwrappedOutputType() {
+ if (unwrappedOutputType == null) {
+ List<ElementInfo> elements = getOutputChildElements();
+ if (elements != null && elements.size() > 0) {
+ if (elements.size() > 1) {
+ // We don't support output with multiple parts
+ throw new IllegalArgumentException("Multi-part output is not supported");
+ }
+ ElementInfo element = elements.get(0);
+
+ unwrappedOutputType = new DataType<XMLType>(dataBinding, Object.class, new XMLType(element));
+ unwrappedOutputType.setMetadata(ElementInfo.class.getName(), element);
+ }
+ }
+ return unwrappedOutputType;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/XMLType.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/XMLType.java
new file mode 100644
index 0000000000..f780c7c5f5
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/XMLType.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.spi.model;
+
+import javax.xml.namespace.QName;
+
+/**
+ * The metadata for an XML element or type
+ */
+public class XMLType {
+ public static final XMLType UNKNOWN = new XMLType(null, null);
+ protected QName element;
+ protected QName type;
+
+ /**
+ * @param element
+ */
+ public XMLType(ElementInfo element) {
+ super();
+ this.element = element.getQName();
+ if (element.getType() != null) {
+ this.type = element.getType().getQName();
+ }
+ }
+
+ /**
+ * @param element
+ */
+ public XMLType(TypeInfo type) {
+ this.element = null;
+ this.type = type.getQName();
+ }
+
+ public XMLType(QName element, QName type) {
+ this.element = element;
+ this.type = type;
+ }
+
+ /**
+ * @return the type
+ */
+ public QName getTypeName() {
+ return type;
+ }
+
+ public boolean isElement() {
+ return element != null;
+ }
+
+ public QName getElementName() {
+ return element;
+ }
+
+ public static XMLType getType(QName type) {
+ return new XMLType(null, type);
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + ((element == null) ? 0 : element.hashCode());
+ result = PRIME * result + ((type == null) ? 0 : type.hashCode());
+ return result;
+ }
+
+ /**
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final XMLType other = (XMLType)obj;
+ if (element == null) {
+ if (other.element != null) {
+ return false;
+ }
+ } else if (!element.equals(other.element)) {
+ return false;
+ }
+ if (type == null) {
+ if (other.type != null) {
+ return false;
+ }
+ } else if (!type.equals(other.type)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "Element: " + element + " Type: " + type;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/InstanceFactoryProviderDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/InstanceFactoryProviderDefinition.java
new file mode 100644
index 0000000000..45314daaee
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/InstanceFactoryProviderDefinition.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.spi.model.physical;
+
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * Base class for instance factory provider definition.
+ *
+ * @version $Revsion$ $Date$
+ * @param
+ */
+public class InstanceFactoryProviderDefinition<T> extends ModelObject {
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/POJOComponentDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/POJOComponentDefinition.java
new file mode 100644
index 0000000000..be68ad9f61
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/POJOComponentDefinition.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.spi.model.physical;
+
+import java.net.URI;
+
+/**
+ * Definition of a physical component based on a POJO.
+ *
+ * @version $Rev$ $Date$
+ * @param <T> the implementation class (if known)
+ */
+public abstract class POJOComponentDefinition<T> extends PhysicalComponentDefinition {
+
+ private InstanceFactoryProviderDefinition<T> instanceFactoryProviderDefinition;
+ private URI classLoaderId;
+
+ /**
+ * Gets the instance factory provider definition.
+ * @return Instance factory provider definition.
+ */
+ public InstanceFactoryProviderDefinition<T> getInstanceFactoryProviderDefinition() {
+ return instanceFactoryProviderDefinition;
+ }
+
+ /**
+ * Sets the instance factory provider definition.
+ * @param instanceFactoryProviderDefinition Instance factory provider definition.
+ */
+ public void setInstanceFactoryProviderDefinition(
+ InstanceFactoryProviderDefinition<T> instanceFactoryProviderDefinition) {
+ this.instanceFactoryProviderDefinition = instanceFactoryProviderDefinition;
+ }
+
+ /**
+ * Gets the classloader id.
+ *
+ * @return Classloader id.
+ */
+ public URI getClassLoaderId() {
+ return classLoaderId;
+ }
+
+ /**
+ * Set the classloader id.
+ *
+ * @param classLoaderId Classloader id.
+ */
+ public void setClassLoaderId(URI classLoaderId) {
+ this.classLoaderId = classLoaderId;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalChangeSet.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalChangeSet.java
new file mode 100644
index 0000000000..658800769a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalChangeSet.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.spi.model.physical;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * Models a physical change set, sent from the master to the slave.
+ *
+ * @version $Revsion$ $Date$
+ *
+ */
+public class PhysicalChangeSet extends ModelObject {
+
+ // Set of physical component definitions
+ private Set<PhysicalComponentDefinition> componentDefinitions = new HashSet<PhysicalComponentDefinition>();
+
+ // Set of wire definitions
+ private Set<PhysicalWireDefinition> wireDefinitions = new HashSet<PhysicalWireDefinition>();
+
+ /**
+ * Get all the physical component definitions.
+ * @return Physical component definitions in the changeset.
+ */
+ public Set<PhysicalComponentDefinition> getComponentDefinitions() {
+ return Collections.unmodifiableSet(componentDefinitions);
+ }
+
+ /**
+ * Get all the wire definitions.
+ * @return Wire definitions in the changeset.
+ */
+ public Set<PhysicalWireDefinition> getWireDefinitions() {
+ return Collections.unmodifiableSet(wireDefinitions);
+ }
+
+ /**
+ * Adds a physical component definition to the physical change set.
+ * @param componentDefinition Physical component definition.
+ */
+ public void addComponentDefinition(PhysicalComponentDefinition componentDefinition) {
+ componentDefinitions.add(componentDefinition);
+ }
+
+ /**
+ * Adds a physical wire definition to the physical change set.
+ * @param wireDefinition Physical wire definition.
+ */
+ public void addWireDefinition(PhysicalWireDefinition wireDefinition) {
+ wireDefinitions.add(wireDefinition);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalComponentDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalComponentDefinition.java
new file mode 100644
index 0000000000..ab78fe44dd
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalComponentDefinition.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.spi.model.physical;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.Scope;
+
+/**
+ * Represents a physical component model.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class PhysicalComponentDefinition extends ModelObject {
+
+ private URI componentId;
+ private Scope scope;
+ private URI groupId;
+ private int initLevel;
+
+ /**
+ * Gets the component id.
+ *
+ * @return Component id.
+ */
+ public URI getComponentId() {
+ return componentId;
+ }
+
+ /**
+ * Sets the component id.
+ *
+ * @param componentId the component id
+ */
+ public void setComponentId(URI componentId) {
+ this.componentId = componentId;
+ }
+
+ /**
+ * Returns the id of the component group this component belongs to.
+ * @return the id of the component group this component belongs to
+ */
+ public URI getGroupId() {
+ return groupId;
+ }
+
+ /**
+ * Sets the id of the component group this component belongs to.
+ * @param groupId the id of the component group this component belongs to
+ */
+ public void setGroupId(URI groupId) {
+ this.groupId = groupId;
+ }
+
+ public int getInitLevel() {
+ return initLevel;
+ }
+
+ public void setInitLevel(int initLevel) {
+ this.initLevel = initLevel;
+ }
+
+ /**
+ * Gets the scope for the component.
+ *
+ * @return The scope for the component.
+ */
+ @Deprecated
+ public Scope getScope() {
+ return scope;
+ }
+
+ /**
+ * Sets the scope for the component.
+ *
+ * @param scope The scope for the component.
+ */
+ @Deprecated
+ public void setScope(Scope scope) {
+ this.scope = scope;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalInterceptorDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalInterceptorDefinition.java
new file mode 100644
index 0000000000..0cecc640ba
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalInterceptorDefinition.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.spi.model.physical;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * Model class representing the portable definition of an interceptor. This class is used to describe the interceptors
+ * around inbound and outbound wires on a physical component definition.
+ *
+ * @version $Rev$ $Date$
+ */
+public class PhysicalInterceptorDefinition extends ModelObject {
+
+ // The qualified name of the interceptor builder
+ private QName builder;
+
+ public PhysicalInterceptorDefinition(QName builder) {
+ this.builder = builder;
+ }
+
+ /**
+ * Gets the qualified name of the builder.
+ *
+ * @return Qualified name of the builder.
+ */
+ public QName getBuilder() {
+ return builder;
+ }
+
+ /**
+ * Sets the qualified name of the builder.
+ *
+ * @param builder Qualified name of the builder.
+ */
+ public void setBuilder(QName builder) {
+ this.builder = builder;
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalOperationDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalOperationDefinition.java
new file mode 100644
index 0000000000..852e71490b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalOperationDefinition.java
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.model.physical;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * Represents an operation.
+ *
+ * @version $Revision$ $Date$
+ * <p/>
+ * TODO Discuss with Jeremy/Jim on how to model MEPs, INOUT parameters, faults etc
+ */
+public class PhysicalOperationDefinition extends ModelObject {
+
+ // Parameters
+ private List<String> parameterTypes = new LinkedList<String>();
+
+ // Return
+ private String returnType;
+
+ // Name of the operation
+ private String name;
+
+ // Callback
+ private boolean callback;
+
+ private int conversationSequence;
+
+ // Interceptors defined against the operation
+ private Set<PhysicalInterceptorDefinition> interceptors = new HashSet<PhysicalInterceptorDefinition>();
+
+ /**
+ * Returns the fully qualified parameter types for this operation.
+ *
+ * @return Parameter types.
+ */
+ public List<String> getParameters() {
+ return Collections.unmodifiableList(parameterTypes);
+ }
+
+ /**
+ * Add the fully qualified parameter type to the operation.
+ *
+ * @param parameter Parameter type to be added.
+ */
+ public void addParameter(String parameter) {
+ parameterTypes.add(parameter);
+ }
+
+ /**
+ * Gets the fuly qualified return type for this operation.
+ *
+ * @return Return type for this operation.
+ */
+ public String getReturnType() {
+ return returnType;
+ }
+
+ /**
+ * Sets the fully qualified return type for this operation.
+ *
+ * @param returnType Return type for this operation.
+ */
+ public void setReturnType(String returnType) {
+ this.returnType = returnType;
+ }
+
+ /**
+ * Returns the interceptor definitions available for this operation.
+ *
+ * @return Inteceptor definitions for this operation.
+ */
+ public Set<PhysicalInterceptorDefinition> getInterceptors() {
+ return Collections.unmodifiableSet(interceptors);
+ }
+
+ /**
+ * Adds an interceptor definition to the operation.
+ *
+ * @param interceptor Interceptor definition to be added.
+ */
+ public void addInterceptor(PhysicalInterceptorDefinition interceptor) {
+ interceptors.add(interceptor);
+ }
+
+ /**
+ * Gets the name of the operation.
+ *
+ * @return Operation name.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name of the operation.
+ *
+ * @param name Operation name.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Checks whether the operation is a callback.
+ *
+ * @return True if this is a callback.
+ */
+ public boolean isCallback() {
+ return callback;
+ }
+
+ /**
+ * Sets whether this is a callback operation or not.
+ *
+ * @param callback True if this is a callback.
+ */
+ public void setCallback(boolean callback) {
+ this.callback = callback;
+ }
+
+
+ public int getConversationSequence() {
+ return conversationSequence;
+ }
+
+ public void setConversationSequence(int conversationSequence) {
+ this.conversationSequence = conversationSequence;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireDefinition.java
new file mode 100644
index 0000000000..b26c9ad736
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireDefinition.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.spi.model.physical;
+
+import java.net.URI;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * Model class representing the portable definition of a wire. This class is used to describe the inbound and outbound
+ * wires on a physical component definition.
+ *
+ * @version $Rev$ $Date$
+ */
+public class PhysicalWireDefinition extends ModelObject {
+
+ // Target definition
+ private PhysicalWireTargetDefinition target;
+
+ // Source definition
+ private PhysicalWireSourceDefinition source;
+
+ // Collection of operations
+ private Set<PhysicalOperationDefinition> operations = new HashSet<PhysicalOperationDefinition>();
+
+ /**
+ * Adds an operation definition.
+ *
+ * @param operation Operation to be added.
+ */
+ public void addOperation(PhysicalOperationDefinition operation) {
+ operations.add(operation);
+ }
+
+
+ /**
+ * Returns a read-only view of the available operations.
+ *
+ * @return Collection of operations.
+ */
+ public Set<PhysicalOperationDefinition> getOperations() {
+ return Collections.unmodifiableSet(operations);
+ }
+
+
+ /**
+ * Returns a read-only view of the available non callback operations.
+ *
+ * @return Collection of non-callback operations.
+ */
+ public Set<PhysicalOperationDefinition> getNonCallbackOperations() {
+ Set<PhysicalOperationDefinition> nonCallbackOperations = new HashSet<PhysicalOperationDefinition>();
+ for (PhysicalOperationDefinition operation : operations) {
+ if (!operation.isCallback()) {
+ nonCallbackOperations.add(operation);
+ }
+ }
+ return nonCallbackOperations;
+ }
+
+ /**
+ * Returns a read-only view of the available callback operations.
+ *
+ * @return Collection of callback operations.
+ */
+ public Set<PhysicalOperationDefinition> getCallbackOperations() {
+ Set<PhysicalOperationDefinition> callbackOperations = new HashSet<PhysicalOperationDefinition>();
+ for (PhysicalOperationDefinition operation : operations) {
+ if (operation.isCallback()) {
+ callbackOperations.add(operation);
+ }
+ }
+ return callbackOperations;
+ }
+
+ /**
+ * Gets the Wire source URI.
+ *
+ * @return Wire source URI.
+ */
+ public URI getSourceUri() {
+ return source.getUri();
+ }
+
+ /**
+ * Gets the Wire target URI.
+ *
+ * @return Wire target URI.
+ */
+ public URI getTargetUri() {
+ return target.getUri();
+ }
+
+ /**
+ * Gets the wire source.
+ *
+ * @return Wire source.
+ */
+ public PhysicalWireSourceDefinition getSource() {
+ return source;
+ }
+
+ /**
+ * Sets the wire source.
+ *
+ * @param source Wire source.
+ */
+ public void setSource(PhysicalWireSourceDefinition source) {
+ this.source = source;
+ }
+
+ /**
+ * Gets the wire target.
+ *
+ * @return Wire target.
+ */
+ public PhysicalWireTargetDefinition getTarget() {
+ return target;
+ }
+
+ /**
+ * Sets the wire target.
+ *
+ * @param target Wire target.
+ */
+ public void setTarget(PhysicalWireTargetDefinition target) {
+ this.target = target;
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireSourceDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireSourceDefinition.java
new file mode 100644
index 0000000000..12ec8e141d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireSourceDefinition.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.spi.model.physical;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * Represents a physical wire source definition.
+ *
+ * @version $Revision$ $Date$
+ */
+public class PhysicalWireSourceDefinition extends ModelObject {
+
+ // URI
+ private URI uri;
+ private URI callbackUri;
+ private boolean optimizable;
+ private boolean conversational;
+
+ /**
+ * Gets the URI.
+ *
+ * @return the URI.
+ */
+ public URI getUri() {
+ return uri;
+ }
+
+ /**
+ * Sets the URI.
+ *
+ * @param uri the URI.
+ */
+ public void setUri(URI uri) {
+ this.uri = uri;
+ }
+
+ /**
+ * Gets the callback URI.
+ *
+ * @return the callback URI.
+ */
+ public URI getCallbackUri() {
+ return callbackUri;
+ }
+
+ /**
+ * Sets the URI.
+ *
+ * @param uri the callback URI.
+ */
+ public void setCallbackUri(URI uri) {
+ this.callbackUri = uri;
+ }
+
+
+ /**
+ * Returns true if the wire may be optimized
+ *
+ * @return true if the wire may be optimized
+ */
+ public boolean isOptimizable() {
+ return optimizable;
+ }
+
+ /**
+ * Setting to true indicates the wire may be optimized
+ *
+ * @param optimizable if the wire can be optimized
+ */
+ public void setOptimizable(boolean optimizable) {
+ this.optimizable = optimizable;
+ }
+
+ public boolean isConversational() {
+ return conversational;
+ }
+
+ public void setConversational(boolean conversational) {
+ this.conversational = conversational;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireTargetDefinition.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireTargetDefinition.java
new file mode 100644
index 0000000000..e36ffde24a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/model/physical/PhysicalWireTargetDefinition.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.spi.model.physical;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * Represents a physical wire target definition.
+ *
+ * @version $Revision$ $Date$
+ */
+public class PhysicalWireTargetDefinition extends ModelObject {
+
+ // URI
+ private URI uri;
+
+ /**
+ * Gets the URI.
+ * @return Gets the URI.
+ */
+ public URI getUri() {
+ return uri;
+ }
+
+ /**
+ * Sets the URI.
+ * @param uri Sets the URI.
+ */
+ public void setUri(URI uri) {
+ this.uri = uri;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/package-info.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/package-info.java
new file mode 100644
index 0000000000..710c0984be
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Overview of Apache Tuscany SPI for extensions.
+ */
+package org.apache.tuscany.spi; \ No newline at end of file
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/IntentRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/IntentRegistry.java
new file mode 100644
index 0000000000..8517977f0d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/IntentRegistry.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.spi.policy;
+
+import java.util.Collection;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.model.Intent;
+import org.apache.tuscany.spi.model.IntentName;
+
+/**
+ * The registry for intents.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface IntentRegistry {
+
+ /**
+ * Register a intent.
+ *
+ * @param intent intent to register
+ */
+ void register(Intent intent);
+
+ /**
+ * Unregister a intent.
+ *
+ * @param intent intent to unregister
+ */
+ void unRegister(Intent intent);
+
+ /**
+ * Replace the profile intents in intentNameList with the real concrete intent.
+ *
+ * @param intentNameList intent list that may contains profile intents
+ * @param artifact QName of SCA artifact
+ * @return concrete intents list
+ */
+ Collection<IntentName> inlineProfileIntent(Collection<IntentName> intentNameList, QName artifact);
+
+ /**
+ * Whether the intent is appplicable for specified SCA artifact.
+ *
+ * @param intentName name of intent
+ * @param artifact QName of SCA artifact
+ * @return Whether the intent is appplicable for specified SCA artifact
+ */
+ boolean isApplicable(IntentName intentName, QName artifact);
+
+ /**
+ * Get a list including all qualified intents for a qulifiable intent.
+ *
+ * @param qualifiable qualifiable intent
+ * @param artifact QName of SCA artifact
+ * @return list including all qualified intents for a qulifiable intent.
+ */
+ Collection<IntentName> getQualifiedIntents(IntentName qualifiable, QName artifact);
+
+ /**
+ * Whether the intent is a qualified.
+ *
+ * @param name intent name.
+ * @return whether the intent is a qualified
+ */
+ boolean isQualifiedIntent(IntentName name);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/PolicyBuilderRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/PolicyBuilderRegistry.java
new file mode 100644
index 0000000000..c7f8016cfa
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/PolicyBuilderRegistry.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.spi.policy;
+
+/**
+ * A registry for policy builders that dispatches to the appropriate builder when converting an assembly to runtime
+ * artifacts. Policy builders operate on either a source- or target-side wires.
+ *
+ * @version $Rev$ $Date$
+ * @deprecated
+ */
+public interface PolicyBuilderRegistry {
+
+ int INITIAL = 0;
+ int EXTENSION = 1;
+ int FINAL = 2;
+
+ /**
+ * Registers a target-side policy builder. Called by extensions to register their builders.
+ *
+ * @param phase the phase hwne the builder must be run
+ * @param builder the builder to register
+ */
+ void registerTargetBuilder(int phase, TargetPolicyBuilder builder);
+
+ /**
+ * Registers a source-side policy builder. Called by extensions to register their builders.
+ *
+ * @param phase the phase hwne the builder must be run
+ * @param builder the builder to register
+ */
+ void registerSourceBuilder(int phase, SourcePolicyBuilder builder);
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/PolicyEngine.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/PolicyEngine.java
new file mode 100644
index 0000000000..fd4ba129d5
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/PolicyEngine.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.spi.policy;
+
+import java.util.Collection;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.model.IntentName;
+import org.apache.tuscany.spi.model.PolicyModel;
+
+/**
+ * Responsible for matching concrete policy artifacts required by abstract intent name.
+ */
+public interface PolicyEngine {
+
+ /**
+ * Retrieve policies which match the intents requirement on a SCA artifact. See SCA policy frame spec. 1.4.5 Guided
+ * Selection of PolicySets using Intents
+ *
+ * @param requires Intent names requred by the SCA artifact
+ * @param policySetName PolicySet names specify on the SCA artifact explicitly
+ * @param artifactType QName of SCA artifact type, which may be a abstract artifact type
+ * @return Collection contains all policy matching the intent requirement
+ */
+ Collection<PolicyModel> getPolicy(IntentName[] requires, QName[] policySetName, QName artifactType);
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/PolicySetContainer.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/PolicySetContainer.java
new file mode 100644
index 0000000000..f7a9e0922a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/PolicySetContainer.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.spi.policy;
+
+import java.util.Collection;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.model.PolicySet;
+
+/**
+ * The host for PolicySet.
+ */
+public interface PolicySetContainer {
+
+ /**
+ * Get all PolicySet of this container
+ *
+ * @return Collection contains all PolicySet of this container
+ */
+ Collection<PolicySet> getAllPolicySet();
+
+ /**
+ * Get PolicySet by name.
+ *
+ * @param name QName of PolicySet.
+ * @return PolicySet with specified name
+ */
+ PolicySet getPolicySet(QName name);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/SCATypeManager.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/SCATypeManager.java
new file mode 100644
index 0000000000..3a5127f014
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/SCATypeManager.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.spi.policy;
+
+import javax.xml.namespace.QName;
+
+public interface SCATypeManager {
+
+ /**
+ * Whether the <code>subType</code> is a sub type of <code>type</code> or the type itself.
+ */
+ boolean isTypeOf(QName subType, QName type);
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/SourcePolicyBuilder.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/SourcePolicyBuilder.java
new file mode 100644
index 0000000000..677ceaab30
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/SourcePolicyBuilder.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.spi.policy;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * Implementations contribute {@link org.apache.tuscany.spi.wire.Interceptor}s to handle source-side policy on a wire.
+ *
+ * @version $$Rev$$ $$Date$$
+ * @deprecated
+ */
+public interface SourcePolicyBuilder {
+
+ /**
+ * Callback for attaching policy to a source-side wire
+ *
+ * @param definition the service definition
+ * @param wire the wire to attach policy to
+ * @throws BuilderException
+ */
+ void build(ReferenceDefinition definition, Wire wire) throws BuilderException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/SourcePolicyBuilderExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/SourcePolicyBuilderExtension.java
new file mode 100644
index 0000000000..d577ae97bf
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/SourcePolicyBuilderExtension.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.spi.policy;
+
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * A runtime extension point for {@link SourcePolicyBuilder}s
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+public abstract class SourcePolicyBuilderExtension implements SourcePolicyBuilder {
+ protected int phase = PolicyBuilderRegistry.EXTENSION;
+ private PolicyBuilderRegistry registry;
+
+ @Reference
+ public void setRegistry(PolicyBuilderRegistry registry) {
+ this.registry = registry;
+ }
+
+ @Property
+ public void setPhase(int phase) {
+ this.phase = phase;
+ }
+
+ @Init
+ public void init() {
+ registry.registerSourceBuilder(phase, this);
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/TargetPolicyBuilder.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/TargetPolicyBuilder.java
new file mode 100644
index 0000000000..f26c7fc4ad
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/TargetPolicyBuilder.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.spi.policy;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.wire.Wire;
+
+/**
+ * Implementations contribute {@link org.apache.tuscany.spi.wire.Interceptor}s to handle target-side policy on a wire.
+ *
+ * @version $$Rev$$ $$Date$$
+ * @deprecated
+ */
+public interface TargetPolicyBuilder {
+
+ /**
+ * Callback for attaching policy to a target-side wire
+ *
+ * @param definition the service definition
+ * @param wire the wire to attach policy to
+ * @throws BuilderException
+ */
+ void build(ServiceDefinition definition, Wire wire) throws BuilderException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/TargetPolicyBuilderExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/TargetPolicyBuilderExtension.java
new file mode 100644
index 0000000000..3b01cd457f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/policy/TargetPolicyBuilderExtension.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.spi.policy;
+
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * A runtime extension point for {@link org.apache.tuscany.spi.policy.SourcePolicyBuilder}s
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+public abstract class TargetPolicyBuilderExtension implements TargetPolicyBuilder {
+ protected int phase = PolicyBuilderRegistry.EXTENSION;
+ private PolicyBuilderRegistry registry;
+
+ @Reference
+ public void setRegistry(PolicyBuilderRegistry registry) {
+ this.registry = registry;
+ }
+
+ @Property
+ public void setPhase(int phase) {
+ this.phase = phase;
+ }
+
+ @Init
+ public void init() {
+ registry.registerTargetBuilder(phase, this);
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/resolver/ResolutionException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/resolver/ResolutionException.java
new file mode 100644
index 0000000000..fd7394b6dd
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/resolver/ResolutionException.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.spi.resolver;
+
+import org.apache.tuscany.api.TuscanyException;
+
+/**
+ * Denotes an error during the resolve phase as an assembly is evaluated
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class ResolutionException extends TuscanyException {
+
+ public ResolutionException() {
+ }
+
+ public ResolutionException(String message) {
+ super(message);
+ }
+
+ public ResolutionException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public ResolutionException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ResolutionException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+
+ public ResolutionException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/resolver/Resolver.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/resolver/Resolver.java
new file mode 100644
index 0000000000..30ccfb2c2e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/resolver/Resolver.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.spi.resolver;
+
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * Implementations are responsible for resolving resources referenced by an assembly model object
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Resolver<T extends ModelObject> {
+
+ /**
+ * Processes a model object, resolving resources referenced by it
+ *
+ * @param registry the resolver registry to callback when processing sub-elements
+ * @param object the model object to process
+ * @throws ResolutionException
+ */
+ void resolve(ResolverRegistry registry, T object) throws ResolutionException;
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/resolver/ResolverRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/resolver/ResolverRegistry.java
new file mode 100644
index 0000000000..c0c7fdbbab
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/resolver/ResolverRegistry.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.spi.resolver;
+
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * Registry for resolvers that handle resolution of resources referenced by assembly model elements
+ * <p/>
+ * Resolvers are contributed by system extensions
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ResolverRegistry {
+ /**
+ * Register a resolver for a model type.
+ *
+ * @param modelClass the type model element the resolver handles
+ * @param resolver the resolver to be registered
+ */
+ <T extends ModelObject> void register(Class<T> modelClass, Resolver<T> resolver);
+
+ /**
+ * Unregister a resolver for a model type.
+ *
+ * @param modelClass the model type whose builder should be unregistered
+ */
+ <T extends ModelObject> void unregister(Class<T> modelClass);
+
+ /**
+ * Initiates the resolution process
+ *
+ * @param object the top-level element to resolve
+ */
+ <T extends ModelObject> void resolve(T object) throws ResolutionException;
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/VoidService.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/VoidService.java
new file mode 100644
index 0000000000..777cfbd3e9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/VoidService.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.spi.services;
+
+import org.osoa.sca.annotations.Service;
+
+/**
+ * Empty interface for a service component that has no operations.
+ * This can be used as a default service interface by components that
+ * do not wish the base class to be used as the interface as specified
+ * by the defaulting rules.
+ *
+ * @version $Rev$ $Date$
+ */
+@Service
+public interface VoidService {
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/artifact/Artifact.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/artifact/Artifact.java
new file mode 100644
index 0000000000..4da522d196
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/artifact/Artifact.java
@@ -0,0 +1,197 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.services.artifact;
+
+import java.net.URL;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Description of some packaged artifact such as a JAR file or a Composite.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Artifact {
+
+ /* Artifact group */
+ private String group;
+
+ /* Artifact name */
+ private String name;
+
+ /* Artifact version */
+ private String version;
+
+ /* Artifact classifier */
+ private String classifier;
+
+ /* Artifact type */
+ private String type;
+
+ /* Artifact url */
+ private URL url;
+
+ /* Transitive dependencies */
+ private Set<Artifact> dependencies = new HashSet<Artifact>();
+
+ /**
+ * Adds a transitive dependency to the artifact.
+ *
+ * @param artifact Dependency to be added.
+ */
+ public void addDependency(Artifact artifact) {
+ dependencies.add(artifact);
+ }
+
+ /**
+ * Gets the URLs for all the transitive dependencies.
+ *
+ * @return Sets of URLs for all the transitive dependencies.
+ */
+ public Set<URL> getUrls() {
+
+ Set<URL> urls = new HashSet<URL>();
+
+ for (Artifact artifact : dependencies) {
+ urls.add(artifact.getUrl());
+ }
+ urls.add(getUrl());
+
+ return urls;
+
+ }
+
+ /**
+ * Returns the name of a logical grouping to which this artifact belongs. For example, this might represent the
+ * original publisher of the artifact.
+ *
+ * @return the name of a logical grouping to which this artifact belongs
+ */
+ public String getGroup() {
+ return group;
+ }
+
+ /**
+ * Sets the name of a logical grouping to which this artifact belongs.
+ *
+ * @param group the name of a logical grouping to which this artifact belongs
+ */
+ public void setGroup(String group) {
+ this.group = group;
+ }
+
+ /**
+ * Returns the name of an artifact.
+ *
+ * @return the name of an artifact
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name of an artifact.
+ *
+ * @param name the name of an artifact
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns the version of an artifact.
+ *
+ * @return the version of an artifact
+ */
+ public String getVersion() {
+ return version;
+ }
+
+ /**
+ * Sets the version of an artifact.
+ *
+ * @param version the version of an artifact
+ */
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ /**
+ * Returns a way of classifying an artifact. This can be used to distinguish variants of an artifact that provide
+ * the same function but which may have platform specific requirements. For example, it may contain the name of a
+ * hardware platform for artifacts that contain native code.
+ *
+ * @return a way of classifying an artifact
+ */
+ public String getClassifier() {
+ return classifier;
+ }
+
+ /**
+ * Sets a way of classifying an artifact
+ *
+ * @param classifier a way of classifying an artifact
+ */
+ public void setClassifier(String classifier) {
+ this.classifier = classifier;
+ }
+
+ /**
+ * Returns the type of artifact.
+ *
+ * @return the type of artifact
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * Sets the type of artifact.
+ *
+ * @param type the type of artifact
+ */
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ /**
+ * Returns a URL from which the artifact can be obtained.
+ *
+ * @return a URL from which the artifact can be obtained
+ */
+ public URL getUrl() {
+ return url;
+ }
+
+ /**
+ * Sets a URL from which the artifact can be obtained.
+ *
+ * @param url a URL from which the artifact can be obtained
+ */
+ public void setUrl(URL url) {
+ this.url = url;
+ }
+
+
+ public String toString() {
+ StringBuilder buf = new StringBuilder();
+ buf.append(group).append(':').append(name).append(':').append(version).append(':').append(type);
+ return buf.toString();
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/artifact/ArtifactRepository.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/artifact/ArtifactRepository.java
new file mode 100644
index 0000000000..b0f590e163
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/artifact/ArtifactRepository.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.spi.services.artifact;
+
+import java.util.Collection;
+
+/**
+ * Abstraction for a repository of SCA and other artifacts.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ArtifactRepository {
+ /**
+ * Resolve an artifact.
+ * This ensures that the information associated with an artifact is fully populated;
+ * Specifically, after this operation the URL should contain a location where the artifact can be obtained.
+ *
+ * @param artifact the artifact to be resolved
+ */
+ void resolve(Artifact artifact);
+
+ /**
+ * Resolve a collection of Artifacts.
+ *
+ * @param artifacts a collection of artifacts to be resolved
+ * @see #resolve(Artifact)
+ */
+ void resolve(Collection<? extends Artifact> artifacts);
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/classloading/ClassLoaderRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/classloading/ClassLoaderRegistry.java
new file mode 100644
index 0000000000..f74d66268b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/classloading/ClassLoaderRegistry.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.spi.services.classloading;
+
+import java.net.URI;
+
+/**
+ * Registry for classloaders available to the local runtime.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ClassLoaderRegistry {
+ /**
+ * Register a ClassLoader with the runtime.
+ *
+ * @param id a unique id for the classloader
+ * @param classLoader the classloader to register
+ * @throws DuplicateClassLoaderException if there is already a classloader registered with the same id
+ */
+ void register(URI id, ClassLoader classLoader) throws DuplicateClassLoaderException;
+
+ /**
+ * Returns the classloader registered with the supplied id, or null if none is registered.
+ *
+ * @param id the id for the classloader
+ * @return the ClassLoader registered with that id, or null
+ */
+ ClassLoader getClassLoader(URI id);
+
+ /**
+ * Unregister the specified classloader from the system.
+ *
+ * @param id the id for the classloader
+ * @return the classloader that was registed with the id, or null if none
+ */
+ ClassLoader unregister(URI id);
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/classloading/DuplicateClassLoaderException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/classloading/DuplicateClassLoaderException.java
new file mode 100644
index 0000000000..77cc836811
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/classloading/DuplicateClassLoaderException.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.spi.services.classloading;
+
+import org.apache.tuscany.spi.CoreRuntimeException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DuplicateClassLoaderException extends CoreRuntimeException {
+ /**
+ * Constructor specifying message and the ID of the duplicate classloader.
+ *
+ * @param message exception message
+ * @param identifier the id of the classloader that is already present
+ */
+ public DuplicateClassLoaderException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/AbstractDiscoveryService.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/AbstractDiscoveryService.java
new file mode 100644
index 0000000000..c42493340f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/AbstractDiscoveryService.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.services.discovery;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.host.RuntimeInfo;
+
+/**
+ * Abstract implementation of the discovery service.
+ *
+ * @version $Revision$ $Date$
+ */
+@EagerInit
+public abstract class AbstractDiscoveryService implements DiscoveryService {
+
+ /**
+ * Runtime info.
+ */
+ private RuntimeInfo runtimeInfo;
+
+ /**
+ * Request listeners.
+ */
+ private Map<QName, RequestListener> requestListenerMap = new ConcurrentHashMap<QName, RequestListener>();
+
+ /**
+ * Response listeners.
+ */
+ private Map<QName, ResponseListener> responseListenerMap = new ConcurrentHashMap<QName, ResponseListener>();
+
+ /**
+ * Registers a request listener for async messages.
+ *
+ * @param messageType Message type that can be handled by the listener.
+ * @param listener Recipient of the async message.
+ */
+ public void registerRequestListener(QName messageType, RequestListener listener) {
+ requestListenerMap.put(messageType, listener);
+ }
+
+ /**
+ * Registers a response listener for async messages.
+ *
+ * @param messageType Message type that can be handled by the listener.
+ * @param listener Recipient of the async message.
+ */
+ public void registerResponseListener(QName messageType, ResponseListener listener) {
+ responseListenerMap.put(messageType, listener);
+ }
+
+ /**
+ * Sets the runtime info for the runtime using the discovery service.
+ *
+ * @param runtimeInfo Runtime info for the runtime using the discovery service.
+ */
+ @Reference
+ public final void setRuntimeInfo(RuntimeInfo runtimeInfo) {
+ this.runtimeInfo = runtimeInfo;
+ }
+
+ /**
+ * Starts the discovery service.
+ */
+ @Init
+ public final void start() throws DiscoveryException {
+ onStart();
+ }
+
+ /**
+ * Stops the discovery service.
+ */
+ @Destroy
+ public final void stop() throws DiscoveryException {
+ onStop();
+ }
+
+ /**
+ * Gets the runtime info for the runtime using the discovery service.
+ *
+ * @return Runtime info for the runtime using the discovery service.
+ */
+ protected final RuntimeInfo getRuntimeInfo() {
+ return runtimeInfo;
+ }
+
+ /**
+ * Returns the request listener for the specified message type.
+ *
+ * @param messageType Message type for the incoming message.
+ * @return Listener interested in the message type.
+ */
+ public final RequestListener getRequestListener(QName messageType) {
+ return requestListenerMap.get(messageType);
+ }
+
+ /**
+ * Returns the request listener for the specified message type.
+ *
+ * @param messageType Message type for the incoming message.
+ * @return Listener interested in the message type.
+ */
+ public final ResponseListener getResponseListener(QName messageType) {
+ return responseListenerMap.get(messageType);
+ }
+
+ /**
+ * Broadcasts the messages to all runtimes in the domain.
+ *
+ * @param content Message content.
+ * @return The message id.
+ * @throws DiscoveryException In case of discovery errors.
+ */
+ public int broadcastMessage(XMLStreamReader content) throws DiscoveryException {
+ return sendMessage(null, content);
+ }
+
+ /**
+ * Required to be overridden by sub-classes.
+ */
+ protected abstract void onStart() throws DiscoveryException;
+
+ /**
+ * Required to be overridden by sub-classes.
+ */
+ protected abstract void onStop() throws DiscoveryException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/DiscoveryException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/DiscoveryException.java
new file mode 100644
index 0000000000..f093321e26
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/DiscoveryException.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.spi.services.discovery;
+
+import org.apache.tuscany.api.TuscanyException;
+
+/**
+ * Checked exception thrown during discovery operations.
+ *
+ * @version $Revision$ $Date$
+ */
+@SuppressWarnings("serial")
+public class DiscoveryException extends TuscanyException {
+
+ /**
+ * Initialises the exception message.
+ *
+ * @param message Message for the exception.
+ */
+ public DiscoveryException(String message) {
+ super(message);
+ }
+
+ /**
+ * Initialises the exception root cause.
+ *
+ * @param cause Root cause for the exception.
+ */
+ public DiscoveryException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/DiscoveryService.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/DiscoveryService.java
new file mode 100644
index 0000000000..5c0a518323
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/DiscoveryService.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.spi.services.discovery;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * Defines the abstraction that allows runtimes participating
+ * in the domain to discover each other and broadcast liveness
+ * to the admin server that holds the domain's runtime physical
+ * model and the domain-wide assembly model..
+ *
+ * @version $Revision$ $Date$
+ *
+ */
+public interface DiscoveryService {
+
+ /**
+ * Sends a message to the specified runtime. The method returns a unique
+ * message id for the sent message. The consumers can use the message id for
+ * correlating responses to sent messages.
+ *
+ * @param runtimeId Runtime id of recipient.
+ * @param content Message content.
+ * @return The message id.
+ * @throws DiscoveryException In case of discovery errors.
+ */
+ int sendMessage(String runtimeId, XMLStreamReader content) throws DiscoveryException;
+
+ /**
+ * Broadcasts the messages to all runtimes in the domain.
+ *
+ * @param content Message content.
+ * @return The message id.
+ * @throws DiscoveryException In case of discovery errors.
+ */
+ int broadcastMessage(XMLStreamReader content) throws DiscoveryException;
+
+ /**
+ * Registers a request listener for async messages. Request listeners handle
+ * unslolicited async messages sent by recipients.
+ *
+ * @param messageType Message type that can be handled by the listener.
+ * @param listener Recipient of the async message.
+ */
+ void registerRequestListener(QName messageType, RequestListener listener);
+
+ /**
+ * Registers a response listener for async messages. Response listeners handle
+ * async meesages that are received in response to a request message that was
+ * originally sent.
+ *
+ * @param messageType Message type that can be handled by the listener.
+ * @param listener Recipient of the async message.
+ */
+ void registerResponseListener(QName messageType, ResponseListener listener);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/RequestListener.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/RequestListener.java
new file mode 100644
index 0000000000..8729757a6b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/RequestListener.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.spi.services.discovery;
+
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * Message listener for propogating callbacks. Request listeners handle
+ * unslolicited async messages sent by recipients.
+ *
+ * @version $Revision$ $Date$
+ *
+ */
+public interface RequestListener {
+
+ /**
+ * Callback for propogating async messages.
+ * @param content Message content.
+ * @return Response to the request message.
+ */
+ XMLStreamReader onRequest(XMLStreamReader content);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/ResponseListener.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/ResponseListener.java
new file mode 100644
index 0000000000..88411ac660
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/discovery/ResponseListener.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.spi.services.discovery;
+
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * Message listener for propogating callbacks. Response listeners handle async meesages that are received in response to
+ * a request message that was originally sent.
+ *
+ * @version $Revision$ $Date$
+ */
+public interface ResponseListener {
+
+ /**
+ * Callback for propogating async messages.
+ *
+ * @param content Message content.
+ * @param messageId optional message id if this was in response to a message that was sent.
+ */
+ void onResponse(XMLStreamReader content, int messageId);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/management/TuscanyManagementService.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/management/TuscanyManagementService.java
new file mode 100644
index 0000000000..10c2215bf6
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/management/TuscanyManagementService.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.spi.services.management;
+
+import org.apache.tuscany.host.management.ManagementService;
+import org.apache.tuscany.spi.component.Component;
+
+/**
+ * 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 TuscanyManagementService extends ManagementService<Component> {
+
+ /**
+ * Registers a component for management.
+ *
+ * @param name Name of the component.
+ * @param component Component to be registered.
+ */
+ void registerComponent(String name, Component component);
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/DuplicateRecordException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/DuplicateRecordException.java
new file mode 100644
index 0000000000..1210d05f5a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/DuplicateRecordException.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.spi.services.store;
+
+/**
+ * thrown when a record already exists during an insert operation
+ *
+ * @version $Rev$ $Date$
+ */
+public class DuplicateRecordException extends StoreWriteException {
+
+ public DuplicateRecordException(String owner, String identifier) {
+ super(null, owner, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/RecoveryListener.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/RecoveryListener.java
new file mode 100644
index 0000000000..186d741c04
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/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.spi.services.store;
+
+import java.util.UUID;
+
+/**
+ * Implementations receive callback events during a store recovery operation
+ *
+ * @version $Rev$ $Date$
+ */
+public interface RecoveryListener {
+
+ /**
+ * Signals the start of a recovery
+ */
+ void onBegin();
+
+ /**
+ * Received when a record is recovered
+ *
+ * @param id
+ */
+ void onRecord(UUID id);
+
+ /**
+ * Signals the end of recovery
+ */
+ void onEnd();
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/Store.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/Store.java
new file mode 100644
index 0000000000..7a09f90811
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/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.spi.services.store;
+
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.event.EventPublisher;
+
+/**
+ * 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(SCAObject 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(SCAObject 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(SCAObject 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(SCAObject owner, String id) throws StoreWriteException;
+
+ /**
+ * Removes all records from the store
+ *
+ * @throws StoreWriteException
+ */
+ void removeRecords() throws StoreWriteException;
+
+ /**
+ * Initiates a recovery operation, for example during restart after a crash
+ *
+ * @param listener the listener to receive recovery callback events
+ * @throws StoreReadException
+ */
+ void recover(RecoveryListener listener) throws StoreReadException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreException.java
new file mode 100644
index 0000000000..59f1797490
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreException.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.spi.services.store;
+
+import org.apache.tuscany.api.TuscanyException;
+
+/**
+ * Represents a generic exception thrown by a <code>Store</code>
+ *
+ * @version $Rev$ $Date$
+ */
+public class StoreException extends TuscanyException {
+ private final String owner;
+
+ public StoreException(String message, String owner, String identifier) {
+ super(message, identifier);
+ this.owner = owner;
+ }
+
+ public StoreException(String message, String owner, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ this.owner = owner;
+ }
+
+ public StoreException(String message, String owner, Throwable cause) {
+ super(message, cause);
+ this.owner = owner;
+ }
+
+ public StoreException(Throwable cause) {
+ super(cause);
+ owner = null;
+ }
+
+ public String getOwner() {
+ return owner;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreExpirationEvent.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreExpirationEvent.java
new file mode 100644
index 0000000000..fbb38dd362
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/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.spi.services.store;
+
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.event.Event;
+
+/**
+ * Fired when a store implementation expires a resource
+ *
+ * @version $Rev$ $Date$
+ */
+public class StoreExpirationEvent implements Event {
+ private Object source;
+ private SCAObject 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, SCAObject 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 SCAObject getOwner() {
+ return owner;
+ }
+
+ /**
+ * Returns the expiring object.
+ *
+ * @return the expiring object.
+ */
+ public Object getInstance() {
+ return instance;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreMonitor.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreMonitor.java
new file mode 100644
index 0000000000..f3bbbf0b73
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreMonitor.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.spi.services.store;
+
+import org.apache.tuscany.api.annotation.LogLevel;
+
+/**
+ * A generic monintor interface for services to log events
+ *
+ * @version $Rev$ $Date$
+ */
+public interface StoreMonitor {
+
+ /**
+ * Signals the service has started
+ *
+ * @param msg
+ */
+ @LogLevel("DEBUG")
+ void start(String msg);
+
+ /**
+ * Signals the service has been shutdown
+ *
+ * @param msg
+ */
+ @LogLevel("DEBUG")
+ void stop(String msg);
+
+ /**
+ * Fired when recovery is started
+ */
+ @LogLevel("DEBUG")
+ void beginRecover();
+
+ /**
+ * Fired when recovery is completed
+ */
+ @LogLevel("DEBUG")
+ void endRecover();
+
+ /**
+ * Fired when a record is processed during recovery
+ *
+ * @param recordId the id of the record being recovered
+ */
+ @LogLevel("DEBUG")
+ void recover(Object recordId);
+
+ /**
+ * Signals an error event
+ *
+ * @param e the error
+ */
+ @LogLevel("ERROR")
+ void error(Throwable e);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreReadException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreReadException.java
new file mode 100644
index 0000000000..0f46ac6878
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreReadException.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.spi.services.store;
+
+/**
+ * Thrown when an error occurs reading from persistent storage
+ *
+ * @version $Rev$ $Date$
+ */
+public class StoreReadException extends StoreException {
+
+ public StoreReadException(Throwable cause) {
+ super(cause);
+ }
+
+ public StoreReadException(String message, String owner, String identifier) {
+ super(message, owner, identifier);
+ }
+
+ public StoreReadException(String owner, String identifier, Throwable throwable) {
+ super(owner, identifier, throwable);
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreWriteException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreWriteException.java
new file mode 100644
index 0000000000..9eef91db9a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/store/StoreWriteException.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.spi.services.store;
+
+/**
+ * Thrown when an error occurs writing to persistent storage
+ *
+ * @version $Rev$ $Date$
+ */
+public class StoreWriteException extends StoreException {
+
+ public StoreWriteException(String message, String owner, String identifier) {
+ super(message, owner, identifier);
+ }
+
+ public StoreWriteException(String message, String owner, String identifier, Throwable cause) {
+ super(message, owner, identifier, cause);
+ }
+
+ public StoreWriteException(String message, String owner, Throwable cause) {
+ super(message, owner, cause);
+ }
+
+ public StoreWriteException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/NotificationListener.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/NotificationListener.java
new file mode 100644
index 0000000000..9675cdce53
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/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.spi.services.work;
+
+/**
+ * A callback inyterface that can be optionally used for registering
+ * interest in status of asynchronously scheduled unit of work.
+ *
+ */
+public interface NotificationListener<T extends Runnable> {
+
+ /**
+ * Callback method when the unit of work is accepted.
+ *
+ * @param work Work that was accepted.
+ */
+ void workAccepted(T work);
+
+ /**
+ * Callback method when the unit of work is successfully completed.
+ *
+ * @param work Work that was succesfully completed.
+ */
+ void workCompleted(T work);
+
+ /**
+ * Callback when the unit of work is started.
+ *
+ * @param work Unit of work that was started.
+ */
+ void workStarted(T work);
+
+ /**
+ * Callback when the unit of work is rejected.
+ *
+ * @param work Unit of work that was rejected.
+ */
+ void workRejected(T work);
+
+ /**
+ * Callnack when the unit of work fails to complete.
+ *
+ * @param work Unit of work that failed to complete.
+ * @param error Error that caused the unit of work to fail.
+ */
+ void workFailed(T work, Throwable error);
+
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/NotificationListenerAdaptor.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/NotificationListenerAdaptor.java
new file mode 100644
index 0000000000..8192f9db1d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/NotificationListenerAdaptor.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.spi.services.work;
+
+/**
+ * Adaptor class for the notification listsner.
+ *
+ * @version $Revision$ $Date$
+ *
+ */
+public class NotificationListenerAdaptor<T extends Runnable> implements NotificationListener<T> {
+
+ /**
+ * Callback method when the unit of work is accepted.
+ *
+ * @param work Work that was accepted.
+ */
+ public void workAccepted(T work) {
+ }
+
+ /**
+ * Callback method when the unit of work is successfully completed.
+ *
+ * @param work Work that was succesfully completed.
+ */
+ public void workCompleted(T work) {
+ }
+
+ /**
+ * Callback when the unit of work is started.
+ *
+ * @param work Unit of work that was started.
+ */
+ public void workStarted(T work) {
+ }
+
+ /**
+ * Callback when the unit of work is rejected.
+ *
+ * @param work Unit of work that was rejected.
+ */
+ public 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.
+ */
+ public void workFailed(T work, Throwable error) {
+ error.printStackTrace();
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/WorkScheduler.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/WorkScheduler.java
new file mode 100644
index 0000000000..0824990c93
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/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.spi.services.work;
+
+/**
+ * Defines the contract for scheduling asychronous units of work.
+ *
+ * <p>
+ * Units of work can be scheduled with an optional <code>NotificationListener</code>.
+ * 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.
+ * </p>
+ *
+ */
+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.
+ */
+ <T extends Runnable>void scheduleWork(T work, NotificationListener<T> 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.
+ */
+ <T extends Runnable>void scheduleWork(T work);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/WorkSchedulerException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/WorkSchedulerException.java
new file mode 100644
index 0000000000..d13edab6a7
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/services/work/WorkSchedulerException.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.spi.services.work;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * Exception thrown by the work scheduler in case of unexpected exceptions.
+ *
+ * @version $Rev$ $Date$
+ *
+ */
+@SuppressWarnings("serial")
+public class WorkSchedulerException extends TuscanyRuntimeException {
+
+ /**
+ * Wraps the root cause.
+ *
+ * @param cause Root cause for the exception.
+ */
+ public WorkSchedulerException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/util/UriHelper.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/util/UriHelper.java
new file mode 100644
index 0000000000..07067a59cf
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/util/UriHelper.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.spi.util;
+
+import java.net.URI;
+
+/**
+ * Utility methods for handling URIs
+ *
+ * @version $Rev$ $Date$
+ */
+public final class UriHelper {
+
+ private UriHelper() {
+ }
+
+ /**
+ * Returns the base name for a component URI, e.g. 'Bar' for 'sca://foo/Bar'
+ *
+ * @param uri the URI to parse
+ * @return the base name
+ */
+ public static String getBaseName(URI uri) {
+ String s = uri.toString();
+ int pos = s.lastIndexOf('/');
+ if (pos > -1) {
+ return s.substring(pos + 1);
+ } else {
+ return s;
+ }
+ }
+
+ public static URI getDefragmentedName(URI uri) {
+ if (uri.getFragment() == null) {
+ return uri;
+ }
+ String s = uri.toString();
+ int pos = s.lastIndexOf('#');
+ return URI.create(s.substring(0, pos));
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/util/stax/StaxUtil.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/util/stax/StaxUtil.java
new file mode 100644
index 0000000000..9b99c78ab2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/util/stax/StaxUtil.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.spi.util.stax;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * Utility for stax operations.
+ *
+ * @version $Revision$ $Date$
+ */
+public abstract class StaxUtil {
+
+ /**
+ * XML input factory.
+ */
+ private static final XMLInputFactory XML_FACTORY =
+ XMLInputFactory.newInstance("javax.xml.stream.XMLInputFactory", StaxUtil.class.getClassLoader());
+
+ private StaxUtil() {
+ }
+
+ /**
+ * Serializes the infoset in the stream reader.
+ *
+ * @param reader Stream reader.
+ * @return Serialized XML.
+ * @throws XMLStreamException In case of an xml stream error.
+ */
+ public static String serialize(XMLStreamReader reader) throws XMLStreamException {
+
+ try {
+
+ StringBuffer xml = new StringBuffer();
+
+ int event = reader.getEventType();
+ while (true) {
+
+ switch (event) {
+ case XMLStreamConstants.START_ELEMENT:
+ onStartElement(reader, xml);
+ onNsMappings(reader, xml);
+ onAttributes(reader, xml);
+ xml.append(">");
+ break;
+ case XMLStreamConstants.CHARACTERS:
+ if (reader.isWhiteSpace()) {
+ break;
+ }
+ xml.append(reader.getText());
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ onEndElement(reader, xml);
+ break;
+ }
+
+ if (!reader.hasNext()) {
+ break;
+ }
+ event = reader.next();
+
+ }
+ return xml.toString();
+
+ } finally {
+ reader.close();
+ }
+
+ }
+
+ /**
+ * Creates a stream reader to the serialized XML.
+ *
+ * @param xml Serialized XML to which reader is to be created.
+ * @return XML stream reader instance.
+ * @throws XMLStreamException In case of an xml stream error.
+ */
+ public static XMLStreamReader createReader(String xml) throws XMLStreamException {
+
+ InputStream in = new ByteArrayInputStream(xml.getBytes());
+ return XML_FACTORY.createXMLStreamReader(in);
+
+ }
+
+ /**
+ * Creates a stream reader to the serialized XML.
+ *
+ * @param xml XML stream to which reader is to be created.
+ * @return XML stream reader instance.
+ * @throws XMLStreamException In case of an xml stream error.
+ */
+ public static XMLStreamReader createReader(InputStream xml) throws XMLStreamException {
+
+ return XML_FACTORY.createXMLStreamReader(xml);
+
+ }
+
+ /**
+ * Returns the qualified name of the document element.
+ *
+ * @param xml Serialized xml that needs to be checked.
+ * @return Qualified name of the document element.
+ * @throws XMLStreamException In case of an xml stream error.
+ */
+ public static QName getDocumentElementQName(String xml) throws XMLStreamException {
+
+ XMLStreamReader reader = null;
+ try {
+ reader = createReader(xml);
+ reader.next();
+ return reader.getName();
+ } finally {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+
+ }
+
+ /*
+ * Renders end element markup.
+ */
+ private static void onEndElement(XMLStreamReader reader, StringBuffer xml) {
+ String name = getName(reader);
+ xml.append("</");
+ xml.append(name);
+ xml.append(">");
+ }
+
+ /*
+ * Gets the fully-qualified name of the element.
+ */
+ private static String getName(XMLStreamReader reader) {
+ QName qname = reader.getName();
+ String namePrefix = qname.getPrefix();
+ String localPart = qname.getLocalPart();
+ return namePrefix == null || "".equals(namePrefix) ? localPart : namePrefix + ":" + localPart;
+ }
+
+ /*
+ * Render the attributes.
+ */
+ private static void onAttributes(XMLStreamReader reader, StringBuffer xml) {
+ int n = reader.getAttributeCount();
+ for (int i = 0; i < n; ++i) {
+ xml.append(' ');
+ xml.append(reader.getAttributeLocalName(i));
+ xml.append('=');
+ xml.append('\'');
+ xml.append(reader.getAttributeValue(i));
+ xml.append('\'');
+ }
+ }
+
+ /*
+ * Renedr namespace mappings.
+ */
+ private static void onNsMappings(XMLStreamReader reader, StringBuffer xml) {
+ int n = reader.getNamespaceCount();
+ for (int i = 0; i < n; ++i) {
+ String prefix = reader.getNamespacePrefix(i);
+ xml.append(" xmlns");
+ if (prefix != null) {
+ xml.append(':').append(prefix);
+ }
+ xml.append('=');
+ xml.append('\'');
+ xml.append(reader.getNamespaceURI(i));
+ xml.append('\'');
+ }
+ }
+
+ /*
+ * Render start element.
+ */
+ private static void onStartElement(XMLStreamReader reader, StringBuffer xml) {
+ xml.append("<");
+ String name = getName(reader);
+ xml.append(name);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/AbstractInvocationHandler.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/AbstractInvocationHandler.java
new file mode 100644
index 0000000000..7ad42cf41d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/AbstractInvocationHandler.java
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.wire;
+
+import java.lang.reflect.InvocationTargetException;
+import java.net.URI;
+import java.util.LinkedList;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.component.WorkContext;
+
+/**
+ * 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;
+
+ protected AbstractInvocationHandler(boolean conversational) {
+ this.conversational = conversational;
+ }
+
+ public AbstractInvocationHandler() {
+ }
+
+ @Deprecated
+ protected Object invoke(InvocationChain chain,
+ TargetInvoker invoker,
+ Object[] args,
+ Object correlationId,
+ LinkedList<URI> callbackUris, WorkContext workContext)
+ throws Throwable {
+ Interceptor headInterceptor = chain.getHeadInterceptor();
+ if (headInterceptor == null) {
+ try {
+ // short-circuit the dispatch and invoke the target directly
+ TargetInvoker targetInvoker = chain.getTargetInvoker();
+ if (targetInvoker == null) {
+ String name = chain.getOperation().getName();
+ throw new AssertionError("No target invoker [" + name + "]");
+ }
+ return targetInvoker.invokeTarget(args, TargetInvoker.NONE, workContext);
+ } catch (InvocationTargetException e) {
+ // the cause was thrown by the target so throw it
+ throw e.getCause();
+ }
+ } else {
+ Message msg = new MessageImpl();
+ msg.setWorkContext(workContext);
+ msg.setTargetInvoker(invoker);
+ msg.setCorrelationId(workContext.getCorrelationId());
+ msg.setCallbackUris(workContext.getCallbackUris());
+ Operation operation = chain.getOperation();
+ ServiceContract contract = operation.getServiceContract();
+ if (contract.isConversational()) {
+ int sequence = chain.getOperation().getConversationSequence();
+ if (sequence == Operation.CONVERSATION_END) {
+ msg.setConversationSequence(TargetInvoker.END);
+ conversationStarted = false;
+ } else if (sequence == Operation.CONVERSATION_CONTINUE) {
+ if (conversationStarted) {
+ msg.setConversationSequence(TargetInvoker.CONTINUE);
+ } else {
+ conversationStarted = true;
+ msg.setConversationSequence(TargetInvoker.START);
+ }
+ }
+ }
+ msg.setBody(args);
+ // dispatch the wire down the chain and get the response
+ Message resp = headInterceptor.invoke(msg);
+ Object body = resp.getBody();
+ if (resp.isFault()) {
+ throw (Throwable) body;
+ }
+ return body;
+ }
+ }
+
+ protected Object invokeTarget(InvocationChain chain,
+ Object[] args,
+ Object correlationId,
+ LinkedList<Wire> callbackWires)
+ throws Throwable {
+ Interceptor headInterceptor = chain.getHeadInterceptor();
+ assert headInterceptor != null;
+ Message msg = new MessageImpl();
+ if (correlationId != null) {
+ msg.setCorrelationId(correlationId);
+ }
+ if (callbackWires != null) {
+ msg.setCallbackWires(callbackWires);
+ }
+ PhysicalOperationDefinition operation = chain.getPhysicalOperation();
+ if (conversational) {
+ int sequence = operation.getConversationSequence();
+ if (sequence == Operation.CONVERSATION_END) {
+ msg.setConversationSequence(TargetInvoker.END);
+ conversationStarted = false;
+ } else if (sequence == Operation.CONVERSATION_CONTINUE) {
+ if (conversationStarted) {
+ msg.setConversationSequence(TargetInvoker.CONTINUE);
+ } else {
+ conversationStarted = true;
+ msg.setConversationSequence(TargetInvoker.START);
+ }
+ }
+ }
+ msg.setBody(args);
+ // dispatch the wire down the chain and get the response
+ Message resp = headInterceptor.invoke(msg);
+ Object body = resp.getBody();
+ if (resp.isFault()) {
+ throw (Throwable) body;
+ }
+ return body;
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ChainHolder.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ChainHolder.java
new file mode 100644
index 0000000000..817599225e
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ChainHolder.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.spi.wire;
+
+/**
+ * A holder used to associate an wire chain with a local copy of a target invoker that was previously cloned from the
+ * chain master
+ *
+ * @version $Rev$ $Date$
+ */
+public class ChainHolder implements Cloneable {
+ InvocationChain chain;
+ TargetInvoker cachedInvoker;
+
+ public ChainHolder(InvocationChain config) {
+ this.chain = config;
+ }
+
+ public InvocationChain getChain() {
+ return chain;
+ }
+
+ public TargetInvoker getCachedInvoker() {
+ return cachedInvoker;
+ }
+
+ public void setCachedInvoker(TargetInvoker invoker) {
+ this.cachedInvoker = invoker;
+ }
+
+ @SuppressWarnings({"CloneDoesntDeclareCloneNotSupportedException"})
+ @Override
+ public ChainHolder clone() {
+ try {
+ return (ChainHolder) super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new AssertionError();
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/IncompatibleServiceContractException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/IncompatibleServiceContractException.java
new file mode 100644
index 0000000000..114df5a55c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/IncompatibleServiceContractException.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.spi.wire;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+import org.apache.tuscany.api.TuscanyException;
+
+/**
+ * Denotes imcompatible service contracts for a wire
+ *
+ * @version $Rev$ $Date$
+ */
+public class IncompatibleServiceContractException extends TuscanyException {
+ private static final long serialVersionUID = 5127478601823295587L;
+ private final ServiceContract<?> source;
+ private final ServiceContract<?> target;
+ private final Operation<?> sourceOperation;
+ private final Operation<?> targetOperation;
+
+ public IncompatibleServiceContractException(String message, ServiceContract<?> source, ServiceContract<?> target) {
+ super(message, (String) null);
+ this.source = source;
+ this.target = target;
+ this.sourceOperation = null;
+ this.targetOperation = null;
+ }
+
+
+ public IncompatibleServiceContractException(String message,
+ ServiceContract<?> source,
+ ServiceContract<?> target,
+ Operation<?> sourceOperation, Operation<?> targetOperation) {
+ super(message, (String) null);
+ this.source = source;
+ this.target = target;
+ this.sourceOperation = sourceOperation;
+ this.targetOperation = targetOperation;
+ }
+
+ public ServiceContract<?> getTarget() {
+ return target;
+ }
+
+ public ServiceContract<?> getSource() {
+ return source;
+ }
+
+ public Operation<?> getSourceOperation() {
+ return sourceOperation;
+ }
+
+ public Operation<?> getTargetOperation() {
+ return targetOperation;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Interceptor.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Interceptor.java
new file mode 100644
index 0000000000..ad38ed1cf1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Interceptor.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.spi.wire;
+
+/**
+ * Synchronous, around-style mediation associated with a client- or target- side wire.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Interceptor {
+
+ /**
+ * Process a synchronous wire
+ *
+ * @param msg the request Message for the wire
+ * @return the response Message from the wire
+ */
+ Message invoke(Message msg);
+
+ /**
+ * Sets the next interceptor
+ */
+ void setNext(Interceptor next);
+
+ /**
+ * Returns the next interceptor or null
+ */
+ Interceptor getNext();
+
+ /**
+ * Returns true if the interceptor can be optimized away from a wire
+ */
+ boolean isOptimizable();
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/InvocationChain.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/InvocationChain.java
new file mode 100644
index 0000000000..c034cf6e86
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/InvocationChain.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.spi.wire;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+
+/**
+ * A wire consists of 1..n invocation chains associated with the operations of its source service contract.
+ * <p/>
+ * Invocation chains may contain </ode>Interceptors</code> that process invocations in an around-style manner.
+ * Invocation chains are also associated with a <code>TargetInvoker</code> which is responsible for dispatching on the
+ * target service provider.
+ * <p/>
+ * A <code>Message</code> is used to pass data associated with an invocation through the chain. The TargetInvoker is
+ * passed with the Message through the interceptor stack, if one is present. At last interceptor in the stack, must call
+ * the TargetInvoker.
+ * <p/>
+ * In certain circumstances, the TargetInvoker may be cached in the source-side proxy. Caching allows various
+ * optimizations such as avoiding target instance resolution when the client-side lifecycle scope is a shorter duration
+ * than the target.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface InvocationChain {
+ /**
+ * Returns the target operation for this invocation chain.
+ *
+ * @return the target operation for this invocation chain
+ */
+ Operation getOperation();
+
+ /**
+ * Returns the target physical operation for this invocation chain.
+ *
+ * @return the target physical operation for this invocation chain
+ */
+ PhysicalOperationDefinition getPhysicalOperation();
+
+ /**
+ * Sets the target invoker to pass down the chain
+ *
+ * @param invoker the invoker
+ */
+ void setTargetInvoker(TargetInvoker invoker);
+
+ /**
+ * Returns the target invoker that is passed down the chain
+ *
+ * @return the target invoker
+ */
+ TargetInvoker getTargetInvoker();
+
+ /**
+ * Adds an interceptor to the chain
+ *
+ * @param interceptor the interceptor to add
+ */
+ void addInterceptor(Interceptor interceptor);
+
+ /**
+ * Adds an interceptor at the given position in the interceptor stack
+ *
+ * @param index the position in the interceptor stack to add the interceptor
+ * @param interceptor the interceptor to add
+ */
+ void addInterceptor(int index, Interceptor interceptor);
+
+ /**
+ * Returns the first interceptor in the chain.
+ *
+ * @return the first interceptor in the chain
+ */
+ Interceptor getHeadInterceptor();
+
+ /**
+ * Returns the last interceptor in the chain.
+ *
+ * @return the last interceptor in the chain
+ */
+ Interceptor getTailInterceptor();
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/InvocationRuntimeException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/InvocationRuntimeException.java
new file mode 100644
index 0000000000..c2ba19c48a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/InvocationRuntimeException.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.spi.wire;
+
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * Denotes a runtime exception thrown during an invocation over a wire
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvocationRuntimeException extends ServiceRuntimeException {
+
+ public InvocationRuntimeException() {
+ super();
+ }
+
+ public InvocationRuntimeException(String message) {
+ super(message);
+ }
+
+ public InvocationRuntimeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public InvocationRuntimeException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Message.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Message.java
new file mode 100644
index 0000000000..c67ca4f7b3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Message.java
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.wire;
+
+import java.net.URI;
+import java.util.LinkedList;
+
+import org.apache.tuscany.spi.component.WorkContext;
+
+/**
+ * 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
+ */
+ Object getBody();
+
+ /**
+ * Sets the body of the message.
+ */
+ void setBody(Object body);
+
+ /**
+ * Returns the context associated with this invocation.
+ * @return the context associated with this invocation
+ */
+ WorkContext getWorkContext();
+
+ /**
+ * Sets the context associated with this invocation.
+ * @param workContext the context associated with this invocation
+ */
+ void setWorkContext(WorkContext workContext);
+
+ /**
+ * Sets the target invoker to dispatch to when the message passes through the request side of the invocation chain
+ *
+ * @Deprecated
+ */
+ void setTargetInvoker(TargetInvoker invoker);
+
+ /**
+ * Sets the target invoker to dispatch to when the message passes through the request side of the invocation chain
+ *
+ * @Deprecated
+ */
+ TargetInvoker getTargetInvoker();
+
+ /**
+ * Adds a URI to the ordered list of callback URIs. Callback URIs are used to resolve the correct wire for a
+ * callback.
+ *
+ * @Deprecated
+ */
+ void pushCallbackUri(URI uri);
+
+ /**
+ * Returns the ordered list of callback URIs. Callback URIs are used to resolve the correct wire for a callback.
+ *
+ * @Deprecated
+ */
+ LinkedList<URI> getCallbackUris();
+
+ /**
+ * Sets the ordered list of callback URIs. Callback URIs are used to resolve the correct wire for a callback.
+ *
+ * @Deprecated
+ */
+ void setCallbackUris(LinkedList<URI> uris);
+
+ /**
+ * Adds a callback wire to the ordered list of callbacks for the current invocation
+ *
+ * @param wire the callback wire
+ */
+ void pushCallbackWire(Wire wire);
+
+ /**
+ * Returns the ordered list of callback wires for the current invocation
+ *
+ * @return the ordered list of callback wires for the current invocation
+ */
+ LinkedList<Wire> getCallbackWires();
+
+ /**
+ * Sets the ordered list of callback wires for the current invocation
+ *
+ * @param wires the ordered list of callback wires for the current invocation
+ */
+ void setCallbackWires(LinkedList<Wire> wires);
+
+ /**
+ * Returns the id of the message
+ */
+ Object getMessageId();
+
+ /**
+ * Sets the id of the message
+ */
+ 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.
+ */
+ Object getCorrelationId();
+
+ /**
+ * Sets the correlation id of the message. Correlation ids are used by transports for message routing.
+ */
+ 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 setBodyWithFault(Object fault);
+
+ /**
+ * Returns the conversational sequence the message is associated with, NONE, START, CONTINUE, or END on {@link
+ * TargetInvoker}
+ *
+ * @return the conversational sequence the message is associated with
+ */
+ short getConversationSequence();
+
+ /**
+ * Returns the conversational sequence the message is associated with, NONE, START, CONTINUE, or END on {@link
+ * TargetInvoker}
+ *
+ * @param sequence the conversational sequence
+ */
+ void setConversationSequence(short sequence);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/MessageId.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/MessageId.java
new file mode 100644
index 0000000000..f179eb79b1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/MessageId.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.spi.wire;
+
+/**
+ * A unique identifier for a message flowing on a wire, potentially end-to-end (ie, through more than one SCAObject to
+ * SCAObject hop).
+ */
+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/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/MessageImpl.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/MessageImpl.java
new file mode 100644
index 0000000000..91840ad299
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/MessageImpl.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.spi.wire;
+
+import java.net.URI;
+import java.util.LinkedList;
+
+import org.apache.tuscany.spi.component.WorkContext;
+
+/**
+ * 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 TargetInvoker invoker;
+ private LinkedList<URI> callbackUris;
+ private LinkedList<Wire> callbackWires;
+ private Object messageId;
+ private Object correlationId;
+ private boolean isFault;
+ private short conversationSequence;
+ private WorkContext workContext;
+
+ public MessageImpl(WorkContext workContext, short conversationSequence, Object body) {
+ this.workContext = workContext;
+ this.conversationSequence = conversationSequence;
+ this.body = body;
+ }
+
+ public MessageImpl() {
+ }
+
+ public Object getBody() {
+ return body;
+ }
+
+ public void setBody(Object body) {
+ this.isFault = false;
+ this.body = body;
+ }
+
+ public WorkContext getWorkContext() {
+ return workContext;
+ }
+
+ public void setWorkContext(WorkContext workContext) {
+ this.workContext = workContext;
+ }
+
+ public short getConversationSequence() {
+ return conversationSequence;
+ }
+
+ public void setConversationSequence(short conversationSequence) {
+ this.conversationSequence = conversationSequence;
+ }
+
+ public void setTargetInvoker(TargetInvoker invoker) {
+ this.invoker = invoker;
+ }
+
+ public TargetInvoker getTargetInvoker() {
+ return invoker;
+ }
+
+ public void pushCallbackUri(URI uri) {
+ if (callbackUris == null) {
+ callbackUris = new LinkedList<URI>();
+ }
+ callbackUris.add(uri);
+ }
+
+ public LinkedList<URI> getCallbackUris() {
+ return callbackUris;
+ }
+
+ public void setCallbackUris(LinkedList<URI> callbackRoutingChain) {
+ this.callbackUris = callbackRoutingChain;
+ }
+
+ public void pushCallbackWire(Wire wire) {
+ if (callbackWires == null) {
+ callbackWires = new LinkedList<Wire>();
+ }
+ callbackWires.add(wire);
+ }
+
+ public LinkedList<Wire> getCallbackWires() {
+ return callbackWires;
+ }
+
+ public void setCallbackWires(LinkedList<Wire> wires) {
+ this.callbackWires = wires;
+ }
+
+ 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 setBodyWithFault(Object fault) {
+ this.isFault = true;
+ this.body = fault;
+ }
+
+ public TargetInvoker getInvoker() {
+ return invoker;
+ }
+
+ public void setInvoker(TargetInvoker invoker) {
+ this.invoker = invoker;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ProxyCreationException.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ProxyCreationException.java
new file mode 100644
index 0000000000..4805c75252
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ProxyCreationException.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.spi.wire;
+
+import org.apache.tuscany.spi.CoreRuntimeException;
+
+/**
+ * Denotes an error creating a proxy
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class ProxyCreationException extends CoreRuntimeException {
+ public ProxyCreationException() {
+ }
+
+ public ProxyCreationException(String message) {
+ super(message);
+ }
+
+ public ProxyCreationException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public ProxyCreationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ProxyCreationException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+
+ public ProxyCreationException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ProxyService.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ProxyService.java
new file mode 100644
index 0000000000..7ea0dd2534
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/ProxyService.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.spi.wire;
+
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Map;
+
+import org.osoa.sca.CallableReference;
+
+import org.apache.tuscany.spi.model.ServiceContract;
+
+/**
+ * Creates proxies that implement Java interfaces and invocation handlers for fronting wires
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+
+public interface ProxyService {
+
+ /**
+ * 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
+ * @Deprecated
+ */
+ <T> T createProxy(Class<T> interfaze, Wire wire) throws ProxyCreationException;
+
+ <T> T createProxy2(Class<T> interfaze, boolean conversational, Wire wire) throws ProxyCreationException;
+
+
+ /**
+ * Creates a Java proxy for the given wire
+ *
+ * @param interfaze the interface the proxy implements
+ * @param wire the wire to proxy @return the proxy
+ * @param mapping the method to chain holder mapping to use in creating the proxy. Clients may cache and resuse
+ * this mapping for performance.
+ * @throws ProxyCreationException
+ * @Deprecated
+ */
+ <T> T createProxy(Class<T> interfaze, Wire wire, Map<Method, ChainHolder> mapping)
+ throws ProxyCreationException;
+
+ /**
+ * Creates a Java proxy for the service contract callback
+ *
+ * @param interfaze the interface the proxy should implement
+ * @return the proxy
+ * @throws ProxyCreationException
+ * @Deprecated
+ */
+ Object createCallbackProxy(Class<?> interfaze, List<Wire> wires) throws ProxyCreationException;
+
+ /**
+ * Creates a Java proxy for the service contract callback
+ *
+ * @param interfaze the interface the proxy should implement
+ * @return the proxy
+ * @throws ProxyCreationException if an error is encountered during proxy generation
+ */
+ Object createCallbackProxy(Class<?> interfaze) 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
+ */
+ <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException;
+
+ /**
+ * Check the compatiblity of the source and the target service contracts.<p> A wire may only connect a source to a
+ * target if the target implements an interface that is compatible with the interface required by the source. The
+ * source and the target are compatible if:
+ * <p/>
+ * <ol> <li>the source interface and the target interface MUST either both be remotable or they are both local
+ * <li>the methods on the target interface MUST be the same as or be a superset of the methods in the interface
+ * specified on the source <li>compatibility for the individual method is defined as compatibility of the signature,
+ * that is method name, input types, and output types MUST BE the same. <li>the order of the input and output types
+ * also MUST BE the same. <li>the set of Faults and Exceptions expected by the source MUST BE the same or be a
+ * superset of those specified by the service. <li>other specified attributes of the two interfaces MUST match,
+ * including Scope and Callback interface </ol>
+ * <p/>
+ * <p>Please note this test is not symetric: the success of checkCompatibility(A, B) does NOT imply
+ * checkCompatibility(B, A)
+ *
+ * @param source The source service contract
+ * @param target The target service contract
+ * @param ignoreCallback Indicate the callback should be checked
+ * @param silent if true, errors will be thrown if the service contracts are not compatible
+ * @return true if the service contracts are compatible
+ * @throws IncompatibleServiceContractException
+ * If the source service contract is not compatible with the target one
+ * <p/>
+ * TODO JFM this method should be moved from this interface to the allocator phase
+ */
+ boolean checkCompatibility(ServiceContract<?> source,
+ ServiceContract<?> target,
+ boolean ignoreCallback,
+ boolean silent) throws IncompatibleServiceContractException;
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/TargetInvoker.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/TargetInvoker.java
new file mode 100644
index 0000000000..9efa673ece
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/TargetInvoker.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.spi.wire;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.tuscany.spi.component.WorkContext;
+
+/**
+ * Implementations are responsible for resolving a target and performing the actual invocation on it, for example, a
+ * component implementation instance or a service client.
+ *
+ * @version $Rev$ $Date$
+ * @Deprecated
+ */
+public interface TargetInvoker extends Cloneable {
+ /* indicates that no conversational sequence is associated with the message */
+ short NONE = 0;
+ /* indicates that the message initiates a conversation */
+ short START = 1;
+ /* indicates that the message continues a conversation */
+ short CONTINUE = 2;
+ /* indicates that the message ends a conversation */
+ short END = 3;
+
+ /**
+ * Invokes an operation on a target with the given payload. Used in optmized cases where messages do not need to be
+ * flowed such as in non-proxied wires.
+ *
+ * @param payload the invocation payload, typically an array of parameters
+ * @param sequence if the invocation is part of a conversation, the sequence. Valid values are {@link #NONE} for
+ * non-conversational, {@link #START} to begin a conversation, {@link #CONTINUE} to continue a
+ * conversation, or {@link #END} to end a conversation
+ * @param workContext work context associated with this invocation
+ * @return the result of the invocation
+ * @throws InvocationTargetException if there was a problem invoking the target
+ */
+ Object invokeTarget(final Object payload, final short sequence, WorkContext workContext)
+ throws InvocationTargetException;
+
+ /**
+ * Invokes an operation on a target with the given message
+ *
+ * @throws InvocationRuntimeException
+ */
+ Message invoke(Message msg) throws InvocationRuntimeException;
+
+ /**
+ * Determines whether the proxy can be cached on the client/source side
+ */
+ boolean isCacheable();
+
+ /**
+ * Sets whether the target service instance may be cached by the invoker. This is a possible optimization when a
+ * wire is configured for a "down-scope" reference, i.e. a reference from a source of a shorter lifetime to a source
+ * of greater lifetime.
+ */
+ void setCacheable(boolean cacheable);
+
+ /**
+ * Determines if the target invoker can be discarded during wire optimization
+ */
+ boolean isOptimizable();
+
+ /**
+ * Implementations must support deep cloning
+ */
+ Object clone() throws CloneNotSupportedException;
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Wire.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Wire.java
new file mode 100644
index 0000000000..7f4f1f84ac
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/Wire.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.spi.wire;
+
+import java.net.URI;
+import java.util.Map;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+
+/**
+ * The base wire type used to connect references and serviceBindings
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public interface Wire {
+ QName LOCAL_BINDING = new QName("http://tuscany.apache.org/xmlns/sca/binding/1.0", "binding.local");
+
+ /**
+ * Returns the URI of the wire source
+ *
+ * @return the wire source URI
+ */
+ URI getSourceUri();
+
+ /**
+ * Sets the URI of the wire source
+ *
+ * @param uri the source uri
+ */
+ void setSourceUri(URI uri);
+
+ /**
+ * Returns the URI of the wire target
+ *
+ * @return the URI of the wire target
+ */
+ URI getTargetUri();
+
+ /**
+ * Sets the URI of the wire target
+ *
+ * @param uri the URI of the wire target
+ */
+ void setTargetUri(URI uri);
+
+ /**
+ * Returns the wire binding type
+ *
+ * @return the wire binding type
+ */
+ QName getBindingType();
+
+ /**
+ * Returns the service contract associated with the the source side of the wire
+ *
+ * @return the service contract associated with the wire
+ * @Deprecated
+ */
+ ServiceContract getSourceContract();
+
+ /**
+ * Sets the contract associated with the source side of the wire
+ *
+ * @param contract the contract associated with the wire
+ * @Deprecated
+ */
+ void setSourceContract(ServiceContract contract);
+
+ /**
+ * Returns the service contract associated with the the target side of the wire
+ *
+ * @return the service contract associated with the wire
+ * @Deprecated
+ */
+ ServiceContract getTargetContract();
+
+ /**
+ * Sets the contract associated with the the target side of the wire
+ *
+ * @param contract the contract associated with the wire
+ * @Deprecated
+ */
+ void setTargetContract(ServiceContract contract);
+
+ /**
+ * Returns true if the wire is optimizable and its invocation chains may be bypassed
+ *
+ * @return true if the wire is optimizable and its invocation chains may be bypassed
+ * @Deprecated
+ */
+ boolean isOptimizable();
+
+ /**
+ * Determines if the wire may be optimized
+ *
+ * @param optimizable true if the wire is optimizable
+ * @Deprecated
+ */
+ void setOptimizable(boolean optimizable);
+
+ /**
+ * Returns the non-proxied target instance for this wire
+ *
+ * @return the non-proxied target instance for this wire
+ * @Deprecated
+ */
+ Object getTargetInstance() throws TargetResolutionException;
+
+ /**
+ * Sets the target for the wire for optimizations
+ *
+ * @param target the target for the wire
+ * @Deprecated
+ */
+ void setTarget(AtomicComponent target);
+
+ /**
+ * Returns the invocation chains for service operations associated with the wire
+ *
+ * @return the invocation chains for service operations associated with the wire
+ * @Deprecated
+ */
+ Map<Operation<?>, InvocationChain> getInvocationChains();
+
+ /**
+ * Adds the invocation chain associated with the given operation
+ *
+ * @param operation the service operation
+ * @param chain the invocation chain
+ * @Deprecated
+ */
+ void addInvocationChain(Operation<?> operation, InvocationChain chain);
+
+ /**
+ * Adds the invocation chain associated with the given operation
+ *
+ * @param operation the service operation
+ * @param chain the invocation chain
+ * @Deprecated
+ */
+ void addInvocationChain(PhysicalOperationDefinition operation, InvocationChain chain);
+
+ Map<PhysicalOperationDefinition, InvocationChain> getPhysicalInvocationChains();
+
+ /**
+ * Returns the invocation chains for callback service operations associated with the wire
+ *
+ * @return the invocation chains for callback service operations associated with the wire
+ * @Deprecated
+ */
+ Map<Operation<?>, InvocationChain> getCallbackInvocationChains();
+
+ /**
+ * Adds the callback invocation chain associated with the given operation
+ *
+ * @param operation the service operation
+ * @param chain the invocation chain
+ * @Deprecated
+ */
+ void addCallbackInvocationChain(Operation<?> operation, InvocationChain chain);
+
+ Map<PhysicalOperationDefinition, InvocationChain> getCallbackPhysicalInvocationChains();
+
+ void addCallbackInvocationChain(PhysicalOperationDefinition operation, InvocationChain chain);
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WirePostProcessor.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WirePostProcessor.java
new file mode 100644
index 0000000000..e3ccb155cd
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WirePostProcessor.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.spi.wire;
+
+/**
+ * Implementations are called after wires are decorated with policy and before they are connected.
+ *
+ * @version $Rev$ $Date$
+ * @deprecated
+ */
+public interface WirePostProcessor {
+
+ void process(Wire wire);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WirePostProcessorExtension.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WirePostProcessorExtension.java
new file mode 100644
index 0000000000..d335df87b9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WirePostProcessorExtension.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.spi.wire;
+
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@Scope("COMPOSITE")
+@EagerInit
+public abstract class WirePostProcessorExtension implements WirePostProcessor {
+ protected WirePostProcessorRegistry registry;
+
+ @Reference
+ public void setRegistry(WirePostProcessorRegistry registry) {
+ this.registry = registry;
+ }
+
+ @Init
+ public void init() {
+ registry.register(this);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WirePostProcessorRegistry.java b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WirePostProcessorRegistry.java
new file mode 100644
index 0000000000..f012d119c3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/main/java/org/apache/tuscany/spi/wire/WirePostProcessorRegistry.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.spi.wire;
+
+/**
+ * Acts as a delegating <code>WirePostProcessor</code>, delegating post-processing of wires after policies have been
+ * applied and source an targets have been matched but before they are connected.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface WirePostProcessorRegistry extends WirePostProcessor {
+
+
+ /**
+ * Registers a post-processor in the runtime
+ *
+ * @param processor the processor to register
+ */
+ void register(WirePostProcessor processor);
+
+ /**
+ * De-registers a post-processor in the runtime
+ *
+ * @param processor the processor to de-register
+ */
+ void unregister(WirePostProcessor processor);
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/AssertionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/AssertionTestCase.java
new file mode 100644
index 0000000000..72739d56c4
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/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.spi;
+
+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/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/QualifiedNameTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/QualifiedNameTestCase.java
new file mode 100644
index 0000000000..1e7b2ab67c
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/QualifiedNameTestCase.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.spi;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests parsing of naming patters
+ *
+ * @version $Rev$ $Date$
+ */
+public class QualifiedNameTestCase extends TestCase {
+
+ public void testSimpleName() throws Exception {
+ QualifiedName name = new QualifiedName("Foo");
+ assertEquals("Foo", name.getPartName());
+ assertEquals(null, name.getPortName());
+ assertEquals("Foo", name.getQualifiedName());
+ assertEquals("Foo", name.getFragment());
+ assertEquals("Foo", name.toString());
+ }
+
+ public void testCompoundName() throws Exception {
+ QualifiedName name = new QualifiedName("Foo/Bar");
+ assertEquals("Foo", name.getPartName());
+ assertEquals("Bar", name.getPortName());
+ assertEquals("Foo/Bar", name.getQualifiedName());
+ assertEquals("Foo#Bar", name.getFragment());
+ assertEquals("Foo/Bar", name.toString());
+ }
+
+ public void testCompoundMultiName() throws Exception {
+ try {
+ new QualifiedName("Foo/Bar/Baz");
+ fail("Invalid name exception not thrown");
+ } catch (InvalidNameException e) {
+ // ok;
+ }
+ }
+
+ public void testInvalidName() throws Exception {
+ try {
+ new QualifiedName("/Foo/Bar");
+ fail("Invalid name exception not thrown");
+ } catch (InvalidNameException e) {
+ //expected
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/TuscanyRuntimeExceptionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/TuscanyRuntimeExceptionTestCase.java
new file mode 100644
index 0000000000..593b5a992b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/TuscanyRuntimeExceptionTestCase.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.spi;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TuscanyRuntimeExceptionTestCase extends TestCase {
+
+ public void testIdentifier() throws Exception {
+ TuscanyRuntimeException e = new TestException("bar", "foo");
+ assertEquals("foo", e.getIdentifier());
+ }
+
+ public void testEmptyGetMessage() throws Exception {
+ TuscanyRuntimeException e = new TestException();
+ e.getMessage();
+ }
+
+ private class TestException extends TuscanyRuntimeException {
+
+ public TestException() {
+ }
+
+ public TestException(String message, String identifier) {
+ super(message, identifier);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/AbstractSCAObjectTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/AbstractSCAObjectTestCase.java
new file mode 100644
index 0000000000..210997b8c8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/AbstractSCAObjectTestCase.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.spi.component;
+
+import java.net.URI;
+
+import org.apache.tuscany.spi.event.Event;
+import org.apache.tuscany.spi.event.EventFilter;
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+import org.apache.tuscany.spi.event.TrueFilter;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AbstractSCAObjectTestCase extends TestCase {
+
+ public void testFireListener() throws Exception {
+ SCAObject object = new TestSCAObject(new URI("foo"));
+ Event event = new TestEvent();
+ RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class);
+ listener.onEvent(EasyMock.same(event));
+ EasyMock.expectLastCall();
+ EasyMock.replay(listener);
+ object.addListener(listener);
+ object.publish(event);
+ }
+
+ public void testRemoveListener() throws Exception {
+ SCAObject object = new TestSCAObject(new URI("foo"));
+ Event event = new TestEvent();
+ RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class);
+ EasyMock.replay(listener);
+ object.addListener(listener);
+ object.removeListener(listener);
+ object.publish(event);
+ }
+
+ public void testFalseFilterListener() throws Exception {
+ SCAObject object = new TestSCAObject(new URI("foo"));
+ Event event = new TestEvent();
+ RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class);
+ EasyMock.replay(listener);
+ object.addListener(new FalseFilter(), listener);
+ object.publish(event);
+ }
+
+ public void testTrueFilterListener() throws Exception {
+ SCAObject object = new TestSCAObject(new URI("foo"));
+ Event event = new TestEvent();
+ RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class);
+ listener.onEvent(EasyMock.same(event));
+ EasyMock.expectLastCall();
+ EasyMock.replay(listener);
+ object.addListener(new TrueFilter(), listener);
+ object.publish(event);
+ }
+
+ public void testToString() throws Exception {
+ SCAObject object = new TestSCAObject(new URI("foo"));
+ assertNotNull(object.toString());
+ }
+
+ private class TestSCAObject extends AbstractSCAObject {
+ public TestSCAObject(URI name) {
+ super(name);
+ }
+
+ }
+
+ private class TestEvent implements Event {
+ public Object getSource() {
+ return null;
+ }
+ }
+
+ private class FalseFilter implements EventFilter {
+
+ public boolean match(Event event) {
+ return false;
+ }
+ }
+
+
+}
+
+
+
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/MockSCAExternalizable.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/MockSCAExternalizable.java
new file mode 100644
index 0000000000..510e6e4390
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/MockSCAExternalizable.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.spi.component;
+
+import java.io.Serializable;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@SuppressWarnings({"SerializableHasSerializationMethods"})
+public class MockSCAExternalizable implements Serializable, SCAExternalizable {
+ private static final long serialVersionUID = 5071815222959279772L;
+
+ private WorkContext context;
+ private boolean activated;
+
+ public void setWorkContext(WorkContext context) {
+ this.context = context;
+ }
+
+ public WorkContext getContext() {
+ return context;
+ }
+
+ public void reactivate() throws ReactivationException {
+ activated = true;
+ }
+
+ public boolean isActivated() {
+ return activated;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/MockSerializable.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/MockSerializable.java
new file mode 100644
index 0000000000..c853f427fb
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/MockSerializable.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.spi.component;
+
+import java.io.Serializable;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@SuppressWarnings({"SerializableHasSerializationMethods"})
+public class MockSerializable implements Serializable {
+ private static final long serialVersionUID = 4013396228070042469L;
+
+ private MockSCAExternalizable externalizable;
+
+ public MockSerializable() {
+ }
+
+ public MockSCAExternalizable getExternalizable() {
+ return externalizable;
+ }
+
+ public void setExternalizable(MockSCAExternalizable externalizable) {
+ this.externalizable = externalizable;
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/SCAObjectInputStreamTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/SCAObjectInputStreamTestCase.java
new file mode 100644
index 0000000000..ae316bc441
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/component/SCAObjectInputStreamTestCase.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.spi.component;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectOutputStream;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SCAObjectInputStreamTestCase extends TestCase {
+
+ public void testSCAExternalizable() throws Exception {
+ WorkContext context = EasyMock.createMock(WorkContext.class);
+ MockSCAExternalizable ext = new MockSCAExternalizable();
+ MockSerializable serializable = new MockSerializable();
+ serializable.setExternalizable(ext);
+ ByteArrayOutputStream bas = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(bas);
+ o.writeObject(serializable);
+ o.close();
+ ByteArrayInputStream bytes = new ByteArrayInputStream(bas.toByteArray());
+ SCAObjectInputStream stream = new SCAObjectInputStream(bytes, context);
+ MockSerializable deserialized = (MockSerializable) stream.readObject();
+ MockSCAExternalizable deserializedExt = deserialized.getExternalizable();
+ assertTrue(deserializedExt.isActivated());
+ assertEquals(context, deserializedExt.getContext());
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DOMHelperTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DOMHelperTestCase.java
new file mode 100644
index 0000000000..40843dea94
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DOMHelperTestCase.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.spi.databinding.extension;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public class DOMHelperTestCase extends TestCase {
+ private static final QName FOO_NAME = new QName("http://foo", "foo");
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testDOM() throws Exception {
+ DocumentBuilder builder = DOMHelper.newDocumentBuilder();
+ assertNotNull(builder);
+ Document document = DOMHelper.newDocument();
+ assertNotNull(document);
+ Element element = DOMHelper.createElement(document, FOO_NAME);
+ document.appendChild(element);
+ QName name = DOMHelper.getQName(element);
+ assertEquals(FOO_NAME, name);
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DataBindingExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DataBindingExtensionTestCase.java
new file mode 100644
index 0000000000..b4b5f6a39a
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/DataBindingExtensionTestCase.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.spi.databinding.extension;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.databinding.DataBindingRegistry;
+import org.easymock.EasyMock;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ *
+ */
+public class DataBindingExtensionTestCase extends TestCase {
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testExtension() {
+ DataBinding1 binding1 = new DataBinding1(Node.class);
+ assertEquals(Node.class.getName(), binding1.getName());
+ assertNotNull(binding1.introspect(Element.class));
+ assertNull(binding1.introspect(String.class));
+ assertNull(binding1.getWrapperHandler());
+
+ DataBindingRegistry registry = EasyMock.createMock(DataBindingRegistry.class);
+ registry.register(binding1);
+ EasyMock.expect(registry.getDataBinding(Node.class.getName())).andReturn(binding1);
+ EasyMock.replay(registry);
+
+ binding1.setDataBindingRegistry(registry);
+ binding1.init();
+ assertNotNull(registry.getDataBinding(Node.class.getName()));
+
+ DataBinding1 binding2 = new DataBinding1("dom", Node.class);
+ assertEquals("dom", binding2.getName());
+ }
+
+ private static class DataBinding1 extends DataBindingExtension {
+
+ /**
+ * @param baseType
+ */
+ public DataBinding1(Class<?> baseType) {
+ super(baseType);
+ }
+
+ /**
+ * @param name
+ * @param baseType
+ */
+ public DataBinding1(String name, Class<?> baseType) {
+ super(name, baseType);
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtensionTestCase.java
new file mode 100644
index 0000000000..6ff7909fa3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/SimpleTypeMapperExtensionTestCase.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.spi.databinding.extension;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.NamespaceContext;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.model.TypeInfo;
+
+import org.easymock.EasyMock;
+
+/**
+ *
+ */
+public class SimpleTypeMapperExtensionTestCase extends TestCase {
+
+ private static final Map<String, Object> SAMPLE_VALUES = new HashMap<String, Object>();
+
+ static {
+ SAMPLE_VALUES.put("anyURI", "http://www.w3.com");
+ SAMPLE_VALUES.put("boolean", new String[] {"true", "false", "1", "0"});
+ SAMPLE_VALUES.put("byte", new String[] {"-128", "127"});
+ SAMPLE_VALUES.put("date", new String[] {"2004-03-15", "2002-09-24-06:00"});
+ SAMPLE_VALUES.put("dateTime", "2003-12-25T08:30:00");
+ SAMPLE_VALUES.put("decimal", "3.1415292");
+ SAMPLE_VALUES.put("double", new String[] {"3.1415292", "INF", "NaN"});
+ SAMPLE_VALUES.put("duration", new String[] {"P8M3DT7H33M2S", "P5Y2M10DT15H"});
+ SAMPLE_VALUES.put("float", new String[] {"3.1415292", "INF", "NaN"});
+ SAMPLE_VALUES.put("gDay", "---11");
+ /*
+ * The value space of xsd:gMonth is the period of one calendar month recurring
+ * each calendar year (such as the month of April). Its lexical space should
+ * follow the ISO 8601 syntax for such periods (i.e., -- MM) with an optional
+ * time zone.
+ * Tip: There's a typo in the W3C XML Schema Recommendation, in which the format
+ * is defined as -- MM -- --. Even though an erratum should be published to
+ * bring the W3C XML Schema inline with ISO 8601, most current schema processors
+ * expect the (bogus) -- MM -- -- format.
+ *
+ * The test might be broken in JDK 1.6
+ */
+ SAMPLE_VALUES.put("gMonth", "--02--");
+ SAMPLE_VALUES.put("gMonthDay", "--02-14");
+ SAMPLE_VALUES.put("gYear", "1999");
+ SAMPLE_VALUES.put("gYearMonth", "1972-08");
+ SAMPLE_VALUES.put("ID", "id-102");
+ SAMPLE_VALUES.put("IDREF", "id-102");
+ SAMPLE_VALUES.put("IDREFS", "id-102 id-103 id-100");
+ SAMPLE_VALUES.put("int", "77");
+ SAMPLE_VALUES.put("integer", "77");
+ SAMPLE_VALUES.put("long", "214");
+ SAMPLE_VALUES.put("negativeInteger", "-123");
+ SAMPLE_VALUES.put("nonNegativeInteger", "2");
+ SAMPLE_VALUES.put("nonPositiveInteger", "0");
+ SAMPLE_VALUES.put("positiveInteger", "500");
+ SAMPLE_VALUES.put("short", "476");
+ SAMPLE_VALUES.put("string", "Joeseph");
+ SAMPLE_VALUES.put("time", "13:02:00");
+ SAMPLE_VALUES.put("base64Binary", "TWFu");
+ SAMPLE_VALUES.put("hexBinary", "2CDB5F");
+ SAMPLE_VALUES.put("QName", "f:foo");
+ SAMPLE_VALUES.put("NOTATION", "f:bar");
+ }
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testMap() throws Exception {
+ SimpleTypeMapperExtension extension = new SimpleTypeMapperExtension();
+ TransformationContext context = EasyMock.createMock(TransformationContext.class);
+ Map<Class<?>, Object> metaData = new HashMap<Class<?>, Object>();
+ EasyMock.expect(context.getMetadata()).andReturn(metaData).anyTimes();
+ EasyMock.replay(context);
+
+ NamespaceContext namespaceContext = EasyMock.createMock(NamespaceContext.class);
+ EasyMock.expect(namespaceContext.getNamespaceURI(EasyMock.eq("f"))).andReturn("http://foo")
+ .anyTimes();
+ EasyMock.expect(namespaceContext.getPrefix(EasyMock.eq("http://foo"))).andReturn("f").anyTimes();
+ EasyMock.replay(namespaceContext);
+ context.getMetadata().put(NamespaceContext.class, namespaceContext);
+ for (TypeInfo simpleType : SimpleTypeMapperExtension.XSD_SIMPLE_TYPES.values()) {
+ String name = simpleType.getQName().getLocalPart();
+ Object value = SAMPLE_VALUES.get(name);
+ if (value instanceof String[]) {
+ for (String s : (String[])value) {
+ Object obj = extension.toJavaObject(simpleType, s, context);
+ String str = extension.toXMLLiteral(simpleType, obj, context);
+ assertNotNull(str);
+ // assertTrue("[" + name + "] " + s + " " + str,
+ // str.contains((String) s));
+ }
+ } else if (value instanceof String) {
+ Object obj = extension.toJavaObject(simpleType, (String)value, context);
+ String str = extension.toXMLLiteral(simpleType, obj, context);
+ assertNotNull(str);
+ // assertTrue("[" + name + "] " + value + " " + str,
+ // str.contains((String) value));
+ }
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/TransformerExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/TransformerExtensionTestCase.java
new file mode 100644
index 0000000000..6f5dfc90e2
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/TransformerExtensionTestCase.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.spi.databinding.extension;
+
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.TransformerRegistry;
+import org.easymock.EasyMock;
+import org.w3c.dom.Node;
+
+/**
+ * Test case for TransformerExtension
+ */
+public class TransformerExtensionTestCase extends TestCase {
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testExtension() {
+ MyTransformer transformer = new MyTransformer();
+ assertEquals(Node.class.getName(), transformer.getSourceDataBinding());
+ assertEquals(XMLStreamReader.class.getName(), transformer.getTargetDataBinding());
+ assertEquals(50, transformer.getWeight());
+ TransformerRegistry registry = EasyMock.createMock(TransformerRegistry.class);
+ registry.registerTransformer(EasyMock.isA(Transformer.class));
+ EasyMock
+ .expect(registry.getTransformer(transformer.getSourceDataBinding(), transformer.getTargetDataBinding()))
+ .andReturn(transformer);
+ EasyMock.replay(registry);
+ transformer.setTransformerRegistry(registry);
+ transformer.init();
+ assertSame(transformer, registry.getTransformer(transformer.getSourceDataBinding(), transformer
+ .getTargetDataBinding()));
+ }
+
+ private static class MyTransformer extends TransformerExtension<Node, XMLStreamReader> {
+
+ @Override
+ protected Class getSourceType() {
+ return Node.class;
+ }
+
+ @Override
+ protected Class getTargetType() {
+ return XMLStreamReader.class;
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/XSDDataTypeConverterTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/XSDDataTypeConverterTestCase.java
new file mode 100644
index 0000000000..4693025c11
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/databinding/extension/XSDDataTypeConverterTestCase.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.spi.databinding.extension;
+
+import java.math.BigInteger;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public class XSDDataTypeConverterTestCase extends TestCase {
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testConvert() throws Exception {
+ XSDDataTypeConverter c = new XSDDataTypeConverter();
+ assertEquals("123", c.parseAnySimpleType(c.printAnySimpleType("123")));
+ assertEquals(true, c.parseBoolean(c.printBoolean(true)));
+ assertEquals(false, c.parseBoolean(c.printBoolean(false)));
+ assertEquals(123.0, c.parseDouble(c.printDouble(123.0)));
+ assertEquals(123.0f, c.parseFloat(c.printFloat(123.0f)));
+ assertEquals(64, c.parseByte(c.printByte((byte)64)));
+ assertEquals(123, c.parseInt(c.printInt(123)));
+ assertEquals(new BigInteger("123456"), c.parseInteger(c.printInteger(new BigInteger("123456"))));
+ assertEquals(123456L, c.parseLong(c.printLong(123456L)));
+ assertEquals((short)123, c.parseShort(c.printShort((short)123)));
+
+ Calendar calendar = new GregorianCalendar();
+ String s = c.printDate(calendar);
+ calendar = (GregorianCalendar)c.parseDate(s);
+ assertEquals(s, c.printDate(calendar));
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/event/AbstractEventPublisherTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/event/AbstractEventPublisherTestCase.java
new file mode 100644
index 0000000000..9eb96cd2f1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/event/AbstractEventPublisherTestCase.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.spi.event;
+
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AbstractEventPublisherTestCase 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 AbstractEventPublisher() {
+ };
+ }
+
+ private class TestEvent implements Event {
+ public Object getSource() {
+ return null;
+ }
+ }
+
+ private class FalseFilter implements EventFilter {
+
+ public boolean match(Event event) {
+ return false;
+ }
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/AbstractComponentExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/AbstractComponentExtensionTestCase.java
new file mode 100644
index 0000000000..e5d6cfe9f1
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/AbstractComponentExtensionTestCase.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.spi.extension;
+
+import java.net.URI;
+import java.util.List;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AbstractComponentExtensionTestCase extends TestCase {
+ private Component composite;
+
+ public void testGetService() throws Exception {
+ Service service = EasyMock.createMock(Service.class);
+ EasyMock.expect(service.getUri()).andReturn(URI.create("composite#service")).atLeastOnce();
+ EasyMock.replay(service);
+ composite.register(service);
+ assertNotNull(composite.getService("service"));
+ }
+
+ public void testGetDefaultService() throws Exception {
+ Service service = EasyMock.createMock(Service.class);
+ EasyMock.expect(service.getUri()).andReturn(URI.create("composite#service")).atLeastOnce();
+ EasyMock.replay(service);
+ composite.register(service);
+ assertNotNull(composite.getService(null));
+ }
+
+ public void testGetReference() throws Exception {
+ Reference reference = EasyMock.createMock(Reference.class);
+ EasyMock.expect(reference.getUri()).andReturn(URI.create("composite#service")).atLeastOnce();
+ EasyMock.replay(reference);
+ composite.register(reference);
+ assertNotNull(composite.getReference("service"));
+ }
+
+ public void testDefaultReference() throws Exception {
+ Reference reference = EasyMock.createMock(Reference.class);
+ EasyMock.expect(reference.getUri()).andReturn(URI.create("composite#service")).atLeastOnce();
+ EasyMock.replay(reference);
+ composite.register(reference);
+ assertNotNull(composite.getReference(null));
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ composite = new AbstractComponentExtension(new URI("foo")) {
+
+ public Scope getScope() {
+ return null;
+ }
+
+ public List<Wire> getWires(String name) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void attachWire(Wire wire) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void attachWires(List<Wire> wires) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void attachCallbackWire(Wire wire) {
+ throw new UnsupportedOperationException();
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, Operation operation)
+ throws TargetInvokerCreationException {
+ return null;
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, PhysicalOperationDefinition operation)
+ throws TargetInvokerCreationException {
+ return null;
+ }
+ };
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/AtomicComponentExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/AtomicComponentExtensionTestCase.java
new file mode 100644
index 0000000000..d2e0c70d62
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/AtomicComponentExtensionTestCase.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.spi.extension;
+
+import java.net.URI;
+import java.util.List;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AtomicComponentExtensionTestCase extends TestCase {
+ private AtomicComponentExtension ext;
+ private URI uri;
+
+ public void testURI() {
+ assertSame(uri, ext.getUri());
+ }
+
+ public void testRemoveInstance() throws Exception {
+ ScopeContainer scopeContainer = EasyMock.createMock(ScopeContainer.class);
+ EasyMock.expect(scopeContainer.getScope()).andReturn(Scope.COMPOSITE);
+ scopeContainer.remove(ext);
+ EasyMock.replay(scopeContainer);
+ ext.setScopeContainer(scopeContainer);
+ ext.removeInstance();
+ EasyMock.verify(scopeContainer);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ uri = URI.create("http://example.com/foo");
+ ext = new TestExtension(uri);
+ }
+
+ private static class TestExtension extends AtomicComponentExtension {
+
+ public TestExtension(URI uri) {
+ super(uri, null, null, URI.create("composite"), 0, -1, -1);
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, Operation operation)
+ throws TargetInvokerCreationException {
+ throw new AssertionFailedError();
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, PhysicalOperationDefinition operation)
+ throws TargetInvokerCreationException {
+ throw new AssertionFailedError();
+ }
+
+ public List<Wire> getWires(String name) {
+ throw new AssertionFailedError();
+ }
+
+ public void attachWire(Wire wire) {
+ throw new AssertionFailedError();
+ }
+
+ public void attachWires(List<Wire> wires) {
+ throw new AssertionFailedError();
+ }
+
+ public void attachCallbackWire(Wire wire) {
+ throw new AssertionFailedError();
+ }
+
+ public Object createInstance() throws ObjectCreationException {
+ throw new AssertionFailedError();
+ }
+
+ public Object getTargetInstance() throws TargetResolutionException {
+ throw new AssertionFailedError();
+ }
+
+ public InstanceWrapper<?> createInstanceWrapper() throws ObjectCreationException {
+ throw new AssertionFailedError();
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/ComponentTypeLoaderExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/ComponentTypeLoaderExtensionTestCase.java
new file mode 100644
index 0000000000..3aefb37b7f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/ComponentTypeLoaderExtensionTestCase.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.spi.extension;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.eq;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.Implementation;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ComponentTypeLoaderExtensionTestCase extends TestCase {
+
+ public void testRegistrationDeregistration() throws Exception {
+ Extension loader = new Extension();
+ LoaderRegistry registry = createMock(LoaderRegistry.class);
+ registry.registerLoader(eq(Implementation.class), eq(loader));
+ registry.unregisterLoader(eq(Implementation.class));
+ EasyMock.replay(registry);
+ loader.setLoaderRegistry(registry);
+ loader.start();
+ loader.stop();
+ }
+
+
+ private class Extension extends ComponentTypeLoaderExtension<Implementation> {
+
+ protected Class<Implementation> getImplementationClass() {
+ return Implementation.class;
+ }
+
+ public void load(Implementation implementation, DeploymentContext context) throws LoaderException {
+
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.java
new file mode 100644
index 0000000000..f7f6bc45c0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/CompositeComponentExtensionTestCase.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.spi.extension;
+
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.ServiceBinding;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CompositeComponentExtensionTestCase extends TestCase {
+ private Component composite;
+
+
+ public void testCreateTargetInvoker() throws Exception {
+ ServiceBinding binding = EasyMock.createMock(ServiceBinding.class);
+ EasyMock.expect(binding.createTargetInvoker(EasyMock.eq("service"), EasyMock.isA(Operation.class)))
+ .andReturn(null);
+ EasyMock.replay(binding);
+ List<ServiceBinding> bindings = new ArrayList<ServiceBinding>();
+ bindings.add(binding);
+ Service service = EasyMock.createMock(Service.class);
+ EasyMock.expect(service.getUri()).andReturn(URI.create("composite#service")).atLeastOnce();
+ EasyMock.expect(service.getServiceBindings()).andReturn(bindings).atLeastOnce();
+ EasyMock.replay(service);
+ composite.register(service);
+ Operation<Type> operation = new Operation<Type>("op", null, null, null);
+ composite.createTargetInvoker("service", operation);
+ EasyMock.verify(binding);
+
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ composite = new CompositeComponentExtension(new URI("foo")) {
+
+ public List<Wire> getWires(String name) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void attachWire(Wire wire) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void attachWires(List<Wire> wires) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void attachCallbackWire(Wire wire) {
+ throw new UnsupportedOperationException();
+ }
+
+ };
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/InterceptorBuilderExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/InterceptorBuilderExtensionTestCase.java
new file mode 100644
index 0000000000..a934f52fc3
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/InterceptorBuilderExtensionTestCase.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.spi.extension;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.builder.interceptor.InterceptorBuilder;
+import org.apache.tuscany.spi.builder.interceptor.InterceptorBuilderRegistry;
+import org.apache.tuscany.spi.model.physical.PhysicalInterceptorDefinition;
+import org.apache.tuscany.spi.wire.Interceptor;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InterceptorBuilderExtensionTestCase extends TestCase {
+ private static final QName QNAME = new QName("builder");
+
+ public void testRegistration() {
+ InterceptorBuilderRegistry registry = EasyMock.createMock(InterceptorBuilderRegistry.class);
+ registry.register(EasyMock.eq(QNAME), EasyMock.isA(InterceptorBuilder.class));
+ EasyMock.replay(registry);
+ InterceptorBuilderExtension builder = new InterceptorBuilderExtension() {
+ protected QName getName() {
+ return QNAME;
+ }
+
+ public Interceptor build(PhysicalInterceptorDefinition definition) throws BuilderException {
+ return null;
+ }
+ };
+
+ builder.setRegistry(registry);
+ builder.init();
+ EasyMock.verify(registry);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/LoaderExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/LoaderExtensionTestCase.java
new file mode 100644
index 0000000000..bf6e1d998d
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/LoaderExtensionTestCase.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.spi.extension;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.ModelObject;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LoaderExtensionTestCase extends TestCase {
+
+ @SuppressWarnings("unchecked")
+ public void testRegistrationDeregistration() throws Exception {
+ LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class);
+ registry.registerLoader(isA(QName.class), isA(Extension.class));
+ expectLastCall();
+ registry.unregisterLoader(isA(QName.class), isA(Extension.class));
+ expectLastCall();
+ EasyMock.replay(registry);
+ Extension loader = new Extension(registry);
+ loader.start();
+ loader.stop();
+ }
+
+
+ private static class Extension extends LoaderExtension {
+
+ public Extension(LoaderRegistry registry) {
+ super(registry);
+ }
+
+ public QName getXMLType() {
+ return new QName("");
+ }
+
+ public ModelObject load(
+ ModelObject object, XMLStreamReader reader,
+ DeploymentContext deploymentContext) throws XMLStreamException, LoaderException {
+ throw new AssertionError();
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionSequenceTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionSequenceTestCase.java
new file mode 100644
index 0000000000..4f3d2c8042
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionSequenceTestCase.java
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.spi.extension;
+
+import java.lang.reflect.InvocationTargetException;
+import java.net.URI;
+import java.util.LinkedList;
+
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TargetInvokerExtensionSequenceTestCase extends TestCase {
+
+ @SuppressWarnings("unchecked")
+ public void testStart() {
+ URI from = URI.create("foo");
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.replay(wire);
+ WorkContext context;
+ context = EasyMock.createMock(WorkContext.class);
+ context.setCallbackUris(EasyMock.isA(LinkedList.class));
+ EasyMock.replay(context);
+ ExecutionMonitor monitor = EasyMock.createNiceMock(ExecutionMonitor.class);
+ Target target = EasyMock.createMock(Target.class);
+ target.invokeStart("test");
+ EasyMock.replay(target);
+ Invoker invoker = new Invoker(target);
+ Message msg = new MessageImpl();
+ msg.setWorkContext(context);
+ msg.pushCallbackUri(from);
+ msg.setBody("test");
+ msg.setConversationSequence(Invoker.START);
+ invoker.invoke(msg);
+ EasyMock.verify(wire);
+ EasyMock.verify(context);
+ EasyMock.verify(target);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testContinue() {
+ URI from = URI.create("foo");
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.replay(wire);
+ WorkContext context;
+ context = EasyMock.createMock(WorkContext.class);
+ context.setCallbackUris(EasyMock.isA(LinkedList.class));
+ EasyMock.replay(context);
+ ExecutionMonitor monitor = EasyMock.createNiceMock(ExecutionMonitor.class);
+ Target target = EasyMock.createMock(Target.class);
+ target.invokeContinue("test");
+ EasyMock.replay(target);
+ Invoker invoker = new Invoker(target);
+ Message msg = new MessageImpl();
+ msg.setWorkContext(context);
+ msg.pushCallbackUri(from);
+ msg.setBody("test");
+ msg.setConversationSequence(Invoker.CONTINUE);
+ invoker.invoke(msg);
+ EasyMock.verify(wire);
+ EasyMock.verify(context);
+ EasyMock.verify(target);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testEnd() {
+ URI from = URI.create("foo");
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.replay(wire);
+ WorkContext context;
+ context = EasyMock.createMock(WorkContext.class);
+ context.setCallbackUris(EasyMock.isA(LinkedList.class));
+ EasyMock.replay(context);
+ ExecutionMonitor monitor = EasyMock.createNiceMock(ExecutionMonitor.class);
+ Target target = EasyMock.createMock(Target.class);
+ target.invokeEnd("test");
+ EasyMock.replay(target);
+ Invoker invoker = new Invoker(target);
+ Message msg = new MessageImpl();
+ msg.setWorkContext(context);
+ msg.pushCallbackUri(from);
+ msg.setBody("test");
+ msg.setConversationSequence(Invoker.END);
+ invoker.invoke(msg);
+ EasyMock.verify(wire);
+ EasyMock.verify(context);
+ EasyMock.verify(target);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testNone() {
+ URI from = URI.create("foo");
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.replay(wire);
+ WorkContext context;
+ context = EasyMock.createMock(WorkContext.class);
+ context.setCallbackUris(EasyMock.isA(LinkedList.class));
+ EasyMock.replay(context);
+ Target target = EasyMock.createMock(Target.class);
+ target.invokeNone("test");
+ EasyMock.replay(target);
+ Invoker invoker = new Invoker(target);
+ Message msg = new MessageImpl();
+ msg.setWorkContext(context);
+ msg.pushCallbackUri(from);
+ msg.setBody("test");
+ invoker.invoke(msg);
+ EasyMock.verify(wire);
+ EasyMock.verify(context);
+ EasyMock.verify(target);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ }
+
+ private class Invoker extends TargetInvokerExtension {
+ private Target target;
+
+ private Invoker(Target target) {
+ this.target = target;
+ }
+
+ public Object invokeTarget(final Object payload, final short sequence, WorkContext workContext) throws InvocationTargetException {
+ if (sequence == NONE) {
+ target.invokeNone((String) payload);
+ } else if (sequence == START) {
+ target.invokeStart((String) payload);
+ } else if (sequence == CONTINUE) {
+ target.invokeContinue((String) payload);
+ } else if (sequence == END) {
+ target.invokeEnd((String) payload);
+ }
+ return null;
+ }
+ }
+
+ private interface Target {
+ void invokeStart(String msg);
+
+ void invokeContinue(String msg);
+
+ void invokeEnd(String msg);
+
+ void invokeNone(String msg);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionTestCase.java
new file mode 100644
index 0000000000..f1205544c5
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/extension/TargetInvokerExtensionTestCase.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.spi.extension;
+
+import java.lang.reflect.InvocationTargetException;
+import java.net.URI;
+import java.util.LinkedList;
+
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TargetInvokerExtensionTestCase extends TestCase {
+
+ @SuppressWarnings("unchecked")
+ public void testNonBlockingDispatch() {
+ URI from = URI.create("foo");
+ Wire wire = EasyMock.createMock(Wire.class);
+ EasyMock.replay(wire);
+ WorkContext context;
+ context = EasyMock.createMock(WorkContext.class);
+ context.setCallbackUris(EasyMock.isA(LinkedList.class));
+ EasyMock.replay(context);
+ Target target = EasyMock.createMock(Target.class);
+ target.invoke("test");
+ EasyMock.replay(target);
+ Invoker invoker = new Invoker(target);
+ Message msg = new MessageImpl();
+ msg.setWorkContext(context);
+ msg.pushCallbackUri(from);
+ msg.setBody("test");
+ invoker.invoke(msg);
+ EasyMock.verify(wire);
+ EasyMock.verify(context);
+ EasyMock.verify(target);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ }
+
+ private class Invoker extends TargetInvokerExtension {
+ private Target target;
+
+ private Invoker(Target target) {
+ this.target = target;
+ }
+
+ public Object invokeTarget(final Object payload, final short sequence, WorkContext workContext) throws InvocationTargetException {
+ target.invoke((String) payload);
+ return null;
+ }
+ }
+
+ private interface Target {
+ void invoke(String msg);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/idl/java/JavaIDLUtilsTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/idl/java/JavaIDLUtilsTestCase.java
new file mode 100644
index 0000000000..cee80026f9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/idl/java/JavaIDLUtilsTestCase.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.spi.idl.java;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.apache.tuscany.spi.idl.java.JavaIDLUtils.findOperation;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaIDLUtilsTestCase extends TestCase {
+ private List<Operation<?>> operations;
+
+ public void testNoParamsFindOperation() throws Exception {
+ Method method = Foo.class.getMethod("foo");
+ Operation ret = findOperation(method, operations);
+ assertEquals("foo", ret.getName());
+ assertEquals(0, method.getParameterTypes().length);
+ }
+
+ public void testParamsFindOperation() throws Exception {
+ Method method = Foo.class.getMethod("foo", String.class);
+ Operation ret = findOperation(method, operations);
+ assertEquals("foo", ret.getName());
+ assertEquals(String.class, method.getParameterTypes()[0]);
+ }
+
+ public void testPrimitiveParamFindOperation() throws NoSuchMethodException {
+ Method method = Foo.class.getMethod("foo", Integer.TYPE);
+ Operation<?> operation = findOperation(method, operations);
+ assertEquals(Integer.TYPE, operation.getInputType().getLogical().get(0).getPhysical());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ Operation<Type> operation = new Operation<Type>("foo", null, null, null, false, null, NO_CONVERSATION);
+ operations = new ArrayList<Operation<?>>();
+ operations.add(operation);
+
+ List<DataType<Type>> types = new ArrayList<DataType<Type>>();
+ DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(Object[].class, types);
+ DataType<Type> type = new DataType<Type>(String.class, Object.class);
+ types.add(type);
+ operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION);
+ operations.add(operation);
+
+ types = new ArrayList<DataType<Type>>();
+ type = new DataType<Type>(String.class, Object.class);
+ DataType<Type> type2 = new DataType<Type>(String.class, Object.class);
+ types.add(type);
+ types.add(type2);
+ inputType = new DataType<List<DataType<Type>>>(Object[].class, types);
+ operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION);
+ operations.add(operation);
+
+ types = new ArrayList<DataType<Type>>();
+ type = new DataType<Type>(Integer.class, Object.class);
+ types.add(type);
+ inputType = new DataType<List<DataType<Type>>>(Object[].class, types);
+ operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION);
+ operations.add(operation);
+
+ types = new ArrayList<DataType<Type>>();
+ type = new DataType<Type>(Integer.TYPE, Object.class);
+ types.add(type);
+ inputType = new DataType<List<DataType<Type>>>(Object[].class, types);
+ operation = new Operation<Type>("foo", inputType, null, null, false, null, NO_CONVERSATION);
+ operations.add(operation);
+
+ }
+
+ private interface Foo {
+ void foo();
+
+ void foo(String foo);
+
+ void foo(int b);
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessorTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessorTestCase.java
new file mode 100644
index 0000000000..45a3bd4d68
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/implementation/java/AbstractPropertyProcessorTestCase.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.spi.implementation.java;
+
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.List;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AbstractPropertyProcessorTestCase extends TestCase {
+
+ private ImplementationProcessor processor;
+
+
+ public void testVisitMethod() throws Exception {
+ Method method = Foo.class.getMethod("setBar", String.class);
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitMethod(method, type, null);
+ JavaMappedProperty<?> prop = type.getProperties().get("test");
+ assertNotNull(prop.getDefaultValueFactory());
+ }
+
+ public void testVisitNoParamsMethod() throws Exception {
+ Method method = Foo.class.getMethod("setNoParamsBar");
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ try {
+ processor.visitMethod(method, type, null);
+ fail();
+ } catch (IllegalPropertyException e) {
+ //expected
+ }
+ }
+
+ public void testVisitNonVoidMethod() throws Exception {
+ Method method = Foo.class.getMethod("setBadBar", String.class);
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ try {
+ processor.visitMethod(method, type, null);
+ fail();
+ } catch (IllegalPropertyException e) {
+ //expected
+ }
+ }
+
+ public void testDuplicateMethod() throws Exception {
+ Method method = Foo.class.getMethod("setBar", String.class);
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitMethod(method, type, null);
+ try {
+ processor.visitMethod(method, type, null);
+ fail();
+ } catch (DuplicatePropertyException e) {
+ //expected
+ }
+ }
+
+ public void testVisitField() throws Exception {
+ Field field = Foo.class.getDeclaredField("d");
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitField(field, type, null);
+ JavaMappedProperty<?> prop = type.getProperties().get("test");
+ assertNotNull(prop.getDefaultValueFactory());
+ }
+
+ public void testVisitConstructor() throws Exception {
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
+ processor.visitConstructor(ctor, type, null);
+ ConstructorDefinition def = type.getConstructorDefinition();
+ assertEquals("test", def.getInjectionNames().get(0));
+ assertNotNull(type.getProperties().get("test"));
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+ ImplementationProcessorService service = EasyMock.createMock(ImplementationProcessorService.class);
+ service.addName(EasyMock.isA(List.class), EasyMock.eq(0), EasyMock.eq("test"));
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer() {
+ public Object answer() throws Throwable {
+ ((List<Object>) EasyMock.getCurrentArguments()[0]).add("test");
+ return null;
+ }
+ });
+ EasyMock.replay(service);
+ processor = new TestProcessor(service);
+ }
+
+ @Retention(RUNTIME)
+ private @interface Bar {
+
+ }
+
+ private class TestProcessor extends AbstractPropertyProcessor<Bar> {
+
+ public TestProcessor(ImplementationProcessorService service) {
+ super(Bar.class, service);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected <T> void initProperty(JavaMappedProperty<T> property,
+ Bar annotation,
+ DeploymentContext context) {
+ property.setDefaultValueFactory(EasyMock.createMock(ObjectFactory.class));
+ property.setName("test");
+ }
+
+ protected String getName(Bar annotation) {
+ return "test";
+ }
+ }
+
+
+ private static class Foo {
+
+ @Bar
+ protected String d;
+
+ public Foo(String a, @Bar String b) {
+ }
+
+ public Foo(@Bar String d) {
+ this.d = d;
+ }
+
+ @Bar
+ public void setBar(String d) {
+ this.d = d;
+ }
+
+ @Bar
+ public void setNoParamsBar() {
+ }
+
+ @Bar
+ public String setBadBar(String d) {
+ return null;
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/loader/LoaderExceptionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/loader/LoaderExceptionTestCase.java
new file mode 100644
index 0000000000..f8c991f7d4
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/loader/LoaderExceptionTestCase.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.spi.loader;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LoaderExceptionTestCase extends TestCase {
+
+ public void testResourceURI() throws Exception {
+ LoaderException e = new LoaderException();
+ e.setResourceURI("test");
+ assertEquals("test", e.getResourceURI());
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ComponentTypeTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ComponentTypeTestCase.java
new file mode 100644
index 0000000000..c7170e0597
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ComponentTypeTestCase.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.spi.model;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ComponentTypeTestCase extends TestCase {
+
+ /**
+ * Verifies fragments are used to retrieve service names
+ */
+ public void testSetServiceName() {
+ ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ServiceDefinition definition = new ServiceDefinition();
+ definition.setUri(URI.create("foo#bar"));
+ type.add(definition);
+ assertEquals(definition, type.getServices().get("bar"));
+ }
+
+ /**
+ * Verifies fragments are used to retrieve service names
+ */
+ public void testSetReferenceName() {
+ ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type =
+ new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>();
+ ReferenceDefinition definition = new ReferenceDefinition();
+ definition.setUri(URI.create("foo#bar"));
+ type.add(definition);
+ assertEquals(definition, type.getReferences().get("bar"));
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/CompositeComponentTypeTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/CompositeComponentTypeTestCase.java
new file mode 100644
index 0000000000..d348d2b3c8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/CompositeComponentTypeTestCase.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.spi.model;
+
+import junit.framework.TestCase;
+
+public class CompositeComponentTypeTestCase extends TestCase {
+
+ public void testWireCreationAndRetrieval() throws Exception {
+ WireDefinition wire1 = new WireDefinition();
+ WireDefinition wire2 = new WireDefinition();
+
+ CompositeComponentType composite = new CompositeComponentType();
+ CompositeComponentType includedComposite = new CompositeComponentType();
+ includedComposite.add(wire1);
+ Include compositeInclude = new Include();
+ compositeInclude.setIncluded(includedComposite);
+
+ composite.add(compositeInclude);
+ composite.add(wire1);
+
+ assertEquals(1, composite.getDeclaredWires().size());
+ assertEquals(wire1, composite.getDeclaredWires().get(0));
+ assertEquals(2, composite.getWires().size());
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/IntentNameTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/IntentNameTestCase.java
new file mode 100644
index 0000000000..698b7835d9
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/IntentNameTestCase.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.spi.model;
+
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+public class IntentNameTestCase extends TestCase {
+
+ public void testConstructor() throws Exception {
+ String case1 = "sec.confidentiality/message/body";
+ IntentName intentName = new IntentName(case1);
+ assertEquals("sec", intentName.getDomain());
+ assertEquals(case1, intentName.toString());
+ assertTrue(Arrays.equals(new String[]{"confidentiality", "message", "body"}, intentName.getQualifiedNames()));
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/OperationTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/OperationTestCase.java
new file mode 100644
index 0000000000..de5f1719b0
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/OperationTestCase.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.spi.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class OperationTestCase extends TestCase {
+
+ public void testClone() throws Exception {
+ DataType<Class> stringType = new DataType<Class>("xml:string", String.class, String.class);
+ List<DataType<Class>> inputTypes = new ArrayList<DataType<Class>>();
+ inputTypes.add(stringType);
+ DataType<List<DataType<Class>>> inputType =
+ new DataType<List<DataType<Class>>>("xml:string", Object[].class, inputTypes);
+
+ DataType<Class> faultType = new DataType<Class>("xml:foo", String.class, String.class);
+ List<DataType<Class>> faultTypes = new ArrayList<DataType<Class>>();
+ faultTypes.add(faultType);
+
+ Operation<Class> operation1 =
+ new Operation<Class>("call", inputType, stringType, faultTypes, true, "xml:string", NO_CONVERSATION);
+ Operation<Class> operation2 = operation1.clone();
+ assertEquals(operation1, operation2);
+ assertEquals(NO_CONVERSATION, operation2.getConversationSequence());
+ assertEquals("call", operation2.getName());
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ScopeTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ScopeTestCase.java
new file mode 100644
index 0000000000..a8a88626ec
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ScopeTestCase.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.spi.model;
+
+import junit.framework.TestCase;
+
+/**
+ * @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 {
+ private String scope;
+
+ public Bar(String scope) {
+ this.scope = scope;
+ }
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ServiceContractTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ServiceContractTestCase.java
new file mode 100644
index 0000000000..4cf98d1542
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/model/ServiceContractTestCase.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.spi.model;
+
+import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.lang.reflect.Type;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ServiceContractTestCase extends TestCase {
+
+ @SuppressWarnings("unchecked")
+ public void testAddOperation() throws Exception {
+ ServiceContract<Type> contract = new TestContract();
+ Operation<Type> operation = new Operation<Type>("foo", null, null, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> ops = new HashMap<String, Operation<Type>>();
+ ops.put("foo", operation);
+ contract.setOperations(ops);
+ assertEquals(contract, operation.getServiceContract());
+ assertFalse(operation.isCallback());
+ }
+
+ public void testAddCallbackOperation() throws Exception {
+ ServiceContract<Type> contract = new TestContract();
+ Operation<Type> operation = new Operation<Type>("foo", null, null, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> ops = new HashMap<String, Operation<Type>>();
+ ops.put("foo", operation);
+ contract.setCallbackOperations(ops);
+ assertEquals(contract, operation.getServiceContract());
+ assertTrue(operation.isCallback());
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testClone() throws Exception {
+ ServiceContract<Type> contract = new TestContract();
+ Operation<Type> operation = new Operation<Type>("foo", null, null, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> ops = new HashMap<String, Operation<Type>>();
+ ops.put("foo", operation);
+ contract.setOperations(ops);
+
+ operation = new Operation<Type>("bar", null, null, null, false, null, NO_CONVERSATION);
+ Map<String, Operation<Type>> callbackOps = new HashMap<String, Operation<Type>>();
+ ops.put("bar", operation);
+ contract.setCallbackOperations(callbackOps);
+
+ ServiceContract<Type> copy = (ServiceContract<Type>) contract.clone();
+ assertEquals(contract, copy);
+ }
+
+
+ private class TestContract extends ServiceContract<Type> {
+
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/policy/SourcePolicyBuilderExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/policy/SourcePolicyBuilderExtensionTestCase.java
new file mode 100644
index 0000000000..be0d96f3ea
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/policy/SourcePolicyBuilderExtensionTestCase.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.spi.policy;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import static org.apache.tuscany.spi.policy.PolicyBuilderRegistry.EXTENSION;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ * @deprecated
+ */
+public class SourcePolicyBuilderExtensionTestCase extends TestCase {
+
+ public void testRegister() throws Exception {
+ PolicyBuilderRegistry registry = EasyMock.createMock(PolicyBuilderRegistry.class);
+ registry.registerSourceBuilder(EasyMock.eq(EXTENSION), EasyMock.isA(MockPolicyBuilderExtension.class));
+ EasyMock.replay(registry);
+ SourcePolicyBuilderExtension extension = new MockPolicyBuilderExtension();
+ extension.setRegistry(registry);
+ extension.init();
+ EasyMock.verify(registry);
+ }
+
+ private static class MockPolicyBuilderExtension extends SourcePolicyBuilderExtension {
+
+ public void build(ReferenceDefinition definition, Wire wire) throws BuilderException {
+
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/policy/TargetPolicyBuilderExtensionTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/policy/TargetPolicyBuilderExtensionTestCase.java
new file mode 100644
index 0000000000..a044f6e507
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/policy/TargetPolicyBuilderExtensionTestCase.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.spi.policy;
+
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import static org.apache.tuscany.spi.policy.PolicyBuilderRegistry.EXTENSION;
+import org.apache.tuscany.spi.wire.Wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TargetPolicyBuilderExtensionTestCase extends TestCase {
+
+ public void testRegister() throws Exception {
+ PolicyBuilderRegistry registry = EasyMock.createMock(PolicyBuilderRegistry.class);
+ registry.registerTargetBuilder(EasyMock.eq(EXTENSION), EasyMock.isA(MockPolicyBuilderExtension.class));
+ EasyMock.replay(registry);
+ TargetPolicyBuilderExtension extension = new MockPolicyBuilderExtension();
+ extension.setRegistry(registry);
+ extension.init();
+ EasyMock.verify(registry);
+ }
+
+ private static class MockPolicyBuilderExtension extends TargetPolicyBuilderExtension {
+
+ public void build(ServiceDefinition definition, Wire wire) throws BuilderException {
+
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/util/URIHelperTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/util/URIHelperTestCase.java
new file mode 100644
index 0000000000..832e3eb3a8
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/util/URIHelperTestCase.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.spi.util;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class URIHelperTestCase extends TestCase {
+
+ public void testBaseName() throws Exception {
+ URI uri = new URI("foo");
+ assertEquals("foo", UriHelper.getBaseName(uri));
+ }
+
+ public void testBaseNameScheme() throws Exception {
+ URI uri = new URI("sca://foo");
+ assertEquals("foo", UriHelper.getBaseName(uri));
+ }
+
+ public void testBaseNameSchemePath() throws Exception {
+ URI uri = new URI("sca://bar/foo");
+ assertEquals("foo", UriHelper.getBaseName(uri));
+ }
+
+ public void testBaseNamePath() throws Exception {
+ URI uri = new URI("bar/foo");
+ assertEquals("foo", UriHelper.getBaseName(uri));
+ }
+
+ public void testBaseNameFragment() throws Exception {
+ URI uri = new URI("#foo");
+ assertEquals("#foo", UriHelper.getBaseName(uri));
+ }
+
+ public void testDefragmentedNameScheme() throws Exception {
+ URI uri = new URI("sca://foo/bar#bar");
+ assertEquals("sca://foo/bar", UriHelper.getDefragmentedName(uri).toString());
+ }
+
+ public void testDefragmentedName() throws Exception {
+ URI uri = new URI("foo/bar#bar");
+ assertEquals("foo/bar", UriHelper.getDefragmentedName(uri).toString());
+ }
+
+ public void testDefragmentedNoName() throws Exception {
+ URI uri = new URI("#bar");
+ assertEquals("", UriHelper.getDefragmentedName(uri).toString());
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/util/stax/StaxUtilTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/util/stax/StaxUtilTestCase.java
new file mode 100644
index 0000000000..87be31b23b
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/util/stax/StaxUtilTestCase.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.spi.util.stax;
+
+import java.io.InputStream;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case for StaxHelper
+ *
+ * @version $Revision$ $Date$
+ *
+ */
+public class StaxUtilTestCase extends TestCase {
+
+ public StaxUtilTestCase(String name) {
+ super(name);
+ }
+
+ public void testSerialize() throws XMLStreamException {
+
+ InputStream in = getClass().getClassLoader().getResourceAsStream("test.scdl");
+ XMLStreamReader reader = StaxUtil.createReader(in);
+ StaxUtil.serialize(reader);
+ // TODO Do assertions
+ }
+
+ public void testGetDocumentElementQName() throws XMLStreamException {
+ InputStream in = getClass().getClassLoader().getResourceAsStream("test.scdl");
+ XMLStreamReader reader = StaxUtil.createReader(in);
+ String xml = StaxUtil.serialize(reader);
+ QName qname = StaxUtil.getDocumentElementQName(xml);
+ assertEquals("http://www.osoa.org/xmlns/sca/1.0", qname.getNamespaceURI());
+ assertEquals("composite", qname.getLocalPart());
+ }
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/AbstractInvocationHandlerTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/AbstractInvocationHandlerTestCase.java
new file mode 100644
index 0000000000..41e2bb2e0f
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/AbstractInvocationHandlerTestCase.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.spi.wire;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URI;
+import java.util.LinkedList;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+import org.apache.tuscany.spi.component.WorkContext;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AbstractInvocationHandlerTestCase extends TestCase {
+ private WorkContext workContext;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ workContext = EasyMock.createMock(WorkContext.class);
+ EasyMock.expect(workContext.getCorrelationId()).andStubReturn(null);
+ EasyMock.expect(workContext.getCallbackUris()).andStubReturn(null);
+ EasyMock.replay(workContext);
+ }
+
+ public void testInvocation() throws Throwable {
+ InvocationHandler handler = new InvocationHandler();
+ Interceptor interceptor = new MockInterceptor();
+ TargetInvoker invoker = EasyMock.createMock(TargetInvoker.class);
+ EasyMock.replay(invoker);
+ InvocationChain chain = EasyMock.createMock(InvocationChain.class);
+ EasyMock.expect(chain.getHeadInterceptor()).andReturn(interceptor);
+ EasyMock.replay(chain);
+ Object resp = handler.invoke(chain, invoker, new String[]{"foo"}, null, new LinkedList<URI>(), workContext);
+ assertEquals("response", resp);
+ }
+
+ public void testShortCircuitInvocation() throws Throwable {
+ InvocationHandler handler = new InvocationHandler();
+ TargetInvoker invoker = new MockInvoker();
+ InvocationChain chain = EasyMock.createMock(InvocationChain.class);
+ EasyMock.expect(chain.getHeadInterceptor()).andReturn(null);
+ EasyMock.expect(chain.getTargetInvoker()).andReturn(invoker);
+ EasyMock.replay(chain);
+ Object resp = handler.invoke(chain, invoker, new String[]{"foo"}, null, new LinkedList<URI>(), workContext);
+ assertEquals("response", resp);
+ }
+
+
+ private class MockInvoker implements TargetInvoker {
+
+ public Object invokeTarget(final Object payload, final short sequence, WorkContext workContext) throws InvocationTargetException {
+ assertEquals("foo", Array.get(payload, 0));
+ return "response";
+ }
+
+ public Message invoke(Message msg) throws InvocationRuntimeException {
+ fail();
+ return null;
+ }
+
+ public boolean isCacheable() {
+ return false;
+ }
+
+ public void setCacheable(boolean cacheable) {
+
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+ }
+
+ private class InvocationHandler extends AbstractInvocationHandler {
+
+ protected URI getFromAddress() {
+ return URI.create("from");
+ }
+
+ }
+
+ private class MockInterceptor implements Interceptor {
+
+ public Message invoke(Message msg) {
+ assertNotNull(msg.getCorrelationId());
+ assertNotNull(msg.getTargetInvoker());
+ assertNotNull(msg.getMessageId());
+ assertNotNull(msg.getCallbackUris());
+ assertEquals("foo", Array.get(msg.getBody(), 0));
+ msg.setBody("response");
+ return msg;
+ }
+
+ public void setNext(Interceptor next) {
+
+ }
+
+ public Interceptor getNext() {
+ return null;
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+ }
+
+
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/ChainHolderTestCase.java b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/ChainHolderTestCase.java
new file mode 100644
index 0000000000..9b67ec53e4
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/java/org/apache/tuscany/spi/wire/ChainHolderTestCase.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.spi.wire;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ChainHolderTestCase extends TestCase {
+
+ public void testClone() {
+ InvocationChain chain = EasyMock.createMock(InvocationChain.class);
+ EasyMock.replay(chain);
+ ChainHolder holder = new ChainHolder(chain);
+ assertNotNull(holder.clone());
+ }
+}
diff --git a/tags/java/tsss-demo/kernel/spi/src/test/resources/test.scdl b/tags/java/tsss-demo/kernel/spi/src/test/resources/test.scdl
new file mode 100644
index 0000000000..337ec02f06
--- /dev/null
+++ b/tags/java/tsss-demo/kernel/spi/src/test/resources/test.scdl
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<!--
+ Test for stax.
+
+ $Rev$ $Date$
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ name="test.scdl">
+
+ <component name="test.component">
+ <system:implementation.system class="test.class"/>
+ <property name="testProperty">123</property>
+ </component>
+
+</composite>
diff --git a/tags/java/tsss-demo/pom.xml b/tags/java/tsss-demo/pom.xml
new file mode 100644
index 0000000000..b06c31003d
--- /dev/null
+++ b/tags/java/tsss-demo/pom.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany</groupId>
+ <artifactId>sca</artifactId>
+ <version>1.0-incubating</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tss-demo</artifactId>
+ <version>20070320-SNAPSHOT</version>
+ <packaging>pom</packaging>
+ <name>Apache Tuscany Demo for The ServerSide Symposium</name>
+ <description>Projet to build the demo run at The ServerSide Symposium March 2007.</description>
+
+ <!-- definition of repositories where the parent pom can be found -->
+ <repositories>
+ <repository>
+ <id>apache.incubator</id>
+ <name>Apache Incubator Repository</name>
+ <url>http://people.apache.org/repo/m2-incubating-repository/</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+
+ <modules>
+ <module>kernel</module>
+ <module>runtime</module>
+ <module>http.jetty</module>
+ <module>jms</module>
+ <module>console</module>
+ <module>core-samples</module>
+ <module>demo.app</module>
+ <module>demo</module>
+ </modules>
+</project>
diff --git a/tags/java/tsss-demo/runtime/LICENSE.txt b/tags/java/tsss-demo/runtime/LICENSE.txt
new file mode 100644
index 0000000000..0084319535
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, serviceDefinition marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/runtime/NOTICE.txt b/tags/java/tsss-demo/runtime/NOTICE.txt
new file mode 100644
index 0000000000..f714b4f572
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/NOTICE.txt
@@ -0,0 +1,14 @@
+Apache Tuscany SCA Runtime Environments
+Copyright (c) 2005 - 2007 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/runtime/README.txt b/tags/java/tsss-demo/runtime/README.txt
new file mode 100644
index 0000000000..7c246636b3
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/README.txt
@@ -0,0 +1,28 @@
+Apache Tuscany may be provisioned to a variety of runtime environments.
+This release provides support for embedding Tuscany in a web application and
+iTest plugin for integration testing. Also included is a standalone runtime
+for using Tuscany as a server.
+
+Standalone Runtime Features
+-----------------------------------
+
+The standalone runtime provides an easy-to-use execution environment for SCA
+composites. This alpha release supports a single-VM deployment model. Support
+for multi-VM contributions and deployment is planned for the next release.
+
+Web Application Runtime Features
+-----------------------------------
+
+The web application runtime provides support for embedding Tuscany in a web
+application. Included in this release is support for injecting services into
+the web application context so they may be accessed from standard
+Web Application UI frameworks.
+
+iTest Plugin Runtime Features
+-----------------------------------
+
+The iTest Plugin Runtime provides support for developing unit tests using the
+SCA 1.0 programming model. Specifically, it allows application assemblies to
+be deployed and tested from with Maven.
+
+The Tuscany Team
diff --git a/tags/java/tsss-demo/runtime/itest/plugin/LICENSE.txt b/tags/java/tsss-demo/runtime/itest/plugin/LICENSE.txt
new file mode 100644
index 0000000000..9601ead3f6
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/plugin/LICENSE.txt
@@ -0,0 +1,1407 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+APACHE TUSCANY SUBCOMPONENTS:
+
+The Apache Tuscany distribution includes a number of subcomponents with
+separate copyright notices and license terms. Your use of the source
+code for the these subcomponents is subject to the terms and
+conditions of the following licenses.
+
+===============================================================================
+
+For the Eclipse Modeling Framework component and the Celtix binding:
+
+Eclipse Public License - v 1.0
+
+THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
+PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF
+THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
+
+1. DEFINITIONS
+
+"Contribution" means:
+
+a) in the case of the initial Contributor, the initial code and
+documentation distributed under this Agreement, and
+b) in the case of each subsequent Contributor:
+
+i) changes to the Program, and
+
+ii) additions to the Program;
+
+where such changes and/or additions to the Program originate from and
+are distributed by that particular Contributor. A Contribution
+'originates' from a Contributor if it was added to the Program by such
+Contributor itself or anyone acting on such Contributor's behalf.
+Contributions do not include additions to the Program which: (i) are
+separate modules of software distributed in conjunction with the
+Program under their own license agreement, and (ii) are not derivative
+works of the Program.
+
+"Contributor" means any person or entity that distributes the Program.
+
+"Licensed Patents " mean patent claims licensable by a Contributor
+which are necessarily infringed by the use or sale of its Contribution
+alone or when combined with the Program.
+
+"Program" means the Contributions distributed in accordance with this
+Agreement.
+
+"Recipient" means anyone who receives the Program under this
+Agreement, including all Contributors.
+
+2. GRANT OF RIGHTS
+
+a) Subject to the terms of this Agreement, each Contributor hereby
+grants Recipient a non-exclusive, worldwide, royalty-free copyright
+license to reproduce, prepare derivative works of, publicly display,
+publicly perform, distribute and sublicense the Contribution of such
+Contributor, if any, and such derivative works, in source code and
+object code form.
+
+b) Subject to the terms of this Agreement, each Contributor hereby
+grants Recipient a non-exclusive, worldwide, royalty-free patent
+license under Licensed Patents to make, use, sell, offer to sell,
+import and otherwise transfer the Contribution of such Contributor, if
+any, in source code and object code form. This patent license shall
+apply to the combination of the Contribution and the Program if, at
+the time the Contribution is added by the Contributor, such addition
+of the Contribution causes such combination to be covered by the
+Licensed Patents. The patent license shall not apply to any other
+combinations which include the Contribution. No hardware per se is
+licensed hereunder.
+
+c) Recipient understands that although each Contributor grants the
+licenses to its Contributions set forth herein, no assurances are
+provided by any Contributor that the Program does not infringe the
+patent or other intellectual property rights of any other entity. Each
+Contributor disclaims any liability to Recipient for claims brought by
+any other entity based on infringement of intellectual property rights
+or otherwise. As a condition to exercising the rights and licenses
+granted hereunder, each Recipient hereby assumes sole responsibility
+to secure any other intellectual property rights needed, if any. For
+example, if a third party patent license is required to allow
+Recipient to distribute the Program, it is Recipient's responsibility
+to acquire that license before distributing the Program.
+
+d) Each Contributor represents that to its knowledge it has sufficient
+copyright rights in its Contribution, if any, to grant the copyright
+license set forth in this Agreement.
+
+3. REQUIREMENTS
+
+A Contributor may choose to distribute the Program in object code form
+under its own license agreement, provided that:
+
+a) it complies with the terms and conditions of this Agreement; and
+
+b) its license agreement:
+
+i) effectively disclaims on behalf of all Contributors all warranties
+and conditions, express and implied, including warranties or
+conditions of title and non-infringement, and implied warranties or
+conditions of merchantability and fitness for a particular purpose;
+
+ii) effectively excludes on behalf of all Contributors all liability
+for damages, including direct, indirect, special, incidental and
+consequential damages, such as lost profits;
+
+iii) states that any provisions which differ from this Agreement are
+offered by that Contributor alone and not by any other party; and
+
+iv) states that source code for the Program is available from such
+Contributor, and informs licensees how to obtain it in a reasonable
+manner on or through a medium customarily used for software exchange.
+
+When the Program is made available in source code form:
+
+a) it must be made available under this Agreement; and
+
+b) a copy of this Agreement must be included with each copy of the
+Program.
+
+Contributors may not remove or alter any copyright notices contained
+within the Program.
+
+Each Contributor must identify itself as the originator of its
+Contribution, if any, in a manner that reasonably allows subsequent
+Recipients to identify the originator of the Contribution.
+
+4. COMMERCIAL DISTRIBUTION
+
+Commercial distributors of software may accept certain
+responsibilities with respect to end users, business partners and the
+like. While this license is intended to facilitate the commercial use
+of the Program, the Contributor who includes the Program in a
+commercial product offering should do so in a manner which does not
+create potential liability for other Contributors. Therefore, if a
+Contributor includes the Program in a commercial product offering,
+such Contributor ("Commercial Contributor") hereby agrees to defend
+and indemnify every other Contributor ("Indemnified Contributor")
+against any losses, damages and costs (collectively "Losses") arising
+from claims, lawsuits and other legal actions brought by a third party
+against the Indemnified Contributor to the extent caused by the acts
+or omissions of such Commercial Contributor in connection with its
+distribution of the Program in a commercial product offering. The
+obligations in this section do not apply to any claims or Losses
+relating to any actual or alleged intellectual property infringement.
+In order to qualify, an Indemnified Contributor must: a) promptly
+notify the Commercial Contributor in writing of such claim, and b)
+allow the Commercial Contributor to control, and cooperate with the
+Commercial Contributor in, the defense and any related settlement
+negotiations. The Indemnified Contributor may participate in any such
+claim at its own expense.
+
+For example, a Contributor might include the Program in a commercial
+product offering, Product X. That Contributor is then a Commercial
+Contributor. If that Commercial Contributor then makes performance
+claims, or offers warranties related to Product X, those performance
+claims and warranties are such Commercial Contributor's responsibility
+alone. Under this section, the Commercial Contributor would have to
+defend claims against the other Contributors related to those
+performance claims and warranties, and if a court requires any other
+Contributor to pay any damages as a result, the Commercial Contributor
+must pay those damages.
+
+5. NO WARRANTY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
+PROVIDED 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. Each Recipient is solely
+responsible for determining the appropriateness of using and
+distributing the Program and assumes all risks associated with its
+exercise of rights under this Agreement , including but not limited to
+the risks and costs of program errors, compliance with applicable
+laws, damage to or loss of data, programs or equipment, and
+unavailability or interruption of operations.
+
+6. DISCLAIMER OF LIABILITY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR
+ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING
+WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR
+DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+7. GENERAL
+
+If any provision of this Agreement is invalid or unenforceable under
+applicable law, it shall not affect the validity or enforceability of
+the remainder of the terms of this Agreement, and without further
+action by the parties hereto, such provision shall be reformed to the
+minimum extent necessary to make such provision valid and enforceable.
+
+If Recipient institutes patent litigation against any entity
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+the Program itself (excluding combinations of the Program with other
+software or hardware) infringes such Recipient's patent(s), then such
+Recipient's rights granted under Section 2(b) shall terminate as of
+the date such litigation is filed.
+
+All Recipient's rights under this Agreement shall terminate if it
+fails to comply with any of the material terms or conditions of this
+Agreement and does not cure such failure in a reasonable period of
+time after becoming aware of such noncompliance. If all Recipient's
+rights under this Agreement terminate, Recipient agrees to cease use
+and distribution of the Program as soon as reasonably practicable.
+However, Recipient's obligations under this Agreement and any licenses
+granted by Recipient relating to the Program shall continue and
+survive.
+
+Everyone is permitted to copy and distribute copies of this Agreement,
+but in order to avoid inconsistency the Agreement is copyrighted and
+may only be modified in the following manner. The Agreement Steward
+reserves the right to publish new versions (including revisions) of
+this Agreement from time to time. No one other than the Agreement
+Steward has the right to modify this Agreement. The Eclipse Foundation
+is the initial Agreement Steward. The Eclipse Foundation may assign
+the responsibility to serve as the Agreement Steward to a suitable
+separate entity. Each new version of the Agreement will be given a
+distinguishing version number. The Program (including Contributions)
+may always be distributed subject to the version of the Agreement
+under which it was received. In addition, after a new version of the
+Agreement is published, Contributor may elect to distribute the
+Program (including its Contributions) under the new version. Except as
+expressly stated in Sections 2(a) and 2(b) above, Recipient receives
+no rights or licenses to the intellectual property of any Contributor
+under this Agreement, whether expressly, by implication, estoppel or
+otherwise. All rights in the Program not expressly granted under this
+Agreement are reserved.
+
+This Agreement is governed by the laws of the State of New York and
+the intellectual property laws of the United States of America. No
+party to this Agreement will bring a legal action under this Agreement
+more than one year after the cause of action arose. Each party waives
+its rights to a jury trial in any resulting litigation.
+
+===============================================================================
+
+For the Rhino JavaScript container component:
+
+Netscape Public License V1.1
+
+ AMENDMENTS
+
+ The Netscape Public License Version 1.1 ("NPL") consists of the
+ Mozilla Public License Version 1.1 with the following Amendments,
+ including Exhibit A-Netscape Public License. Files identified with
+ "Exhibit A-Netscape Public License" are governed by the Netscape
+ Public License Version 1.1.
+
+ Additional Terms applicable to the Netscape Public License.
+ I. Effect.
+ These additional terms described in this Netscape Public
+ License -- Amendments shall apply to the Mozilla Communicator
+ client code and to all Covered Code under this License.
+
+ II. "Netscape's Branded Code" means Covered Code that Netscape
+ distributes and/or permits others to distribute under one or more
+ trademark(s) which are controlled by Netscape but which are not
+ licensed for use under this License.
+
+ III. Netscape and logo.
+ This License does not grant any rights to use the trademarks
+ "Netscape", the "Netscape N and horizon" logo or the "Netscape
+ lighthouse" logo, "Netcenter", "Gecko", "Java" or "JavaScript",
+ "Smart Browsing" even if such marks are included in the Original
+ Code or Modifications.
+
+ IV. Inability to Comply Due to Contractual Obligation.
+ Prior to licensing the Original Code under this License, Netscape
+ has licensed third party code for use in Netscape's Branded Code.
+ To the extent that Netscape is limited contractually from making
+ such third party code available under this License, Netscape may
+ choose to reintegrate such code into Covered Code without being
+ required to distribute such code in Source Code form, even if
+ such code would otherwise be considered "Modifications" under
+ this License.
+
+ V. Use of Modifications and Covered Code by Initial Developer.
+ V.1. In General.
+ The obligations of Section 3 apply to Netscape, except to
+ the extent specified in this Amendment, Section V.2 and V.3.
+
+ V.2. Other Products.
+ Netscape may include Covered Code in products other than the
+ Netscape's Branded Code which are released by Netscape
+ during the two (2) years following the release date of the
+ Original Code, without such additional products becoming
+ subject to the terms of this License, and may license such
+ additional products on different terms from those contained
+ in this License.
+
+ V.3. Alternative Licensing.
+ Netscape may license the Source Code of Netscape's Branded
+ Code, including Modifications incorporated therein, without
+ such Netscape Branded Code becoming subject to the terms of
+ this License, and may license such Netscape Branded Code on
+ different terms from those contained in this License.
+
+ VI. Litigation.
+ Notwithstanding the limitations of Section 11 above, the
+ provisions regarding litigation in Section 11(a), (b) and (c) of
+ the License shall apply to all disputes relating to this License.
+
+ EXHIBIT A-Netscape Public License.
+
+ "The contents of this file are subject to the Netscape Public
+ License Version 1.1 (the "License"); you may not use this file
+ except in compliance with the License. You may obtain a copy of
+ the License at http://www.mozilla.org/NPL/
+
+ Software distributed under the License is distributed on an "AS
+ IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ implied. See the License for the specific language governing
+ rights and limitations under the License.
+
+ The Original Code is Mozilla Communicator client code, released
+ March 31, 1998.
+
+ The Initial Developer of the Original Code is Netscape
+ Communications Corporation. Portions created by Netscape are
+ Copyright (C) 1998-1999 Netscape Communications Corporation. All
+ Rights Reserved.
+
+ Contributor(s): ______________________________________.
+
+ Alternatively, the contents of this file may be used under the
+ terms of the _____ license (the "[___] License"), in which case
+ the provisions of [______] License are applicable instead of
+ those above. If you wish to allow use of your version of this
+ file only under the terms of the [____] License and not to allow
+ others to use your version of this file under the NPL, indicate
+ your decision by deleting the provisions above and replace them
+ with the notice and other provisions required by the [___]
+ License. If you do not delete the provisions above, a recipient
+ may use your version of this file under either the NPL or the
+ [___] License."
+
+ ----------------------------------------------------------------------
+
+ MOZILLA PUBLIC LICENSE
+ Version 1.1
+
+ ---------------
+
+1. Definitions.
+
+ 1.0.1. "Commercial Use" means distribution or otherwise making the
+ Covered Code available to a third party.
+
+ 1.1. "Contributor" means each entity that creates or contributes to
+ the creation of Modifications.
+
+ 1.2. "Contributor Version" means the combination of the Original
+ Code, prior Modifications used by a Contributor, and the Modifications
+ made by that particular Contributor.
+
+ 1.3. "Covered Code" means the Original Code or Modifications or the
+ combination of the Original Code and Modifications, in each case
+ including portions thereof.
+
+ 1.4. "Electronic Distribution Mechanism" means a mechanism generally
+ accepted in the software development community for the electronic
+ transfer of data.
+
+ 1.5. "Executable" means Covered Code in any form other than Source
+ Code.
+
+ 1.6. "Initial Developer" means the individual or entity identified
+ as the Initial Developer in the Source Code notice required by Exhibit
+ A.
+
+ 1.7. "Larger Work" means a work which combines Covered Code or
+ portions thereof with code not governed by the terms of this License.
+
+ 1.8. "License" means this document.
+
+ 1.8.1. "Licensable" means having the right to grant, to the maximum
+ extent possible, whether at the time of the initial grant or
+ subsequently acquired, any and all of the rights conveyed herein.
+
+ 1.9. "Modifications" means any addition to or deletion from the
+ substance or structure of either the Original Code or any previous
+ Modifications. When Covered Code is released as a series of files, a
+ Modification is:
+ A. Any addition to or deletion from the contents of a file
+ containing Original Code or previous Modifications.
+
+ B. Any new file that contains any part of the Original Code or
+ previous Modifications.
+
+ 1.10. "Original Code" means Source Code of computer software code
+ which is described in the Source Code notice required by Exhibit A as
+ Original Code, and which, at the time of its release under this
+ License is not already Covered Code governed by this License.
+
+ 1.10.1. "Patent Claims" means any patent claim(s), now owned or
+ hereafter acquired, including without limitation, method, process,
+ and apparatus claims, in any patent Licensable by grantor.
+
+ 1.11. "Source Code" means the preferred form of the Covered Code for
+ making modifications to it, including all modules it contains, plus
+ any associated interface definition files, scripts used to control
+ compilation and installation of an Executable, or source code
+ differential comparisons against either the Original Code or another
+ well known, available Covered Code of the Contributor's choice. The
+ Source Code can be in a compressed or archival form, provided the
+ appropriate decompression or de-archiving software is widely available
+ for no charge.
+
+ 1.12. "You" (or "Your") means an individual or a legal entity
+ exercising rights under, and complying with all of the terms of, this
+ License or a future version of this License issued under Section 6.1.
+ For legal entities, "You" includes any entity which controls, is
+ controlled by, or is under common control with You. For purposes of
+ this definition, "control" means (a) the power, direct or indirect,
+ to cause the direction or management of such entity, whether by
+ contract or otherwise, or (b) ownership of more than fifty percent
+ (50%) of the outstanding shares or beneficial ownership of such
+ entity.
+
+2. Source Code License.
+
+ 2.1. The Initial Developer Grant.
+ The Initial Developer hereby grants You a world-wide, royalty-free,
+ non-exclusive license, subject to third party intellectual property
+ claims:
+ (a) under intellectual property rights (other than patent or
+ trademark) Licensable by Initial Developer to use, reproduce,
+ modify, display, perform, sublicense and distribute the Original
+ Code (or portions thereof) with or without Modifications, and/or
+ as part of a Larger Work; and
+
+ (b) under Patents Claims infringed by the making, using or
+ selling of Original Code, to make, have made, use, practice,
+ sell, and offer for sale, and/or otherwise dispose of the
+ Original Code (or portions thereof).
+
+ (c) the licenses granted in this Section 2.1(a) and (b) are
+ effective on the date Initial Developer first distributes
+ Original Code under the terms of this License.
+
+ (d) Notwithstanding Section 2.1(b) above, no patent license is
+ granted: 1) for code that You delete from the Original Code; 2)
+ separate from the Original Code; or 3) for infringements caused
+ by: i) the modification of the Original Code or ii) the
+ combination of the Original Code with other software or devices.
+
+ 2.2. Contributor Grant.
+ Subject to third party intellectual property claims, each Contributor
+ hereby grants You a world-wide, royalty-free, non-exclusive license
+
+ (a) under intellectual property rights (other than patent or
+ trademark) Licensable by Contributor, to use, reproduce, modify,
+ display, perform, sublicense and distribute the Modifications
+ created by such Contributor (or portions thereof) either on an
+ unmodified basis, with other Modifications, as Covered Code
+ and/or as part of a Larger Work; and
+
+ (b) under Patent Claims infringed by the making, using, or
+ selling of Modifications made by that Contributor either alone
+ and/or in combination with its Contributor Version (or portions
+ of such combination), to make, use, sell, offer for sale, have
+ made, and/or otherwise dispose of: 1) Modifications made by that
+ Contributor (or portions thereof); and 2) the combination of
+ Modifications made by that Contributor with its Contributor
+ Version (or portions of such combination).
+
+ (c) the licenses granted in Sections 2.2(a) and 2.2(b) are
+ effective on the date Contributor first makes Commercial Use of
+ the Covered Code.
+
+ (d) Notwithstanding Section 2.2(b) above, no patent license is
+ granted: 1) for any code that Contributor has deleted from the
+ Contributor Version; 2) separate from the Contributor Version;
+ 3) for infringements caused by: i) third party modifications of
+ Contributor Version or ii) the combination of Modifications made
+ by that Contributor with other software (except as part of the
+ Contributor Version) or other devices; or 4) under Patent Claims
+ infringed by Covered Code in the absence of Modifications made by
+ that Contributor.
+
+3. Distribution Obligations.
+
+ 3.1. Application of License.
+ The Modifications which You create or to which You contribute are
+ governed by the terms of this License, including without limitation
+ Section 2.2. The Source Code version of Covered Code may be
+ distributed only under the terms of this License or a future version
+ of this License released under Section 6.1, and You must include a
+ copy of this License with every copy of the Source Code You
+ distribute. You may not offer or impose any terms on any Source Code
+ version that alters or restricts the applicable version of this
+ License or the recipients' rights hereunder. However, You may include
+ an additional document offering the additional rights described in
+ Section 3.5.
+
+ 3.2. Availability of Source Code.
+ Any Modification which You create or to which You contribute must be
+ made available in Source Code form under the terms of this License
+ either on the same media as an Executable version or via an accepted
+ Electronic Distribution Mechanism to anyone to whom you made an
+ Executable version available; and if made available via Electronic
+ Distribution Mechanism, must remain available for at least twelve (12)
+ months after the date it initially became available, or at least six
+ (6) months after a subsequent version of that particular Modification
+ has been made available to such recipients. You are responsible for
+ ensuring that the Source Code version remains available even if the
+ Electronic Distribution Mechanism is maintained by a third party.
+
+ 3.3. Description of Modifications.
+ You must cause all Covered Code to which You contribute to contain a
+ file documenting the changes You made to create that Covered Code and
+ the date of any change. You must include a prominent statement that
+ the Modification is derived, directly or indirectly, from Original
+ Code provided by the Initial Developer and including the name of the
+ Initial Developer in (a) the Source Code, and (b) in any notice in an
+ Executable version or related documentation in which You describe the
+ origin or ownership of the Covered Code.
+
+ 3.4. Intellectual Property Matters
+ (a) Third Party Claims.
+ If Contributor has knowledge that a license under a third party's
+ intellectual property rights is required to exercise the rights
+ granted by such Contributor under Sections 2.1 or 2.2,
+ Contributor must include a text file with the Source Code
+ distribution titled "LEGAL" which describes the claim and the
+ party making the claim in sufficient detail that a recipient will
+ know whom to contact. If Contributor obtains such knowledge after
+ the Modification is made available as described in Section 3.2,
+ Contributor shall promptly modify the LEGAL file in all copies
+ Contributor makes available thereafter and shall take other steps
+ (such as notifying appropriate mailing lists or newsgroups)
+ reasonably calculated to inform those who received the Covered
+ Code that new knowledge has been obtained.
+
+ (b) Contributor APIs.
+ If Contributor's Modifications include an application programming
+ interface and Contributor has knowledge of patent licenses which
+ are reasonably necessary to implement that API, Contributor must
+ also include this information in the LEGAL file.
+
+ (c) Representations.
+ Contributor represents that, except as disclosed pursuant to
+ Section 3.4(a) above, Contributor believes that Contributor's
+ Modifications are Contributor's original creation(s) and/or
+ Contributor has sufficient rights to grant the rights conveyed by
+ this License.
+
+ 3.5. Required Notices.
+ You must duplicate the notice in Exhibit A in each file of the Source
+ Code. If it is not possible to put such notice in a particular Source
+ Code file due to its structure, then You must include such notice in a
+ location (such as a relevant directory) where a user would be likely
+ to look for such a notice. If You created one or more Modification(s)
+ You may add your name as a Contributor to the notice described in
+ Exhibit A. You must also duplicate this License in any documentation
+ for the Source Code where You describe recipients' rights or ownership
+ rights relating to Covered Code. You may choose to offer, and to
+ charge a fee for, warranty, support, indemnity or liability
+ obligations to one or more recipients of Covered Code. However, You
+ may do so only on Your own behalf, and not on behalf of the Initial
+ Developer or any Contributor. You must make it absolutely clear than
+ any such warranty, support, indemnity or liability obligation is
+ offered by You alone, and You hereby agree to indemnify the Initial
+ Developer and every Contributor for any liability incurred by the
+ Initial Developer or such Contributor as a result of warranty,
+ support, indemnity or liability terms You offer.
+
+ 3.6. Distribution of Executable Versions.
+ You may distribute Covered Code in Executable form only if the
+ requirements of Section 3.1-3.5 have been met for that Covered Code,
+ and if You include a notice stating that the Source Code version of
+ the Covered Code is available under the terms of this License,
+ including a description of how and where You have fulfilled the
+ obligations of Section 3.2. The notice must be conspicuously included
+ in any notice in an Executable version, related documentation or
+ collateral in which You describe recipients' rights relating to the
+ Covered Code. You may distribute the Executable version of Covered
+ Code or ownership rights under a license of Your choice, which may
+ contain terms different from this License, provided that You are in
+ compliance with the terms of this License and that the license for the
+ Executable version does not attempt to limit or alter the recipient's
+ rights in the Source Code version from the rights set forth in this
+ License. If You distribute the Executable version under a different
+ license You must make it absolutely clear that any terms which differ
+ from this License are offered by You alone, not by the Initial
+ Developer or any Contributor. You hereby agree to indemnify the
+ Initial Developer and every Contributor for any liability incurred by
+ the Initial Developer or such Contributor as a result of any such
+ terms You offer.
+
+ 3.7. Larger Works.
+ You may create a Larger Work by combining Covered Code with other code
+ not governed by the terms of this License and distribute the Larger
+ Work as a single product. In such a case, You must make sure the
+ requirements of this License are fulfilled for the Covered Code.
+
+4. Inability to Comply Due to Statute or Regulation.
+
+ If it is impossible for You to comply with any of the terms of this
+ License with respect to some or all of the Covered Code due to
+ statute, judicial order, or regulation then You must: (a) comply with
+ the terms of this License to the maximum extent possible; and (b)
+ describe the limitations and the code they affect. Such description
+ must be included in the LEGAL file described in Section 3.4 and must
+ be included with all distributions of the Source Code. Except to the
+ extent prohibited by statute or regulation, such description must be
+ sufficiently detailed for a recipient of ordinary skill to be able to
+ understand it.
+
+5. Application of this License.
+
+ This License applies to code to which the Initial Developer has
+ attached the notice in Exhibit A and to related Covered Code.
+
+6. Versions of the License.
+
+ 6.1. New Versions.
+ Netscape Communications Corporation ("Netscape") may publish revised
+ and/or new versions of the License from time to time. Each version
+ will be given a distinguishing version number.
+
+ 6.2. Effect of New Versions.
+ Once Covered Code has been published under a particular version of the
+ License, You may always continue to use it under the terms of that
+ version. You may also choose to use such Covered Code under the terms
+ of any subsequent version of the License published by Netscape. No one
+ other than Netscape has the right to modify the terms applicable to
+ Covered Code created under this License.
+
+ 6.3. Derivative Works.
+ If You create or use a modified version of this License (which you may
+ only do in order to apply it to code which is not already Covered Code
+ governed by this License), You must (a) rename Your license so that
+ the phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape",
+ "MPL", "NPL" or any confusingly similar phrase do not appear in your
+ license (except to note that your license differs from this License)
+ and (b) otherwise make it clear that Your version of the license
+ contains terms which differ from the Mozilla Public License and
+ Netscape Public License. (Filling in the name of the Initial
+ Developer, Original Code or Contributor in the notice described in
+ Exhibit A shall not of themselves be deemed to be modifications of
+ this License.)
+
+7. DISCLAIMER OF WARRANTY.
+
+ COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF
+ DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING.
+ THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE
+ IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT,
+ YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE
+ COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER
+ OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF
+ ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
+
+8. TERMINATION.
+
+ 8.1. This License and the rights granted hereunder will terminate
+ automatically if You fail to comply with terms herein and fail to cure
+ such breach within 30 days of becoming aware of the breach. All
+ sublicenses to the Covered Code which are properly granted shall
+ survive any termination of this License. Provisions which, by their
+ nature, must remain in effect beyond the termination of this License
+ shall survive.
+
+ 8.2. If You initiate litigation by asserting a patent infringement
+ claim (excluding declatory judgment actions) against Initial Developer
+ or a Contributor (the Initial Developer or Contributor against whom
+ You file such action is referred to as "Participant") alleging that:
+
+ (a) such Participant's Contributor Version directly or indirectly
+ infringes any patent, then any and all rights granted by such
+ Participant to You under Sections 2.1 and/or 2.2 of this License
+ shall, upon 60 days notice from Participant terminate prospectively,
+ unless if within 60 days after receipt of notice You either: (i)
+ agree in writing to pay Participant a mutually agreeable reasonable
+ royalty for Your past and future use of Modifications made by such
+ Participant, or (ii) withdraw Your litigation claim with respect to
+ the Contributor Version against such Participant. If within 60 days
+ of notice, a reasonable royalty and payment arrangement are not
+ mutually agreed upon in writing by the parties or the litigation claim
+ is not withdrawn, the rights granted by Participant to You under
+ Sections 2.1 and/or 2.2 automatically terminate at the expiration of
+ the 60 day notice period specified above.
+
+ (b) any software, hardware, or device, other than such Participant's
+ Contributor Version, directly or indirectly infringes any patent, then
+ any rights granted to You by such Participant under Sections 2.1(b)
+ and 2.2(b) are revoked effective as of the date You first made, used,
+ sold, distributed, or had made, Modifications made by that
+ Participant.
+
+ 8.3. If You assert a patent infringement claim against Participant
+ alleging that such Participant's Contributor Version directly or
+ indirectly infringes any patent where such claim is resolved (such as
+ by license or settlement) prior to the initiation of patent
+ infringement litigation, then the reasonable value of the licenses
+ granted by such Participant under Sections 2.1 or 2.2 shall be taken
+ into account in determining the amount or value of any payment or
+ license.
+
+ 8.4. In the event of termination under Sections 8.1 or 8.2 above,
+ all end user license agreements (excluding distributors and resellers)
+ which have been validly granted by You or any distributor hereunder
+ prior to termination shall survive termination.
+
+9. LIMITATION OF LIABILITY.
+
+ UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
+ (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL
+ DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE,
+ OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR
+ ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY
+ CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL,
+ WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER
+ COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN
+ INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF
+ LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY
+ RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW
+ PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE
+ EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO
+ THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
+
+10. U.S. GOVERNMENT END USERS.
+
+ The Covered Code is a "commercial item," as that term is defined in
+ 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer
+ software" and "commercial computer software documentation," as such
+ terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48
+ C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995),
+ all U.S. Government End Users acquire Covered Code with only those
+ rights set forth herein.
+
+11. MISCELLANEOUS.
+
+ This License represents the complete agreement concerning subject
+ matter hereof. If any provision of this License is held to be
+ unenforceable, such provision shall be reformed only to the extent
+ necessary to make it enforceable. This License shall be governed by
+ California law provisions (except to the extent applicable law, if
+ any, provides otherwise), excluding its conflict-of-law provisions.
+ With respect to disputes in which at least one party is a citizen of,
+ or an entity chartered or registered to do business in the United
+ States of America, any litigation relating to this License shall be
+ subject to the jurisdiction of the Federal Courts of the Northern
+ District of California, with venue lying in Santa Clara County,
+ California, with the losing party responsible for costs, including
+ without limitation, court costs and reasonable attorneys' fees and
+ expenses. The application of the United Nations Convention on
+ Contracts for the International Sale of Goods is expressly excluded.
+ Any law or regulation which provides that the language of a contract
+ shall be construed against the drafter shall not apply to this
+ License.
+
+12. RESPONSIBILITY FOR CLAIMS.
+
+ As between Initial Developer and the Contributors, each party is
+ responsible for claims and damages arising, directly or indirectly,
+ out of its utilization of rights under this License and You agree to
+ work with Initial Developer and Contributors to distribute such
+ responsibility on an equitable basis. Nothing herein is intended or
+ shall be deemed to constitute any admission of liability.
+
+13. MULTIPLE-LICENSED CODE.
+
+ Initial Developer may designate portions of the Covered Code as
+ "Multiple-Licensed". "Multiple-Licensed" means that the Initial
+ Developer permits you to utilize portions of the Covered Code under
+ Your choice of the NPL or the alternative licenses, if any, specified
+ by the Initial Developer in the file described in Exhibit A.
+
+EXHIBIT A -Mozilla Public License.
+
+ ``The contents of this file are subject to the Mozilla Public License
+ Version 1.1 (the "License"); you may not use this file except in
+ compliance with the License. You may obtain a copy of the License at
+ http://www.mozilla.org/MPL/
+
+ Software distributed under the License is distributed on an "AS IS"
+ basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ License for the specific language governing rights and limitations
+ under the License.
+
+ The Original Code is ______________________________________.
+
+ The Initial Developer of the Original Code is ________________________.
+ Portions created by ______________________ are Copyright (C) ______
+ _______________________. All Rights Reserved.
+
+ Contributor(s): ______________________________________.
+
+ Alternatively, the contents of this file may be used under the terms
+ of the _____ license (the "[___] License"), in which case the
+ provisions of [______] License are applicable instead of those
+ above. If you wish to allow use of your version of this file only
+ under the terms of the [____] License and not to allow others to use
+ your version of this file under the MPL, indicate your decision by
+ deleting the provisions above and replace them with the notice and
+ other provisions required by the [___] License. If you do not delete
+ the provisions above, a recipient may use your version of this file
+ under either the MPL or the [___] License."
+
+ [NOTE: The text of this Exhibit A may differ slightly from the text of
+ the notices in the Source Code files of the Original Code. You should
+ use the text of this Exhibit A rather than the text found in the
+ Original Code Source Code for Your Modifications.]
+
+
+===============================================================================
+
+For the JAX-WS Reference Implementation component:
+
+COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
+
+
+ 1. Definitions.
+
+ 1.1. "Contributor" means each individual or entity that
+ creates or contributes to the creation of Modifications.
+
+ 1.2. "Contributor Version" means the combination of the
+ Original Software, prior Modifications used by a
+ Contributor (if any), and the Modifications made by that
+ particular Contributor.
+
+ 1.3. "Covered Software" means (a) the Original Software, or
+ (b) Modifications, or (c) the combination of files
+ containing Original Software with files containing
+ Modifications, in each case including portions thereof.
+
+ 1.4. "Executable" means the Covered Software in any form
+ other than Source Code.
+
+ 1.5. "Initial Developer" means the individual or entity
+ that first makes Original Software available under this
+ License.
+
+ 1.6. "Larger Work" means a work which combines Covered
+ Software or portions thereof with code not governed by the
+ terms of this License.
+
+ 1.7. "License" means this document.
+
+ 1.8. "Licensable" means having the right to grant, to the
+ maximum extent possible, whether at the time of the initial
+ grant or subsequently acquired, any and all of the rights
+ conveyed herein.
+
+ 1.9. "Modifications" means the Source Code and Executable
+ form of any of the following:
+
+ A. Any file that results from an addition to,
+ deletion from or modification of the contents of a
+ file containing Original Software or previous
+ Modifications;
+
+ B. Any new file that contains any part of the
+ Original Software or previous Modification; or
+
+ C. Any new file that is contributed or otherwise made
+ available under the terms of this License.
+
+ 1.10. "Original Software" means the Source Code and
+ Executable form of computer software code that is
+ originally released under this License.
+
+ 1.11. "Patent Claims" means any patent claim(s), now owned
+ or hereafter acquired, including without limitation,
+ method, process, and apparatus claims, in any patent
+ Licensable by grantor.
+
+ 1.12. "Source Code" means (a) the common form of computer
+ software code in which modifications are made and (b)
+ associated documentation included in or with such code.
+
+ 1.13. "You" (or "Your") means an individual or a legal
+ entity exercising rights under, and complying with all of
+ the terms of, this License. For legal entities, "You"
+ includes any entity which controls, is controlled by, or is
+ under common control with You. For purposes of this
+ definition, "control" means (a) the power, direct or
+ indirect, to cause the direction or management of such
+ entity, whether by contract or otherwise, or (b) ownership
+ of more than fifty percent (50%) of the outstanding shares
+ or beneficial ownership of such entity.
+
+ 2. License Grants.
+
+ 2.1. The Initial Developer Grant.
+
+ Conditioned upon Your compliance with Section 3.1 below and
+ subject to third party intellectual property claims, the
+ Initial Developer hereby grants You a world-wide,
+ royalty-free, non-exclusive license:
+
+ (a) under intellectual property rights (other than
+ patent or trademark) Licensable by Initial Developer,
+ to use, reproduce, modify, display, perform,
+ sublicense and distribute the Original Software (or
+ portions thereof), with or without Modifications,
+ and/or as part of a Larger Work; and
+
+ (b) under Patent Claims infringed by the making,
+ using or selling of Original Software, to make, have
+ made, use, practice, sell, and offer for sale, and/or
+ otherwise dispose of the Original Software (or
+ portions thereof).
+
+ (c) The licenses granted in Sections 2.1(a) and (b)
+ are effective on the date Initial Developer first
+ distributes or otherwise makes the Original Software
+ available to a third party under the terms of this
+ License.
+
+ (d) Notwithstanding Section 2.1(b) above, no patent
+ license is granted: (1) for code that You delete from
+ the Original Software, or (2) for infringements
+ caused by: (i) the modification of the Original
+ Software, or (ii) the combination of the Original
+ Software with other software or devices.
+
+ 2.2. Contributor Grant.
+
+ Conditioned upon Your compliance with Section 3.1 below and
+ subject to third party intellectual property claims, each
+ Contributor hereby grants You a world-wide, royalty-free,
+ non-exclusive license:
+
+ (a) under intellectual property rights (other than
+ patent or trademark) Licensable by Contributor to
+ use, reproduce, modify, display, perform, sublicense
+ and distribute the Modifications created by such
+ Contributor (or portions thereof), either on an
+ unmodified basis, with other Modifications, as
+ Covered Software and/or as part of a Larger Work; and
+
+
+ (b) under Patent Claims infringed by the making,
+ using, or selling of Modifications made by that
+ Contributor either alone and/or in combination with
+ its Contributor Version (or portions of such
+ combination), to make, use, sell, offer for sale,
+ have made, and/or otherwise dispose of: (1)
+ Modifications made by that Contributor (or portions
+ thereof); and (2) the combination of Modifications
+ made by that Contributor with its Contributor Version
+ (or portions of such combination).
+
+ (c) The licenses granted in Sections 2.2(a) and
+ 2.2(b) are effective on the date Contributor first
+ distributes or otherwise makes the Modifications
+ available to a third party.
+
+ (d) Notwithstanding Section 2.2(b) above, no patent
+ license is granted: (1) for any code that Contributor
+ has deleted from the Contributor Version; (2) for
+ infringements caused by: (i) third party
+ modifications of Contributor Version, or (ii) the
+ combination of Modifications made by that Contributor
+ with other software (except as part of the
+ Contributor Version) or other devices; or (3) under
+ Patent Claims infringed by Covered Software in the
+ absence of Modifications made by that Contributor.
+
+ 3. Distribution Obligations.
+
+ 3.1. Availability of Source Code.
+
+ Any Covered Software that You distribute or otherwise make
+ available in Executable form must also be made available in
+ Source Code form and that Source Code form must be
+ distributed only under the terms of this License. You must
+ include a copy of this License with every copy of the
+ Source Code form of the Covered Software You distribute or
+ otherwise make available. You must inform recipients of any
+ such Covered Software in Executable form as to how they can
+ obtain such Covered Software in Source Code form in a
+ reasonable manner on or through a medium customarily used
+ for software exchange.
+
+ 3.2. Modifications.
+
+ The Modifications that You create or to which You
+ contribute are governed by the terms of this License. You
+ represent that You believe Your Modifications are Your
+ original creation(s) and/or You have sufficient rights to
+ grant the rights conveyed by this License.
+
+ 3.3. Required Notices.
+
+ You must include a notice in each of Your Modifications
+ that identifies You as the Contributor of the Modification.
+ You may not remove or alter any copyright, patent or
+ trademark notices contained within the Covered Software, or
+ any notices of licensing or any descriptive text giving
+ attribution to any Contributor or the Initial Developer.
+
+ 3.4. Application of Additional Terms.
+
+ You may not offer or impose any terms on any Covered
+ Software in Source Code form that alters or restricts the
+ applicable version of this License or the recipients'
+ rights hereunder. You may choose to offer, and to charge a
+ fee for, warranty, support, indemnity or liability
+ obligations to one or more recipients of Covered Software.
+ However, you may do so only on Your own behalf, and not on
+ behalf of the Initial Developer or any Contributor. You
+ must make it absolutely clear that any such warranty,
+ support, indemnity or liability obligation is offered by
+ You alone, and You hereby agree to indemnify the Initial
+ Developer and every Contributor for any liability incurred
+ by the Initial Developer or such Contributor as a result of
+ warranty, support, indemnity or liability terms You offer.
+
+
+ 3.5. Distribution of Executable Versions.
+
+ You may distribute the Executable form of the Covered
+ Software under the terms of this License or under the terms
+ of a license of Your choice, which may contain terms
+ different from this License, provided that You are in
+ compliance with the terms of this License and that the
+ license for the Executable form does not attempt to limit
+ or alter the recipient's rights in the Source Code form
+ from the rights set forth in this License. If You
+ distribute the Covered Software in Executable form under a
+ different license, You must make it absolutely clear that
+ any terms which differ from this License are offered by You
+ alone, not by the Initial Developer or Contributor. You
+ hereby agree to indemnify the Initial Developer and every
+ Contributor for any liability incurred by the Initial
+ Developer or such Contributor as a result of any such terms
+ You offer.
+
+ 3.6. Larger Works.
+
+ You may create a Larger Work by combining Covered Software
+ with other code not governed by the terms of this License
+ and distribute the Larger Work as a single product. In such
+ a case, You must make sure the requirements of this License
+ are fulfilled for the Covered Software.
+
+ 4. Versions of the License.
+
+ 4.1. New Versions.
+
+ Sun Microsystems, Inc. is the initial license steward and
+ may publish revised and/or new versions of this License
+ from time to time. Each version will be given a
+ distinguishing version number. Except as provided in
+ Section 4.3, no one other than the license steward has the
+ right to modify this License.
+
+ 4.2. Effect of New Versions.
+
+ You may always continue to use, distribute or otherwise
+ make the Covered Software available under the terms of the
+ version of the License under which You originally received
+ the Covered Software. If the Initial Developer includes a
+ notice in the Original Software prohibiting it from being
+ distributed or otherwise made available under any
+ subsequent version of the License, You must distribute and
+ make the Covered Software available under the terms of the
+ version of the License under which You originally received
+ the Covered Software. Otherwise, You may also choose to
+ use, distribute or otherwise make the Covered Software
+ available under the terms of any subsequent version of the
+ License published by the license steward.
+
+ 4.3. Modified Versions.
+
+ When You are an Initial Developer and You want to create a
+ new license for Your Original Software, You may create and
+ use a modified version of this License if You: (a) rename
+ the license and remove any references to the name of the
+ license steward (except to note that the license differs
+ from this License); and (b) otherwise make it clear that
+ the license contains terms which differ from this License.
+
+
+ 5. DISCLAIMER OF WARRANTY.
+
+ COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS"
+ BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
+ INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED
+ SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR
+ PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND
+ PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY
+ COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE
+ INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF
+ ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF
+ WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF
+ ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS
+ DISCLAIMER.
+
+ 6. TERMINATION.
+
+ 6.1. This License and the rights granted hereunder will
+ terminate automatically if You fail to comply with terms
+ herein and fail to cure such breach within 30 days of
+ becoming aware of the breach. Provisions which, by their
+ nature, must remain in effect beyond the termination of
+ this License shall survive.
+
+ 6.2. If You assert a patent infringement claim (excluding
+ declaratory judgment actions) against Initial Developer or
+ a Contributor (the Initial Developer or Contributor against
+ whom You assert such claim is referred to as "Participant")
+ alleging that the Participant Software (meaning the
+ Contributor Version where the Participant is a Contributor
+ or the Original Software where the Participant is the
+ Initial Developer) directly or indirectly infringes any
+ patent, then any and all rights granted directly or
+ indirectly to You by such Participant, the Initial
+ Developer (if the Initial Developer is not the Participant)
+ and all Contributors under Sections 2.1 and/or 2.2 of this
+ License shall, upon 60 days notice from Participant
+ terminate prospectively and automatically at the expiration
+ of such 60 day notice period, unless if within such 60 day
+ period You withdraw Your claim with respect to the
+ Participant Software against such Participant either
+ unilaterally or pursuant to a written agreement with
+ Participant.
+
+ 6.3. In the event of termination under Sections 6.1 or 6.2
+ above, all end user licenses that have been validly granted
+ by You or any distributor hereunder prior to termination
+ (excluding licenses granted to You by any distributor)
+ shall survive termination.
+
+ 7. LIMITATION OF LIABILITY.
+
+ UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
+ (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE
+ INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF
+ COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE
+ LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT
+ LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK
+ STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER
+ COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN
+ INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF
+ LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL
+ INJURY RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT
+ APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO
+ NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR
+ CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT
+ APPLY TO YOU.
+
+ 8. U.S. GOVERNMENT END USERS.
+
+ The Covered Software is a "commercial item," as that term is
+ defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial
+ computer software" (as that term is defined at 48 C.F.R.
+ 252.227-7014(a)(1)) and "commercial computer software
+ documentation" as such terms are used in 48 C.F.R. 12.212 (Sept.
+ 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1
+ through 227.7202-4 (June 1995), all U.S. Government End Users
+ acquire Covered Software with only those rights set forth herein.
+ This U.S. Government Rights clause is in lieu of, and supersedes,
+ any other FAR, DFAR, or other clause or provision that addresses
+ Government rights in computer software under this License.
+
+ 9. MISCELLANEOUS.
+
+ This License represents the complete agreement concerning subject
+ matter hereof. If any provision of this License is held to be
+ unenforceable, such provision shall be reformed only to the
+ extent necessary to make it enforceable. This License shall be
+ governed by the law of the jurisdiction specified in a notice
+ contained within the Original Software (except to the extent
+ applicable law, if any, provides otherwise), excluding such
+ jurisdiction's conflict-of-law provisions. Any litigation
+ relating to this License shall be subject to the jurisdiction of
+ the courts located in the jurisdiction and venue specified in a
+ notice contained within the Original Software, with the losing
+ party responsible for costs, including, without limitation, court
+ costs and reasonable attorneys' fees and expenses. The
+ application of the United Nations Convention on Contracts for the
+ International Sale of Goods is expressly excluded. Any law or
+ regulation which provides that the language of a contract shall
+ be construed against the drafter shall not apply to this License.
+ You agree that You alone are responsible for compliance with the
+ United States export administration regulations (and the export
+ control laws and regulation of any other countries) when You use,
+ distribute or otherwise make available any Covered Software.
+
+ 10. RESPONSIBILITY FOR CLAIMS.
+
+ As between Initial Developer and the Contributors, each party is
+ responsible for claims and damages arising, directly or
+ indirectly, out of its utilization of rights under this License
+ and You agree to work with Initial Developer and Contributors to
+ distribute such responsibility on an equitable basis. Nothing
+ herein is intended or shall be deemed to constitute any admission
+ of liability.
+
diff --git a/tags/java/tsss-demo/runtime/itest/plugin/NOTICE.txt b/tags/java/tsss-demo/runtime/itest/plugin/NOTICE.txt
new file mode 100644
index 0000000000..d83ebbe236
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/plugin/NOTICE.txt
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/runtime/itest/plugin/pom.xml b/tags/java/tsss-demo/runtime/itest/plugin/pom.xml
new file mode 100644
index 0000000000..b196938b57
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/plugin/pom.xml
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany</groupId>
+ <artifactId>sca</artifactId>
+ <version>1.0-incubating</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>tuscany-itest-plugin</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ <packaging>maven-plugin</packaging>
+ <name>Apache Tuscany Integration Test Plugin</name>
+ <description>A plugin for Apache Maven that simplifies integration testing of SCA components.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact</artifactId>
+ <version>2.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>surefire-api</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>surefire-junit</artifactId>
+ <version>2.0</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-core</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+ <distributionManagement>
+ <site>
+ <id>apache.website</id>
+ <url>scp://people.apache.org/www/incubator.apache.org/tuscany/plugins/tuscany-itest-plugin</url>
+ </site>
+ </distributionManagement>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>2.2</version>
+ </plugin>
+ </plugins>
+ </build>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>2.2</version>
+ </plugin>
+ </plugins>
+ </reporting>
+</project>
diff --git a/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/Dependency.java b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/Dependency.java
new file mode 100644
index 0000000000..4f3f6b0f10
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/Dependency.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.plugin.itest;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+
+/**
+ * Represents a configured tuscany dependency for boot and extension libraries.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Dependency {
+
+ /**
+ * JAR type artifact.
+ */
+ private static final String TYPE_JAR = "jar";
+
+ /**
+ * Group Id that is injected in from configuration.
+ */
+ private String groupId;
+
+ /**
+ * Artifact Id that is injected in from configuration.
+ */
+ private String artifactId;
+
+ /**
+ * Version that is injected in from configuration.
+ */
+ private String version;
+
+ /**
+ * Default constructor.
+ */
+ public Dependency() {
+ }
+
+ /**
+ * Initializes the field.
+ *
+ * @param groupId Group id.
+ * @param artifactId Artifact id.
+ * @param version Artifact version.
+ */
+ public Dependency(String groupId, String artifactId, String version) {
+ super();
+ this.groupId = groupId;
+ this.artifactId = artifactId;
+ this.version = version;
+ }
+
+ /**
+ * Gets the artifact using the specified artifact factory.
+ *
+ * @param artifactFactory Artifact factory to use.
+ * @return Artifact identified by the dependency.
+ */
+ public Artifact getArtifact(ArtifactFactory artifactFactory) {
+ return artifactFactory.createArtifact(groupId, artifactId, version, Artifact.SCOPE_RUNTIME, TYPE_JAR);
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedArtifactRepository.java b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedArtifactRepository.java
new file mode 100644
index 0000000000..282099062d
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedArtifactRepository.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.plugin.itest;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.metadata.ResolutionGroup;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MavenEmbeddedArtifactRepository implements org.apache.tuscany.spi.services.artifact.ArtifactRepository {
+ public static final URI COMPONENT_NAME = URI.create("MavenEmbeddedArtifactRepository");
+
+ private ArtifactFactory artifactFactory;
+ private ArtifactResolver resolver;
+ private ArtifactMetadataSource metadataSource;
+ private ArtifactRepository localRepository;
+ private List remoteRepositories;
+
+ public MavenEmbeddedArtifactRepository(ArtifactFactory artifactFactory,
+ ArtifactResolver resolver,
+ ArtifactMetadataSource metadataSource,
+ ArtifactRepository localRepository,
+ List remoteRepositories) {
+ this.artifactFactory = artifactFactory;
+ this.resolver = resolver;
+ this.metadataSource = metadataSource;
+ this.localRepository = localRepository;
+ this.remoteRepositories = remoteRepositories;
+ }
+
+ public void resolve(org.apache.tuscany.spi.services.artifact.Artifact artifact) {
+ resolveTransitively(artifact);
+ }
+
+ public void resolve(Collection artifacts) {
+ for (Object a : artifacts) {
+ resolve((Artifact) a);
+ }
+ }
+
+ /**
+ * Resolves the dependencies transitively.
+ *
+ * @param rootArtifact Artifact whose dependencies need to be resolved.
+ * @return true if all dependencies were resolved
+ */
+ public boolean resolveTransitively(org.apache.tuscany.spi.services.artifact.Artifact rootArtifact) {
+
+ Artifact mavenRootArtifact =
+ artifactFactory.createArtifact(rootArtifact.getGroup(), rootArtifact.getName(), rootArtifact
+ .getVersion(), Artifact.SCOPE_RUNTIME, rootArtifact.getType());
+
+ try {
+
+ if (resolve(mavenRootArtifact)) {
+ rootArtifact.setUrl(mavenRootArtifact.getFile().toURL());
+ return resolveDependencies(rootArtifact, mavenRootArtifact);
+ } else {
+ return false;
+ }
+ } catch (MalformedURLException ex) {
+ throw new IllegalArgumentException(ex);
+ }
+
+ }
+
+ /*
+ * Resolves the artifact.
+ */
+ private boolean resolve(Artifact mavenRootArtifact) {
+
+ try {
+ resolver.resolve(mavenRootArtifact, remoteRepositories, localRepository);
+ return true;
+ } catch (ArtifactResolutionException ex) {
+ return false;
+ } catch (ArtifactNotFoundException ex) {
+ return false;
+ }
+
+ }
+
+ /*
+ * Resolves transitive dependencies.
+ */
+ private boolean resolveDependencies(org.apache.tuscany.spi.services.artifact.Artifact rootArtifact,
+ Artifact mavenRootArtifact) {
+
+ try {
+
+ ResolutionGroup resolutionGroup = metadataSource.retrieve(mavenRootArtifact,
+ localRepository,
+ remoteRepositories);
+
+ ArtifactResolutionResult result = resolver.resolveTransitively(resolutionGroup.getArtifacts(),
+ mavenRootArtifact,
+ remoteRepositories,
+ localRepository,
+ metadataSource);
+
+ // Add the artifacts to the deployment unit
+ for (Object obj : result.getArtifacts()) {
+ Artifact depArtifact = (Artifact) obj;
+ org.apache.tuscany.spi.services.artifact.Artifact artifact =
+ new org.apache.tuscany.spi.services.artifact.Artifact();
+ artifact.setName(depArtifact.getArtifactId());
+ artifact.setGroup(depArtifact.getGroupId());
+ artifact.setType(depArtifact.getType());
+ artifact.setClassifier(depArtifact.getClassifier());
+ artifact.setUrl(depArtifact.getFile().toURL());
+ artifact.setVersion(depArtifact.getVersion());
+ rootArtifact.addDependency(artifact);
+ }
+
+ } catch (ArtifactMetadataRetrievalException ex) {
+ return false;
+ } catch (MalformedURLException ex) {
+ throw new IllegalArgumentException(ex);
+ } catch (ArtifactResolutionException ex) {
+ return false;
+ } catch (ArtifactNotFoundException ex) {
+ return false;
+ }
+
+ return true;
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java
new file mode 100644
index 0000000000..407b07e72e
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.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.plugin.itest;
+
+import java.net.URI;
+import java.util.Collection;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.GroupInitializationException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.deployer.Deployer;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.services.artifact.ArtifactRepository;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+import org.apache.maven.plugin.logging.Log;
+import org.apache.tuscany.core.runtime.AbstractRuntime;
+import org.apache.tuscany.core.component.SimpleWorkContext;
+import org.apache.tuscany.core.implementation.PojoWorkContextTunnel;
+import org.apache.tuscany.host.MonitorFactory;
+import org.apache.tuscany.host.runtime.InitializationException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MavenEmbeddedRuntime extends AbstractRuntime<MavenRuntimeInfo> {
+ private ArtifactRepository artifactRepository;
+
+ public MavenEmbeddedRuntime(Log log) {
+ super(MavenRuntimeInfo.class);
+ MonitorFactory monitorFactory = new MavenMonitorFactory(log);
+ setMonitorFactory(monitorFactory);
+ }
+
+ protected void registerBaselineSystemComponents() throws InitializationException {
+ super.registerBaselineSystemComponents();
+ registerSystemComponent(MavenEmbeddedArtifactRepository.COMPONENT_NAME,
+ ArtifactRepository.class,
+ artifactRepository);
+ }
+
+ public void setArtifactRepository(ArtifactRepository artifactRepository) {
+ this.artifactRepository = artifactRepository;
+ }
+
+ public Collection<Component> deployTestScdl(ComponentDefinition<CompositeImplementation> definition)
+ throws Exception {
+ Deployer deployer = getDeployer();
+ return deployer.deploy(null, definition);
+ }
+
+ public void startContext(URI compositeId) throws GroupInitializationException {
+ getScopeRegistry().getScopeContainer(Scope.COMPOSITE).startContext(compositeId, compositeId);
+ }
+
+ public void executeTest(URI contextId, URI componentId, Operation<?> operation) throws Exception {
+ Component testComponent = getComponentManager().getComponent(componentId);
+ TargetInvoker targetInvoker = testComponent.createTargetInvoker("testService", operation);
+ getWorkContext().setIdentifier(Scope.COMPOSITE, contextId);
+ WorkContext workContext = new SimpleWorkContext();
+ workContext.setIdentifier(Scope.COMPOSITE, contextId);
+ PojoWorkContextTunnel.setThreadWorkContext(workContext);
+ try {
+ targetInvoker.invokeTarget(null, TargetInvoker.NONE, workContext);
+ } finally {
+ getWorkContext().clearIdentifier(Scope.COMPOSITE);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenMonitorFactory.java b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenMonitorFactory.java
new file mode 100644
index 0000000000..0fd4aa7d59
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenMonitorFactory.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.plugin.itest;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.Map;
+import java.util.ResourceBundle;
+import java.util.HashMap;
+import java.util.logging.Level;
+import java.text.MessageFormat;
+
+import org.apache.maven.plugin.logging.Log;
+
+import org.apache.tuscany.core.monitor.ProxyMonitorFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MavenMonitorFactory extends ProxyMonitorFactory {
+ private final Log log;
+
+ public MavenMonitorFactory(Log log) {
+ this.log = log;
+ Map<String, Object> configProperties = new HashMap<String, Object>();
+ configProperties.put("defaultLevel", Level.FINEST);
+ initInternal(configProperties);
+ }
+
+ protected <T> InvocationHandler createInvocationHandler(Class<T> monitorInterface, Map<String, Level> levels) {
+ ResourceBundle bundle = locateBundle(monitorInterface, bundleName);
+ return new MonitorHandler(monitorInterface.getName(), levels, bundle);
+ }
+
+ private class MonitorHandler implements InvocationHandler {
+ private final String monitorName;
+ private final Map<String, Level> methodLevels;
+ private final ResourceBundle bundle;
+
+ public MonitorHandler(String monitorName, Map<String, Level> methodLevels, ResourceBundle bundle) {
+ this.monitorName = monitorName;
+ this.methodLevels = methodLevels;
+ this.bundle = bundle;
+ }
+
+ public Object invoke(Object object, Method method, Object[] objects) throws Throwable {
+ String sourceMethod = method.getName();
+ Level level = methodLevels.get(sourceMethod);
+ if (level == Level.OFF) {
+ return null;
+ }
+
+ int value = level.intValue();
+ if (isLogEnabled(value)) {
+ String key = monitorName + '#' + sourceMethod;
+ String message;
+ if (bundle != null) {
+ message = bundle.getString(key);
+ } else {
+ message = null;
+ }
+ if (message != null) {
+ message = MessageFormat.format(message, objects);
+ } else {
+ StringBuilder builder = new StringBuilder();
+ builder.append(key).append(":");
+ for (Object o : objects) {
+ builder.append(' ');
+ if (o instanceof Throwable) {
+ builder.append(formatException((Throwable) o));
+ } else {
+ builder.append(String.valueOf(o));
+ }
+ }
+ message = builder.toString();
+ }
+ Throwable cause = getFirstException(objects);
+ if (cause != null) {
+ if (value >= Level.SEVERE.intValue()) {
+ log.error(message, cause);
+ } else if (value >= Level.WARNING.intValue()) {
+ log.warn(message, cause);
+ } else if (value >= Level.INFO.intValue()) {
+ log.info(message, cause);
+ } else if (value >= Level.FINEST.intValue()) {
+ log.debug(message, cause);
+ }
+ } else {
+ if (value >= Level.SEVERE.intValue()) {
+ log.error(message);
+ } else if (value >= Level.WARNING.intValue()) {
+ log.warn(message);
+ } else if (value >= Level.INFO.intValue()) {
+ log.info(message);
+ } else if (value >= Level.FINEST.intValue()) {
+ log.debug(message);
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private boolean isLogEnabled(int value) {
+ return log.isDebugEnabled() && value >= Level.FINEST.intValue()
+ || log.isInfoEnabled() && value >= Level.INFO.intValue()
+ || log.isWarnEnabled() && value >= Level.WARNING.intValue()
+ || log.isErrorEnabled() && value >= Level.SEVERE.intValue();
+ }
+
+ private Throwable getFirstException(Object[] objects) {
+ for (Object object : objects) {
+ if (object instanceof Throwable) {
+ return (Throwable) object;
+ }
+ }
+ return null;
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenRuntimeInfo.java b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenRuntimeInfo.java
new file mode 100644
index 0000000000..f6a4e1f52c
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenRuntimeInfo.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.plugin.itest;
+
+import java.io.File;
+import java.net.URL;
+import java.net.URI;
+
+import org.apache.tuscany.host.RuntimeInfo;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MavenRuntimeInfo implements RuntimeInfo {
+ public static final URI COMPONENT_NAME = URI.create("MavenRuntimeInfo");
+
+ public File getInstallDirectory() {
+ throw new UnsupportedOperationException();
+ }
+
+ public File getApplicationRootDirectory() {
+ throw new UnsupportedOperationException();
+ }
+
+ public URL getBaseURL() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean isOnline() {
+ throw new UnsupportedOperationException();
+ }
+
+ public URI getDomain() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getRuntimeId() {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSet.java b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSet.java
new file mode 100644
index 0000000000..9e3d0d3f55
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSet.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.plugin.itest;
+
+import java.util.Collection;
+import java.net.URI;
+
+import org.apache.maven.surefire.testset.SurefireTestSet;
+import org.apache.maven.surefire.testset.TestSetFailedException;
+import org.apache.maven.surefire.report.ReporterManager;
+import org.apache.maven.surefire.report.ReportEntry;
+import org.apache.maven.surefire.report.StackTraceWriter;
+import org.apache.maven.surefire.report.PojoStackTraceWriter;
+
+import org.apache.tuscany.spi.model.Operation;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SCATestSet implements SurefireTestSet {
+ private final MavenEmbeddedRuntime runtime;
+ private final String name;
+ private final URI contextId;
+ private final URI componentId;
+ private final Collection<? extends Operation<?>> operations;
+
+ public SCATestSet(MavenEmbeddedRuntime runtime,
+ String name,
+ URI contextId,
+ URI uri,
+ Collection<? extends Operation<?>> operations) {
+ this.runtime = runtime;
+ this.name = name;
+ this.contextId = contextId;
+ this.componentId = uri;
+ this.operations = operations;
+ }
+
+ public void execute(ReporterManager reporterManager, ClassLoader classLoader) throws TestSetFailedException {
+ for (Operation<?> operation : operations) {
+ String operationName = operation.getName();
+ reporterManager.testStarting(new ReportEntry(this, operationName, name));
+ try {
+ runtime.executeTest(contextId, componentId, operation);
+ reporterManager.testSucceeded(new ReportEntry(this, operationName, name));
+ } catch (Exception e) {
+ StackTraceWriter stw = new PojoStackTraceWriter(name, operationName, e);
+ reporterManager.testFailed(new ReportEntry(this, operationName, name, stw));
+ throw new TestSetFailedException(e);
+ }
+ }
+ }
+
+ public int getTestCount() {
+ return operations.size();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Class getTestClass() {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSuite.java b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSuite.java
new file mode 100644
index 0000000000..1029b70733
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/SCATestSuite.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.plugin.itest;
+
+import java.util.Map;
+import java.util.HashMap;
+
+import org.apache.maven.surefire.suite.SurefireTestSuite;
+import org.apache.maven.surefire.report.ReporterManager;
+import org.apache.maven.surefire.report.ReporterException;
+import org.apache.maven.surefire.report.ReportEntry;
+import org.apache.maven.surefire.testset.TestSetFailedException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SCATestSuite implements SurefireTestSuite {
+ private final Map<String, SCATestSet> testSets = new HashMap<String, SCATestSet>();
+ private int testSetCount = 0;
+ private int testCount = 0;
+
+ public void add(SCATestSet testSet) {
+ testSets.put(testSet.getName(), testSet);
+ testSetCount += 1;
+ testCount += testSet.getTestCount();
+ }
+
+ public int getNumTests() {
+ return testCount;
+ }
+
+ public int getNumTestSets() {
+ return testSetCount;
+ }
+
+ public void execute(ReporterManager reporterManager, ClassLoader classLoader)
+ throws ReporterException, TestSetFailedException {
+ for (SCATestSet testSet : testSets.values()) {
+ execute(testSet, reporterManager, classLoader);
+ }
+ }
+
+ public void execute(String name, ReporterManager reporterManager, ClassLoader classLoader)
+ throws ReporterException, TestSetFailedException {
+ SCATestSet testSet = testSets.get(name);
+ if (testSet == null) {
+ throw new TestSetFailedException("Suite does not contain TestSet: " + name);
+ }
+ execute(testSet, reporterManager, classLoader);
+ }
+
+ protected void execute(SCATestSet testSet, ReporterManager reporterManager, ClassLoader classLoader)
+ throws ReporterException, TestSetFailedException {
+ reporterManager.testSetStarting(new ReportEntry(this, testSet.getName(), "Starting"));
+ testSet.execute(reporterManager, classLoader);
+ reporterManager.testSetCompleted(new ReportEntry(this, testSet.getName(), "Completed"));
+ reporterManager.reset();
+ }
+
+ public Map locateTestSets(ClassLoader classLoader) throws TestSetFailedException {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyITestMojo.java b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyITestMojo.java
new file mode 100644
index 0000000000..78cd505a67
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyITestMojo.java
@@ -0,0 +1,429 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.plugin.itest;
+
+import java.io.File;
+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.Properties;
+import java.util.Collection;
+import java.util.Set;
+import java.util.HashSet;
+
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.metadata.ResolutionGroup;
+import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.surefire.report.BriefConsoleReporter;
+import org.apache.maven.surefire.report.BriefFileReporter;
+import org.apache.maven.surefire.report.Reporter;
+import org.apache.maven.surefire.report.ReporterException;
+import org.apache.maven.surefire.report.ReporterManager;
+import org.apache.maven.surefire.suite.SurefireTestSuite;
+import org.apache.maven.surefire.testset.TestSetFailedException;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+import org.apache.tuscany.api.annotation.LogLevel;
+import org.apache.tuscany.host.runtime.InitializationException;
+import org.apache.tuscany.sca.plugin.itest.implementation.junit.ImplementationJUnit;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.deployer.CompositeClassLoader;
+
+/**
+ * Integration-tests an SCA composite by running it in local copy of Apache Tuscany
+ * and calling JUnit-based test components to exercise it.
+ *
+ * @version $Rev$ $Date$
+ * @goal test
+ * @phase integration-test
+ */
+public class TuscanyITestMojo extends AbstractMojo {
+ /**
+ * The directory where reports will be written.
+ *
+ * @parameter expression="${project.build.directory}/surefire-reports"
+ */
+ public File reportsDirectory;
+
+ /**
+ * Whether to trim the stack trace in the reports to just the lines within
+ * the test, or show the full trace.
+ *
+ * @parameter expression="${trimStackTrace}" default-value="true"
+ */
+ public boolean trimStackTrace;
+
+ /**
+ * The directory containing generated test classes of the project being tested.
+ *
+ * @parameter expression="${project.build.testOutputDirectory}"
+ * @required
+ */
+ public File testClassesDirectory;
+
+ /**
+ * The SCA domain in which to deploy the test components.
+ *
+ * @parameter expression="itest://localhost/testDomain/"
+ * @required
+ */
+ public String testDomain;
+
+ /**
+ * The name of the component that will be implemented by the test harness composite.
+ *
+ * @parameter expression="testHarness"
+ * @required
+ */
+ public String testComponentName;
+
+ /**
+ * The location if the SCDL that defines the test harness composite.
+ * The source for this would normally be placed in the test/resources
+ * directory and be copied by the resource plugin; this allows property
+ * substitution if required.
+ *
+ * @parameter expression="${project.build.testOutputDirectory}/itest.scdl"
+ */
+ public File testScdl;
+
+ /**
+ * The location of the SCDL that configures the Apache Tuscany runtime.
+ * This allows the default runtime configuration supplied in this plugin
+ * to be overridden.
+ *
+ * @parameter
+ */
+ public URL systemScdl;
+
+ /**
+ * Set of extension artifacts that should be deployed to the runtime.
+ *
+ * @parameter
+ */
+ public Dependency[] extensions;
+
+ /**
+ * @parameter expression="${project.testClasspathElements}"
+ * @required
+ * @readonly
+ */
+ public List<String> testClassPath;
+
+ /**
+ * Used to look up Artifacts in the remote repository.
+ *
+ * @parameter expression="${component.org.apache.maven.artifact.resolver.ArtifactResolver}"
+ * @required
+ * @readonly
+ */
+ public ArtifactResolver resolver;
+
+ /**
+ * Used to look up Artifacts in the remote repository.
+ *
+ * @parameter expression="${component.org.apache.maven.artifact.metadata.ArtifactMetadataSource}"
+ * @required
+ * @readonly
+ */
+ public ArtifactMetadataSource metadataSource;
+
+ /**
+ * Location of the local repository.
+ *
+ * @parameter expression="${localRepository}"
+ * @readonly
+ * @required
+ */
+ public ArtifactRepository localRepository;
+
+ /**
+ * List of Remote Repositories used by the resolver
+ *
+ * @parameter expression="${project.remoteArtifactRepositories}"
+ * @readonly
+ * @required
+ */
+ public List remoteRepositories;
+
+ /**
+ * Used to look up Artifacts in the remote repository.
+ *
+ * @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}"
+ * @required
+ * @readonly
+ */
+ public ArtifactFactory artifactFactory;
+ private MojoMonitor monitor;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ Log log = getLog();
+ if (!testScdl.exists()) {
+ log.info("No itest SCDL found, skipping integration tests");
+ return;
+ }
+
+ log.info("Starting Tuscany...");
+ ClassLoader cl = createHostClassLoader(getClass().getClassLoader(), extensions);
+ MavenEmbeddedRuntime runtime = createRuntime(cl);
+ MavenMonitorFactory monitorFactory = new MavenMonitorFactory(log);
+ runtime.setMonitorFactory(monitorFactory);
+ monitor = monitorFactory.getMonitor(MojoMonitor.class);
+ try {
+ runtime.initialize();
+ } catch (InitializationException e) {
+ throw new MojoExecutionException("Error initializing Tuscany runtime", e);
+ }
+ try {
+ SurefireTestSuite testSuite;
+ log.info("Deploying test SCDL from " + testScdl);
+ try {
+ // fixme this should probably be an isolated classloader
+ ClassLoader testClassLoader = createTestClassLoader(getClass().getClassLoader());
+
+ URI domain = URI.create(testDomain);
+ String harnessComponentName = testComponentName;
+ URI componentName = domain.resolve(harnessComponentName);
+ URI base = domain.resolve(harnessComponentName + "/");
+
+ CompositeImplementation impl = new CompositeImplementation();
+ impl.setScdlLocation(testScdl.toURI().toURL());
+ impl.setClassLoader(testClassLoader);
+
+ ComponentDefinition<CompositeImplementation> definition =
+ new ComponentDefinition<CompositeImplementation>(componentName, impl);
+ Collection<Component> testComponent = runtime.deployTestScdl(definition);
+ testSuite = createTestSuite(runtime, definition, base);
+ for (Component component : testComponent) {
+ component.start();
+ }
+
+ runtime.startContext(componentName);
+ } catch (Exception e) {
+ monitor.runError(e);
+ throw new MojoExecutionException("Error deploying test component " + testScdl, e);
+ }
+ log.info("Executing tests...");
+
+ boolean success = runSurefire(testSuite);
+ if (!success) {
+ String msg = "There were test failures";
+ throw new MojoFailureException(msg);
+ }
+ } finally {
+ log.info("Stopping Tuscany...");
+ try {
+ runtime.destroy();
+ } catch (TuscanyRuntimeException e) {
+ monitor.runError(e);
+ }
+ }
+ }
+
+ protected ClassLoader createHostClassLoader(ClassLoader parent, Dependency[] extensions)
+ throws MojoExecutionException {
+ if (extensions == null || extensions.length == 0) {
+ return parent;
+ }
+
+ Set<Artifact> artifacts = new HashSet<Artifact>();
+ for (Dependency extension : extensions) {
+ Artifact artifact = extension.getArtifact(artifactFactory);
+ try {
+ resolver.resolve(artifact, remoteRepositories, localRepository);
+ ResolutionGroup resolutionGroup = metadataSource.retrieve(artifact,
+ localRepository,
+ remoteRepositories);
+ ArtifactResolutionResult result = resolver.resolveTransitively(resolutionGroup.getArtifacts(),
+ artifact,
+ remoteRepositories,
+ localRepository,
+ metadataSource);
+ artifacts.add(artifact);
+ artifacts.addAll(result.getArtifacts());
+ } catch (ArtifactResolutionException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
+ } catch (ArtifactNotFoundException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
+ } catch (ArtifactMetadataRetrievalException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
+ }
+ }
+ URL[] urls = new URL[artifacts.size()];
+ int i = 0;
+ for (Artifact artifact : artifacts) {
+ File file = artifact.getFile();
+ assert file != null;
+ try {
+ urls[i++] = file.toURI().toURL();
+ } catch (MalformedURLException e) {
+ // toURI should have made this valid
+ throw new AssertionError();
+ }
+ }
+
+ Log log = getLog();
+ if (log.isDebugEnabled()) {
+ log.debug("Tuscany extension classpath:");
+ for (URL url : urls) {
+ log.debug(" " + url);
+ }
+ }
+
+ return new CompositeClassLoader(null, urls, parent);
+ }
+
+ public boolean runSurefire(SurefireTestSuite testSuite) throws MojoExecutionException {
+ try {
+ Properties status = new Properties();
+ boolean success = run(testSuite, status);
+ getLog().debug("Test results: "+status);
+ return success;
+ } catch (ReporterException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
+ } catch (TestSetFailedException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
+ }
+ }
+
+ public boolean run(SurefireTestSuite suite, Properties status) throws ReporterException, TestSetFailedException {
+ int totalTests = suite.getNumTests();
+
+ List<Reporter> reports = new ArrayList<Reporter>();
+ reports.add(new BriefFileReporter(reportsDirectory, trimStackTrace));
+ reports.add(new BriefConsoleReporter(trimStackTrace));
+ ReporterManager reporterManager = new ReporterManager(reports);
+ reporterManager.initResultsFromProperties(status);
+
+ reporterManager.runStarting(totalTests);
+
+ if (totalTests == 0) {
+ reporterManager.writeMessage("There are no tests to run.");
+ } else {
+ suite.execute(reporterManager, null);
+ }
+
+ reporterManager.runCompleted();
+ reporterManager.updateResultsProperties(status);
+ return reporterManager.getNumErrors() == 0 && reporterManager.getNumFailures() == 0;
+ }
+
+ protected MavenEmbeddedRuntime createRuntime(ClassLoader hostClassLoader) throws MojoExecutionException {
+ if (systemScdl == null) {
+ systemScdl = hostClassLoader.getResource("META-INF/tuscany/embeddedMaven.scdl");
+ }
+
+ MavenRuntimeInfo runtimeInfo = new MavenRuntimeInfo();
+ MavenEmbeddedArtifactRepository artifactRepository = new MavenEmbeddedArtifactRepository(artifactFactory,
+ resolver,
+ metadataSource,
+ localRepository,
+ remoteRepositories);
+ MavenEmbeddedRuntime runtime = new MavenEmbeddedRuntime(getLog());
+ runtime.setRuntimeInfo(runtimeInfo);
+ runtime.setSystemScdl(systemScdl);
+ runtime.setHostClassLoader(hostClassLoader);
+ runtime.setArtifactRepository(artifactRepository);
+ return runtime;
+ }
+
+ public ClassLoader createTestClassLoader(ClassLoader parent) {
+ URL[] urls = new URL[testClassPath.size()];
+ int idx = 0;
+ for (String s : testClassPath) {
+ File pathElement = new File(s);
+ try {
+ URL url = pathElement.toURI().toURL();
+ getLog().debug("Adding application URL: " + url);
+ urls[idx++] = url;
+ } catch (MalformedURLException e) {
+ // toURI should have encoded the URL
+ throw new AssertionError();
+ }
+
+ }
+ return new URLClassLoader(urls, parent);
+ }
+
+ protected SurefireTestSuite createTestSuite(MavenEmbeddedRuntime runtime,
+ ComponentDefinition<CompositeImplementation> definition,
+ URI uriBase) throws MojoExecutionException {
+ SCATestSuite suite = new SCATestSuite();
+
+ URI contextId = definition.getUri();
+ CompositeImplementation impl = definition.getImplementation();
+ CompositeComponentType<?,?,?> componentType = impl.getComponentType();
+ Map<String, ComponentDefinition<? extends Implementation<?>>> components = componentType.getComponents();
+ for (Map.Entry<String, ComponentDefinition<? extends Implementation<?>>> entry : components.entrySet()) {
+ String name = entry.getKey();
+ ComponentDefinition<? extends Implementation<?>> junitDefinition = entry.getValue();
+ Implementation<?> implementation = junitDefinition.getImplementation();
+ if (ImplementationJUnit.class.isAssignableFrom(implementation.getClass())) {
+ URI uri = uriBase.resolve(name);
+ SCATestSet testSet = createTestSet(runtime, name, contextId, uri, junitDefinition);
+ suite.add(testSet);
+ }
+ }
+ return suite;
+ }
+
+ protected SCATestSet createTestSet(MavenEmbeddedRuntime runtime,
+ String name,
+ URI contextId,
+ URI uri,
+ ComponentDefinition definition) throws MojoExecutionException {
+ ImplementationJUnit impl = (ImplementationJUnit) definition.getImplementation();
+ PojoComponentType componentType = impl.getComponentType();
+ Map services = componentType.getServices();
+ JavaMappedService testService = (JavaMappedService) services.get("testService");
+ if (testService == null) {
+ throw new MojoExecutionException("No testService defined on component: " + definition.getUri());
+ }
+ Map<String, ? extends Operation<?>> operations = testService.getServiceContract().getOperations();
+ return new SCATestSet(runtime, name, contextId, uri, operations.values());
+ }
+
+ public interface MojoMonitor {
+ @LogLevel("SEVERE")
+ void runError(Exception e);
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/ImplementationJUnit.java b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/ImplementationJUnit.java
new file mode 100644
index 0000000000..592cd91a76
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/ImplementationJUnit.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.plugin.itest.implementation.junit;
+
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.AtomicImplementation;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ImplementationJUnit extends AtomicImplementation<PojoComponentType> {
+ private String className;
+
+ /**
+ * Constructor supplying the name of the JUnit test class
+ *
+ * @param className the name of the JUnit test class
+ */
+ public ImplementationJUnit(String className) {
+ this.className = className;
+ }
+
+ /**
+ * Returns the name of the JUnit test class.
+ *
+ * @return the name of the JUnit test class
+ */
+ public String getClassName() {
+ return className;
+ }
+
+ /**
+ * Sets the name of the JUnit test class.
+ *
+ * @param className the name of the JUnit test class
+ */
+ public void setClassName(String className) {
+ this.className = className;
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/ImplementationJUnitLoader.java b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/ImplementationJUnitLoader.java
new file mode 100644
index 0000000000..e2daa7a3ec
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/ImplementationJUnitLoader.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.plugin.itest.implementation.junit;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ImplementationJUnitLoader extends LoaderExtension<ImplementationJUnit> {
+ private static final QName JUNIT = new QName("http://tuscany.apache.org/xmlns/sca/2.0-alpha", "junit");
+
+ public ImplementationJUnitLoader(@Reference LoaderRegistry registry) {
+ super(registry);
+ }
+
+ public QName getXMLType() {
+ return JUNIT;
+ }
+
+ public ImplementationJUnit load(
+ ModelObject object,
+ XMLStreamReader reader,
+ DeploymentContext deploymentContext) throws XMLStreamException, LoaderException {
+ String className = reader.getAttributeValue(null, "class");
+ return new ImplementationJUnit(className);
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitComponentBuilder.java b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitComponentBuilder.java
new file mode 100644
index 0000000000..4716587c76
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitComponentBuilder.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.plugin.itest.implementation.junit;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.builder.BuilderConfigException;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentBuilderExtension;
+import org.apache.tuscany.spi.host.ResourceHost;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.Resource;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.PropertyValue;
+
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.java.JavaAtomicComponent;
+import org.apache.tuscany.core.injection.MethodEventInvoker;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.injection.ResourceObjectFactory;
+
+/**
+ * Builds a Java-based atomic context from a component definition
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+public class JUnitComponentBuilder extends ComponentBuilderExtension<ImplementationJUnit> {
+
+ private ResourceHost host;
+
+ @Reference
+ public void setHost(ResourceHost host) {
+ this.host = host;
+ }
+
+ @SuppressWarnings("unchecked")
+ public AtomicComponent build(ComponentDefinition<ImplementationJUnit> definition, DeploymentContext deployment)
+ throws BuilderConfigException {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> componentType =
+ definition.getImplementation().getComponentType();
+ Class<?> implClass = componentType.getImplClass();
+
+ PojoConfiguration configuration = new PojoConfiguration();
+ if (definition.getInitLevel() != null) {
+ configuration.setInitLevel(definition.getInitLevel());
+ } else {
+ configuration.setInitLevel(componentType.getInitLevel());
+ }
+ if (componentType.getMaxAge() > 0) {
+ configuration.setMaxAge(componentType.getMaxAge());
+ } else if (componentType.getMaxIdleTime() > 0) {
+ configuration.setMaxIdleTime(componentType.getMaxIdleTime());
+ }
+ Method initMethod = componentType.getInitMethod();
+ if (initMethod != null) {
+ configuration.setInitInvoker(new MethodEventInvoker(initMethod));
+ }
+ Method destroyMethod = componentType.getDestroyMethod();
+ if (destroyMethod != null) {
+ configuration.setDestroyInvoker(new MethodEventInvoker(destroyMethod));
+ }
+
+ configuration.setProxyService(proxyService);
+ configuration.setWorkContext(workContext);
+ configuration.setImplementationClass(implClass);
+ configuration.setGroupId(deployment.getGroupId());
+
+ // setup property injection sites
+ for (JavaMappedProperty<?> property : componentType.getProperties().values()) {
+ configuration.addPropertySite(property.getName(), property.getMember());
+ }
+
+ // setup reference injection sites
+ for (JavaMappedReference reference : componentType.getReferences().values()) {
+ Member member = reference.getMember();
+ if (member != null) {
+ // could be null if the reference is mapped to a constructor
+ configuration.addReferenceSite(reference.getUri().getFragment(), member);
+ }
+ }
+
+ for (Resource resource : componentType.getResources().values()) {
+ Member member = resource.getMember();
+ if (member != null) {
+ // could be null if the resource is mapped to a constructor
+ configuration.addResourceSite(resource.getName(), member);
+ }
+ }
+
+ // setup constructor injection
+ ConstructorDefinition<?> ctorDef = componentType.getConstructorDefinition();
+ Constructor<?> constr = ctorDef.getConstructor();
+ PojoObjectFactory<?> instanceFactory = new PojoObjectFactory(constr);
+ configuration.setInstanceFactory(instanceFactory);
+ configuration.getConstructorParamNames().addAll(ctorDef.getInjectionNames());
+ for (Class<?> clazz : constr.getParameterTypes()) {
+ configuration.addConstructorParamType(clazz);
+ }
+ configuration.setName(definition.getUri());
+ JavaAtomicComponent component = new JavaAtomicComponent(configuration);
+
+ // handle properties
+ handleProperties(definition, component);
+
+ // handle resources
+ handleResources(componentType, component);
+
+ handleCallbackSites(componentType, configuration);
+
+ if (componentType.getConversationIDMember() != null) {
+ component.addConversationIDFactory(componentType.getConversationIDMember());
+ }
+
+ return component;
+ }
+
+ private void handleCallbackSites(
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> componentType,
+ PojoConfiguration configuration) {
+ for (JavaMappedService service : componentType.getServices().values()) {
+ // setup callback injection sites
+ if (service.getCallbackReferenceName() != null) {
+ // Only if there is a callback reference in the service
+ configuration.addCallbackSite(service.getCallbackReferenceName(), service.getCallbackMember());
+ }
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private void handleResources(
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> componentType,
+ JavaAtomicComponent component) {
+
+ for (Resource resource : componentType.getResources().values()) {
+ ObjectFactory<?> objectFactory = resource.getObjectFactory();
+ if (objectFactory != null) {
+ component.addResourceFactory(resource.getName(), objectFactory);
+ } else {
+ String name = resource.getName();
+ boolean optional = resource.isOptional();
+ Class<Object> type = (Class<Object>) resource.getType();
+ ResourceObjectFactory<Object> factory;
+ String mappedName = resource.getMappedName();
+ if (mappedName == null) {
+ // by type
+ factory = new ResourceObjectFactory<Object>(type, optional, host);
+ } else {
+ factory = new ResourceObjectFactory<Object>(type, mappedName, optional, host);
+ }
+ component.addResourceFactory(name, factory);
+ }
+ }
+ }
+
+ private void handleProperties(ComponentDefinition<ImplementationJUnit> definition, JavaAtomicComponent component) {
+ for (PropertyValue<?> property : definition.getPropertyValues().values()) {
+ ObjectFactory<?> factory = property.getValueFactory();
+ if (factory != null) {
+ component.addPropertyFactory(property.getName(), factory);
+ }
+ }
+ }
+
+ protected Class<ImplementationJUnit> getImplementationType() {
+ return ImplementationJUnit.class;
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitComponentTypeLoader.java b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitComponentTypeLoader.java
new file mode 100644
index 0000000000..bb7ff476a2
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitComponentTypeLoader.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.plugin.itest.implementation.junit;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentTypeLoaderExtension;
+import org.apache.tuscany.spi.implementation.java.IntrospectionRegistry;
+import org.apache.tuscany.spi.implementation.java.Introspector;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.MissingResourceException;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JUnitComponentTypeLoader extends ComponentTypeLoaderExtension<ImplementationJUnit> {
+ private static final URI TEST_SERVICE_NAME = URI.create("#testService");
+ private Introspector introspector;
+
+ @Constructor
+ public JUnitComponentTypeLoader(@Reference LoaderRegistry loaderRegistry,
+ @Reference IntrospectionRegistry introspector) {
+ super(loaderRegistry);
+ this.introspector = introspector;
+ }
+
+ @Override
+ protected Class<ImplementationJUnit> getImplementationClass() {
+ return ImplementationJUnit.class;
+ }
+
+ public void load(ImplementationJUnit implementation, DeploymentContext context) throws LoaderException {
+ String className = implementation.getClassName();
+ Class<?> implClass;
+ try {
+ implClass = context.getClassLoader().loadClass(className);
+ } catch (ClassNotFoundException e) {
+ throw new MissingResourceException(className, e);
+ }
+ PojoComponentType componentType = loadByIntrospection(implementation, context, implClass);
+ implementation.setComponentType(componentType);
+ }
+
+ protected PojoComponentType loadByIntrospection(ImplementationJUnit implementation,
+ DeploymentContext deploymentContext,
+ Class<?> implClass) throws ProcessingException {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> componentType =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(implClass);
+ introspector.introspect(implClass, componentType, deploymentContext);
+
+ if (componentType.getInitMethod() == null) {
+ componentType.setInitMethod(getCallback(implClass, "setUp"));
+ }
+ if (componentType.getDestroyMethod() == null) {
+ componentType.setDestroyMethod(getCallback(implClass, "tearDown"));
+ }
+ ServiceContract testContract = generateTestContract(implClass);
+ JavaMappedService testService = new JavaMappedService(TEST_SERVICE_NAME, testContract, false);
+ componentType.add(testService);
+ return componentType;
+ }
+
+ protected Method getCallback(Class<?> implClass, String name) {
+ while (Object.class != implClass) {
+ try {
+ Method callback = implClass.getDeclaredMethod(name);
+ callback.setAccessible(true);
+ return callback;
+ } catch (NoSuchMethodException e) {
+ implClass = implClass.getSuperclass();
+ continue;
+ }
+ }
+ return null;
+ }
+
+ private static final DataType<List<DataType<Type>>> INPUT_TYPE;
+ private static final DataType<Type> OUTPUT_TYPE;
+ private static final List<DataType<Type>> FAULT_TYPE;
+
+ static {
+ List<DataType<Type>> paramDataTypes = Collections.emptyList();
+ INPUT_TYPE = new DataType<List<DataType<Type>>>("idl:input", Object[].class, paramDataTypes);
+ OUTPUT_TYPE = new DataType<Type>(null, void.class, void.class);
+ FAULT_TYPE = Collections.emptyList();
+ }
+
+ protected ServiceContract generateTestContract(Class<?> implClass) {
+ Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>();
+ for (Method method : implClass.getMethods()) {
+ // see if this is a test method
+ if (Modifier.isStatic(method.getModifiers())) {
+ continue;
+ }
+ if (method.getReturnType() != void.class) {
+ continue;
+ }
+ if (method.getParameterTypes().length != 0) {
+ continue;
+ }
+ String name = method.getName();
+ if (name.length() < 5 || !name.startsWith("test")) {
+ continue;
+ }
+ Operation<Type> operation = new Operation<Type>(name, INPUT_TYPE, OUTPUT_TYPE, FAULT_TYPE);
+ operations.put(name, operation);
+ }
+ return new JUnitServiceContract(operations);
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitServiceContract.java b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitServiceContract.java
new file mode 100644
index 0000000000..4e3fad0db2
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/plugin/src/main/java/org/apache/tuscany/sca/plugin/itest/implementation/junit/JUnitServiceContract.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.plugin.itest.implementation.junit;
+
+import java.util.Map;
+import java.lang.reflect.Type;
+
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.model.Operation;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JUnitServiceContract extends ServiceContract<Type> {
+
+ public JUnitServiceContract(Map<String, Operation<Type>> operations) {
+ setOperations(operations);
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/itest/plugin/src/main/resources/META-INF/tuscany/embeddedMaven.scdl b/tags/java/tsss-demo/runtime/itest/plugin/src/main/resources/META-INF/tuscany/embeddedMaven.scdl
new file mode 100644
index 0000000000..493952944c
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/plugin/src/main/resources/META-INF/tuscany/embeddedMaven.scdl
@@ -0,0 +1,174 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<!--
+ Default system configuration for the launcher environment.
+
+ $Rev$ $Date$
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ name="org.apache.tuscany.sca.plugins.itest.EmbeddedMaven"
+ autowire="true">
+
+ <!-- Component that provides the Deployer service -->
+ <component name="deployer">
+ <system:implementation.system class="org.apache.tuscany.core.deployer.DeployerImpl"/>
+ </component>
+
+ <!-- Work management -->
+ <component name="WorkContext">
+ <system:implementation.system class="org.apache.tuscany.core.component.WorkContextImpl"/>
+ </component>
+
+ <!-- Wire service -->
+ <component name="proxyService">
+ <system:implementation.system class="org.apache.tuscany.core.wire.jdk.JDKProxyService"/>
+ </component>
+
+ <!-- Builder and BuilderRegistry -->
+ <component name="builder">
+ <system:implementation.system class="org.apache.tuscany.core.builder.BuilderRegistryImpl"/>
+ </component>
+
+ <!-- Loader and LoaderRegistry -->
+ <component name="loader">
+ <system:implementation.system class="org.apache.tuscany.core.loader.LoaderRegistryImpl"/>
+ </component>
+
+ <!-- Introspector and IntrospectionRegistry -->
+ <component name="interfaceProcessorRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.IntrospectionRegistryImpl"/>
+ </component>
+
+ <!-- Connector infrastructure -->
+ <component name="connector">
+ <system:implementation.system class="org.apache.tuscany.core.builder.ConnectorImpl"/>
+ </component>
+
+ <component name="interceptorBuilderRegistry">
+ <system:implementation.system
+ class="org.apache.tuscany.core.builder.interceptor.InterceptorBuilderRegistryImpl"/>
+ </component>
+
+ <component name="wireAttacherRegistry">
+ <system:implementation.system
+ class="org.apache.tuscany.core.builder.physical.WireAttacherRegistryImpl"/>
+ </component>
+
+ <component name="wirePostProcessorRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.builder.WirePostProcessorRegistryImpl"/>
+ </component>
+
+ <!-- Resource host registry -->
+ <component name="resourceHostRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.services.host.DelegatingResourceHostRegistry"/>
+ </component>
+
+ <!-- Default scopes -->
+ <component name="scope.stateless">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.StatelessScopeContainer"/>
+ </component>
+<!--
+ <component name="scope.request">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.RequestScopeContainer"/>
+ </component>
+-->
+<!--
+ <component name="scope.conversational">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.ConversationalScopeContainer"/>
+ </component>
+-->
+
+ <!-- include loader configuration -->
+ <include name="org.apache.tuscany.core.Loader" scdlResource="org/apache/tuscany/core/loader.scdl"/>
+
+ <!-- include databinding configuration -->
+ <include name="org.apache.tuscany.core.DataBinding" scdlResource="org/apache/tuscany/core/databinding.scdl"/>
+
+ <!-- include implementation processor configuration -->
+ <include name="org.apache.tuscany.core.Implementation" scdlResource="org/apache/tuscany/core/implementation.scdl"/>
+
+ <!-- Java interface definition language -->
+ <include name="org.apache.tuscany.core.InterfaceJava" scdlResource="org/apache/tuscany/core/interfaceJava.scdl"/>
+
+ <!-- include composite implementation type -->
+ <include name="org.apache.tuscany.core.Composite" scdlResource="org/apache/tuscany/core/composite.scdl"/>
+
+ <!-- include exception formatters -->
+ <include name="org.apache.tuscany.core.Formatters" scdlResource="org/apache/tuscany/core/formatters.scdl"/>
+
+ <!-- System implementation type -->
+ <include name="org.apache.tuscany.core.SystemImplementation"
+ scdlResource="org/apache/tuscany/core/systemImplementation.scdl"/>
+
+ <!-- Java implementation type -->
+ <include name="org.apache.tuscany.core.JavaImplementation"
+ scdlResource="org/apache/tuscany/core/javaImplementation.scdl"/>
+
+ <!-- WorkScheduler service -->
+ <component name="workManager">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.work.jsr237.workmanager.ThreadPoolWorkManager"/>
+ <property name="poolSize">10</property>
+ </component>
+
+ <component name="workScheduler">
+ <system:implementation.system class="org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler"/>
+ </component>
+
+ <component name="policyBuilderRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.policy.PolicyBuilderRegistryImpl"/>
+ </component>
+
+ <component name="propertyFactory">
+ <system:implementation.system class="org.apache.tuscany.core.property.PropertyObjectFactoryImpl"/>
+ </component>
+
+ <!-- Store infrastructure -->
+ <component name="store">
+ <system:implementation.system class="org.apache.tuscany.core.services.store.memory.MemoryStore"/>
+ </component>
+
+ <!-- the local binding -->
+ <component name="localBindingLoader">
+ <system:implementation.system class="org.apache.tuscany.core.binding.local.LocalBindingLoader"/>
+ </component>
+
+ <component name="localBindingBuilder">
+ <system:implementation.system class="org.apache.tuscany.core.binding.local.LocalBindingBuilder"/>
+ </component>
+
+ <component name="org.apache.tuscany.sca.plugin.itest.implementation.junit.ImplementationJUnitLoader">
+ <system:implementation.system
+ class="org.apache.tuscany.sca.plugin.itest.implementation.junit.ImplementationJUnitLoader"/>
+ </component>
+
+ <component name="org.apache.tuscany.sca.plugin.itest.implementation.junit.JUnitComponentTypeLoader">
+ <system:implementation.system
+ class="org.apache.tuscany.sca.plugin.itest.implementation.junit.JUnitComponentTypeLoader"/>
+ </component>
+
+ <component name="org.apache.tuscany.sca.plugin.itest.implementation.junit.JUnitComponentBuilder">
+ <system:implementation.system
+ class="org.apache.tuscany.sca.plugin.itest.implementation.junit.JUnitComponentBuilder"/>
+ </component>
+
+
+</composite>
diff --git a/tags/java/tsss-demo/runtime/itest/plugin/src/site/apt/usage.apt b/tags/java/tsss-demo/runtime/itest/plugin/src/site/apt/usage.apt
new file mode 100644
index 0000000000..7606bd23a1
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/plugin/src/site/apt/usage.apt
@@ -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.
+
+Usage
+
+ The <<<tuscany-itest-plugin>>> is associated with the <<<integration-test>>> phase of the build lifecycle.
+
+ The plugin can be invoked directly from the command line:
+
++---+
+mvn org.apache.tuscany.sca:tuscany-itest-plugin:test
++---+
+
+ or can be included in the build definition for your project:
+
++---+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-itest-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
++---+
+
+* Writing Integration Tests
+
+ Integration tests are written as JUnit TestCases (currently only JUnit 3.8.1 is supported but other frameworks
+ may be added later) that use SCA references to access services provided by the components under test. The
+ references are injected into your testcase before its setUp method is called (using constructor, setter or field
+ injection).
+
+ For example, to test a component that implemented the <<<MyService>>> interface you could write:
+
++---+
+public class ServiceTestComponent extends TestCase {
+
+ @Reference
+ public MyService service;
+
+ public void testSomething() {
+ assertEquals(result, service.doSomething);
+ }
+}
++---+
+
+ This TestCase is used as a component within a SCA composite that defines the test suite
+ as described in the next section. This separates TestCase's for normal unit tests from
+ those that are integration tests.
+
+ If any methods have an SCA <<<@Init>>> or <<<@Destroy>>> annotation they will be called
+ before and after executing tests; if no methods are annotated in this way the normal
+ JUnit <<<setUp>>> and <<<tearDown>>> methods will be called.
+
+ If the component's scope is <<<STATELESS>>> (the default), then a new instance of the
+ test component will used to run each test; if the component's scope is <<<COMPOSITE>>>
+ then a single instance will be used to run all tests. The scope can be set with the
+ standard SCA <<<@Scope>>> annotation.
+
+* Defining an SCA Test Suite
+
+ The Test Suite for your integration tests is defined by an SCA composite file that contains
+ the test components written above wired to the production components for the application.
+ The test components must use an implementation type of <<< <tuscany:junit> >>>.
+
+ A simple way to achieve this is to use a SCDL <include> element to include the content of
+ production composite in the test harness; this gives the test components access to all of
+ the components and references in the production composite.
+
+ For example, the following SCDL configures the <<<ServiceTestComponent>>> above
+ to test the <<<MyServiceComponent>>> in the production composite <<<ProductionComposite>>>:
+
++---+
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/2.0-alpha"
+ name="PropertyTestHarnessComposite">
+
+ <include name="ProductionComposite" scdlResource="META-INF/sca/default.scdl"/>
+
+ <component name="testMyService">
+ <tuscany:junit class="ServiceTestComponent"/>
+ <reference name="service">MyServiceImpl</reference>
+ </component>
+</composite>
++---+
+
+ Alternatively, the production composite can be tested as a black box by using it to
+ implement a component and wiring test components to it. This allows the externally
+ visible services to be tested without knowledge of the internals of the composite.
+
+ For example, the following SCDL tests the <<<ProductionComposite>>> in this way:
+
++---+
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/2.0-alpha"
+ name="PropertyTestHarnessComposite">
+
+ <component name="ProductionComponent">
+ <implementation.composite name="ProductionComposite"
+ scdlResource="META-INF/sca/default.scdl"/>
+ </component>
+
+ <component name="testMyService">
+ <tuscany:junit class="ServiceTestComponent"/>
+ <reference name="service">ProductionComponent</reference>
+ </component>
+</composite>
++---+
+
+ The location of this test composite definition can be specified using the <<<testScdl>>>
+ plugin configuration property; the default location is <<<${project.build.testOutputDirectory}/itest.scdl>>>
+ which allows the <<<itest.scdl>>> source file to be placed in the test resources (<<<src/test/resources>>>).
+
+* Test Result Output
+
+ The test results are output using Surefire's reporting framework for integration with other test reports.
+ XML and test results are stored in the normal test output directory (<<<target/surefire-reports>>>) with
+ a summary displayed on the console:
+
++---+
+[INFO] [tuscany-itest:test {execution: default}]
+[INFO] Starting Tuscany...
+[INFO] Deploying test SCDL from .../target/test-classes/itest.scdl
+[INFO] Executing tests...
+
+-------------------------------------------------------
+ T E S T S
+-------------------------------------------------------
+Running testMyService
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 sec
+
+Results :
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
+
+[INFO] Stopping Tuscany...
++---+ \ No newline at end of file
diff --git a/tags/java/tsss-demo/runtime/itest/plugin/src/site/fml/faq.fml b/tags/java/tsss-demo/runtime/itest/plugin/src/site/fml/faq.fml
new file mode 100644
index 0000000000..681567e432
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/plugin/src/site/fml/faq.fml
@@ -0,0 +1,65 @@
+<?xml version="1.0"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<faqs id="FAQ" title="Frequently Asked Questions">
+ <part id="General">
+ <faq id="junit4-support">
+ <question>Does the plugin support JUnit 4.0?</question>
+ <answer>
+ <p>
+ Not at this time.
+ </p>
+ </answer>
+ </faq>
+ <faq id="extensions">
+ <question>How do I add extensions to the runtime?</question>
+ <answer>
+ <p>
+ The plugin uses the normal extension mechanisms provided by
+ the Apache Tuscany runtime.
+ </p>
+ <p>
+ At the moment this requires supplying a custom system SCDL file that
+ includes the extension composites. In the future, we plan to load
+ extensions dynamically - please check back later.
+ </p>
+ </answer>
+ </faq>
+ <faq id="service-support">
+ <question>Can I use services provided by another systems?</question>
+ <answer>
+ <p>
+ You can define &lt;reference&gt; elements in your composite to access
+ services using a binding. Those can be standard web services, or any
+ other type of service that there is a binding for.
+ </p>
+ </answer>
+ </faq>
+ <faq id="domain-support">
+ <question>Can I use services provided by another SCA domain?</question>
+ <answer>
+ <p>
+ As we add federation support, the local runtime will be able to
+ join any SCA domain (subject to authorization) and use its services.
+ </p>
+ </answer>
+ </faq>
+ </part>
+</faqs>
diff --git a/tags/java/tsss-demo/runtime/itest/plugin/src/site/site.xml b/tags/java/tsss-demo/runtime/itest/plugin/src/site/site.xml
new file mode 100644
index 0000000000..bf5bf8c35b
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/plugin/src/site/site.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project>
+ <body>
+ <menu name="Overview">
+ <item name="Introduction" href="index.html"/>
+ <item name="Goals" href="plugin-info.html"/>
+ <item name="Usage" href="usage.html"/>
+ <item name="FAQ" href="faq.html"/>
+ </menu>
+ <menu name="Examples">
+ </menu>
+ </body>
+</project>
diff --git a/tags/java/tsss-demo/runtime/itest/pom.xml b/tags/java/tsss-demo/runtime/itest/pom.xml
new file mode 100644
index 0000000000..2907a12f73
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/pom.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>runtime</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.runtime</groupId>
+ <artifactId>itest</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache Tuscany Integration Test Runtime</name>
+
+ <profiles>
+ <profile>
+ <id>default</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <modules>
+ <module>plugin</module>
+ <module>smoketest</module>
+ </modules>
+ </profile>
+
+ <profile>
+ <!-- for the release profile exclude the smoketest -->
+ <id>release</id>
+ <modules>
+ <module>plugin</module>
+ </modules>
+ </profile>
+ </profiles>
+</project>
diff --git a/tags/java/tsss-demo/runtime/itest/smoketest/LICENSE.txt b/tags/java/tsss-demo/runtime/itest/smoketest/LICENSE.txt
new file mode 100644
index 0000000000..9601ead3f6
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/smoketest/LICENSE.txt
@@ -0,0 +1,1407 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+APACHE TUSCANY SUBCOMPONENTS:
+
+The Apache Tuscany distribution includes a number of subcomponents with
+separate copyright notices and license terms. Your use of the source
+code for the these subcomponents is subject to the terms and
+conditions of the following licenses.
+
+===============================================================================
+
+For the Eclipse Modeling Framework component and the Celtix binding:
+
+Eclipse Public License - v 1.0
+
+THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
+PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF
+THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
+
+1. DEFINITIONS
+
+"Contribution" means:
+
+a) in the case of the initial Contributor, the initial code and
+documentation distributed under this Agreement, and
+b) in the case of each subsequent Contributor:
+
+i) changes to the Program, and
+
+ii) additions to the Program;
+
+where such changes and/or additions to the Program originate from and
+are distributed by that particular Contributor. A Contribution
+'originates' from a Contributor if it was added to the Program by such
+Contributor itself or anyone acting on such Contributor's behalf.
+Contributions do not include additions to the Program which: (i) are
+separate modules of software distributed in conjunction with the
+Program under their own license agreement, and (ii) are not derivative
+works of the Program.
+
+"Contributor" means any person or entity that distributes the Program.
+
+"Licensed Patents " mean patent claims licensable by a Contributor
+which are necessarily infringed by the use or sale of its Contribution
+alone or when combined with the Program.
+
+"Program" means the Contributions distributed in accordance with this
+Agreement.
+
+"Recipient" means anyone who receives the Program under this
+Agreement, including all Contributors.
+
+2. GRANT OF RIGHTS
+
+a) Subject to the terms of this Agreement, each Contributor hereby
+grants Recipient a non-exclusive, worldwide, royalty-free copyright
+license to reproduce, prepare derivative works of, publicly display,
+publicly perform, distribute and sublicense the Contribution of such
+Contributor, if any, and such derivative works, in source code and
+object code form.
+
+b) Subject to the terms of this Agreement, each Contributor hereby
+grants Recipient a non-exclusive, worldwide, royalty-free patent
+license under Licensed Patents to make, use, sell, offer to sell,
+import and otherwise transfer the Contribution of such Contributor, if
+any, in source code and object code form. This patent license shall
+apply to the combination of the Contribution and the Program if, at
+the time the Contribution is added by the Contributor, such addition
+of the Contribution causes such combination to be covered by the
+Licensed Patents. The patent license shall not apply to any other
+combinations which include the Contribution. No hardware per se is
+licensed hereunder.
+
+c) Recipient understands that although each Contributor grants the
+licenses to its Contributions set forth herein, no assurances are
+provided by any Contributor that the Program does not infringe the
+patent or other intellectual property rights of any other entity. Each
+Contributor disclaims any liability to Recipient for claims brought by
+any other entity based on infringement of intellectual property rights
+or otherwise. As a condition to exercising the rights and licenses
+granted hereunder, each Recipient hereby assumes sole responsibility
+to secure any other intellectual property rights needed, if any. For
+example, if a third party patent license is required to allow
+Recipient to distribute the Program, it is Recipient's responsibility
+to acquire that license before distributing the Program.
+
+d) Each Contributor represents that to its knowledge it has sufficient
+copyright rights in its Contribution, if any, to grant the copyright
+license set forth in this Agreement.
+
+3. REQUIREMENTS
+
+A Contributor may choose to distribute the Program in object code form
+under its own license agreement, provided that:
+
+a) it complies with the terms and conditions of this Agreement; and
+
+b) its license agreement:
+
+i) effectively disclaims on behalf of all Contributors all warranties
+and conditions, express and implied, including warranties or
+conditions of title and non-infringement, and implied warranties or
+conditions of merchantability and fitness for a particular purpose;
+
+ii) effectively excludes on behalf of all Contributors all liability
+for damages, including direct, indirect, special, incidental and
+consequential damages, such as lost profits;
+
+iii) states that any provisions which differ from this Agreement are
+offered by that Contributor alone and not by any other party; and
+
+iv) states that source code for the Program is available from such
+Contributor, and informs licensees how to obtain it in a reasonable
+manner on or through a medium customarily used for software exchange.
+
+When the Program is made available in source code form:
+
+a) it must be made available under this Agreement; and
+
+b) a copy of this Agreement must be included with each copy of the
+Program.
+
+Contributors may not remove or alter any copyright notices contained
+within the Program.
+
+Each Contributor must identify itself as the originator of its
+Contribution, if any, in a manner that reasonably allows subsequent
+Recipients to identify the originator of the Contribution.
+
+4. COMMERCIAL DISTRIBUTION
+
+Commercial distributors of software may accept certain
+responsibilities with respect to end users, business partners and the
+like. While this license is intended to facilitate the commercial use
+of the Program, the Contributor who includes the Program in a
+commercial product offering should do so in a manner which does not
+create potential liability for other Contributors. Therefore, if a
+Contributor includes the Program in a commercial product offering,
+such Contributor ("Commercial Contributor") hereby agrees to defend
+and indemnify every other Contributor ("Indemnified Contributor")
+against any losses, damages and costs (collectively "Losses") arising
+from claims, lawsuits and other legal actions brought by a third party
+against the Indemnified Contributor to the extent caused by the acts
+or omissions of such Commercial Contributor in connection with its
+distribution of the Program in a commercial product offering. The
+obligations in this section do not apply to any claims or Losses
+relating to any actual or alleged intellectual property infringement.
+In order to qualify, an Indemnified Contributor must: a) promptly
+notify the Commercial Contributor in writing of such claim, and b)
+allow the Commercial Contributor to control, and cooperate with the
+Commercial Contributor in, the defense and any related settlement
+negotiations. The Indemnified Contributor may participate in any such
+claim at its own expense.
+
+For example, a Contributor might include the Program in a commercial
+product offering, Product X. That Contributor is then a Commercial
+Contributor. If that Commercial Contributor then makes performance
+claims, or offers warranties related to Product X, those performance
+claims and warranties are such Commercial Contributor's responsibility
+alone. Under this section, the Commercial Contributor would have to
+defend claims against the other Contributors related to those
+performance claims and warranties, and if a court requires any other
+Contributor to pay any damages as a result, the Commercial Contributor
+must pay those damages.
+
+5. NO WARRANTY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
+PROVIDED 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. Each Recipient is solely
+responsible for determining the appropriateness of using and
+distributing the Program and assumes all risks associated with its
+exercise of rights under this Agreement , including but not limited to
+the risks and costs of program errors, compliance with applicable
+laws, damage to or loss of data, programs or equipment, and
+unavailability or interruption of operations.
+
+6. DISCLAIMER OF LIABILITY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR
+ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING
+WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR
+DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+7. GENERAL
+
+If any provision of this Agreement is invalid or unenforceable under
+applicable law, it shall not affect the validity or enforceability of
+the remainder of the terms of this Agreement, and without further
+action by the parties hereto, such provision shall be reformed to the
+minimum extent necessary to make such provision valid and enforceable.
+
+If Recipient institutes patent litigation against any entity
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+the Program itself (excluding combinations of the Program with other
+software or hardware) infringes such Recipient's patent(s), then such
+Recipient's rights granted under Section 2(b) shall terminate as of
+the date such litigation is filed.
+
+All Recipient's rights under this Agreement shall terminate if it
+fails to comply with any of the material terms or conditions of this
+Agreement and does not cure such failure in a reasonable period of
+time after becoming aware of such noncompliance. If all Recipient's
+rights under this Agreement terminate, Recipient agrees to cease use
+and distribution of the Program as soon as reasonably practicable.
+However, Recipient's obligations under this Agreement and any licenses
+granted by Recipient relating to the Program shall continue and
+survive.
+
+Everyone is permitted to copy and distribute copies of this Agreement,
+but in order to avoid inconsistency the Agreement is copyrighted and
+may only be modified in the following manner. The Agreement Steward
+reserves the right to publish new versions (including revisions) of
+this Agreement from time to time. No one other than the Agreement
+Steward has the right to modify this Agreement. The Eclipse Foundation
+is the initial Agreement Steward. The Eclipse Foundation may assign
+the responsibility to serve as the Agreement Steward to a suitable
+separate entity. Each new version of the Agreement will be given a
+distinguishing version number. The Program (including Contributions)
+may always be distributed subject to the version of the Agreement
+under which it was received. In addition, after a new version of the
+Agreement is published, Contributor may elect to distribute the
+Program (including its Contributions) under the new version. Except as
+expressly stated in Sections 2(a) and 2(b) above, Recipient receives
+no rights or licenses to the intellectual property of any Contributor
+under this Agreement, whether expressly, by implication, estoppel or
+otherwise. All rights in the Program not expressly granted under this
+Agreement are reserved.
+
+This Agreement is governed by the laws of the State of New York and
+the intellectual property laws of the United States of America. No
+party to this Agreement will bring a legal action under this Agreement
+more than one year after the cause of action arose. Each party waives
+its rights to a jury trial in any resulting litigation.
+
+===============================================================================
+
+For the Rhino JavaScript container component:
+
+Netscape Public License V1.1
+
+ AMENDMENTS
+
+ The Netscape Public License Version 1.1 ("NPL") consists of the
+ Mozilla Public License Version 1.1 with the following Amendments,
+ including Exhibit A-Netscape Public License. Files identified with
+ "Exhibit A-Netscape Public License" are governed by the Netscape
+ Public License Version 1.1.
+
+ Additional Terms applicable to the Netscape Public License.
+ I. Effect.
+ These additional terms described in this Netscape Public
+ License -- Amendments shall apply to the Mozilla Communicator
+ client code and to all Covered Code under this License.
+
+ II. "Netscape's Branded Code" means Covered Code that Netscape
+ distributes and/or permits others to distribute under one or more
+ trademark(s) which are controlled by Netscape but which are not
+ licensed for use under this License.
+
+ III. Netscape and logo.
+ This License does not grant any rights to use the trademarks
+ "Netscape", the "Netscape N and horizon" logo or the "Netscape
+ lighthouse" logo, "Netcenter", "Gecko", "Java" or "JavaScript",
+ "Smart Browsing" even if such marks are included in the Original
+ Code or Modifications.
+
+ IV. Inability to Comply Due to Contractual Obligation.
+ Prior to licensing the Original Code under this License, Netscape
+ has licensed third party code for use in Netscape's Branded Code.
+ To the extent that Netscape is limited contractually from making
+ such third party code available under this License, Netscape may
+ choose to reintegrate such code into Covered Code without being
+ required to distribute such code in Source Code form, even if
+ such code would otherwise be considered "Modifications" under
+ this License.
+
+ V. Use of Modifications and Covered Code by Initial Developer.
+ V.1. In General.
+ The obligations of Section 3 apply to Netscape, except to
+ the extent specified in this Amendment, Section V.2 and V.3.
+
+ V.2. Other Products.
+ Netscape may include Covered Code in products other than the
+ Netscape's Branded Code which are released by Netscape
+ during the two (2) years following the release date of the
+ Original Code, without such additional products becoming
+ subject to the terms of this License, and may license such
+ additional products on different terms from those contained
+ in this License.
+
+ V.3. Alternative Licensing.
+ Netscape may license the Source Code of Netscape's Branded
+ Code, including Modifications incorporated therein, without
+ such Netscape Branded Code becoming subject to the terms of
+ this License, and may license such Netscape Branded Code on
+ different terms from those contained in this License.
+
+ VI. Litigation.
+ Notwithstanding the limitations of Section 11 above, the
+ provisions regarding litigation in Section 11(a), (b) and (c) of
+ the License shall apply to all disputes relating to this License.
+
+ EXHIBIT A-Netscape Public License.
+
+ "The contents of this file are subject to the Netscape Public
+ License Version 1.1 (the "License"); you may not use this file
+ except in compliance with the License. You may obtain a copy of
+ the License at http://www.mozilla.org/NPL/
+
+ Software distributed under the License is distributed on an "AS
+ IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ implied. See the License for the specific language governing
+ rights and limitations under the License.
+
+ The Original Code is Mozilla Communicator client code, released
+ March 31, 1998.
+
+ The Initial Developer of the Original Code is Netscape
+ Communications Corporation. Portions created by Netscape are
+ Copyright (C) 1998-1999 Netscape Communications Corporation. All
+ Rights Reserved.
+
+ Contributor(s): ______________________________________.
+
+ Alternatively, the contents of this file may be used under the
+ terms of the _____ license (the "[___] License"), in which case
+ the provisions of [______] License are applicable instead of
+ those above. If you wish to allow use of your version of this
+ file only under the terms of the [____] License and not to allow
+ others to use your version of this file under the NPL, indicate
+ your decision by deleting the provisions above and replace them
+ with the notice and other provisions required by the [___]
+ License. If you do not delete the provisions above, a recipient
+ may use your version of this file under either the NPL or the
+ [___] License."
+
+ ----------------------------------------------------------------------
+
+ MOZILLA PUBLIC LICENSE
+ Version 1.1
+
+ ---------------
+
+1. Definitions.
+
+ 1.0.1. "Commercial Use" means distribution or otherwise making the
+ Covered Code available to a third party.
+
+ 1.1. "Contributor" means each entity that creates or contributes to
+ the creation of Modifications.
+
+ 1.2. "Contributor Version" means the combination of the Original
+ Code, prior Modifications used by a Contributor, and the Modifications
+ made by that particular Contributor.
+
+ 1.3. "Covered Code" means the Original Code or Modifications or the
+ combination of the Original Code and Modifications, in each case
+ including portions thereof.
+
+ 1.4. "Electronic Distribution Mechanism" means a mechanism generally
+ accepted in the software development community for the electronic
+ transfer of data.
+
+ 1.5. "Executable" means Covered Code in any form other than Source
+ Code.
+
+ 1.6. "Initial Developer" means the individual or entity identified
+ as the Initial Developer in the Source Code notice required by Exhibit
+ A.
+
+ 1.7. "Larger Work" means a work which combines Covered Code or
+ portions thereof with code not governed by the terms of this License.
+
+ 1.8. "License" means this document.
+
+ 1.8.1. "Licensable" means having the right to grant, to the maximum
+ extent possible, whether at the time of the initial grant or
+ subsequently acquired, any and all of the rights conveyed herein.
+
+ 1.9. "Modifications" means any addition to or deletion from the
+ substance or structure of either the Original Code or any previous
+ Modifications. When Covered Code is released as a series of files, a
+ Modification is:
+ A. Any addition to or deletion from the contents of a file
+ containing Original Code or previous Modifications.
+
+ B. Any new file that contains any part of the Original Code or
+ previous Modifications.
+
+ 1.10. "Original Code" means Source Code of computer software code
+ which is described in the Source Code notice required by Exhibit A as
+ Original Code, and which, at the time of its release under this
+ License is not already Covered Code governed by this License.
+
+ 1.10.1. "Patent Claims" means any patent claim(s), now owned or
+ hereafter acquired, including without limitation, method, process,
+ and apparatus claims, in any patent Licensable by grantor.
+
+ 1.11. "Source Code" means the preferred form of the Covered Code for
+ making modifications to it, including all modules it contains, plus
+ any associated interface definition files, scripts used to control
+ compilation and installation of an Executable, or source code
+ differential comparisons against either the Original Code or another
+ well known, available Covered Code of the Contributor's choice. The
+ Source Code can be in a compressed or archival form, provided the
+ appropriate decompression or de-archiving software is widely available
+ for no charge.
+
+ 1.12. "You" (or "Your") means an individual or a legal entity
+ exercising rights under, and complying with all of the terms of, this
+ License or a future version of this License issued under Section 6.1.
+ For legal entities, "You" includes any entity which controls, is
+ controlled by, or is under common control with You. For purposes of
+ this definition, "control" means (a) the power, direct or indirect,
+ to cause the direction or management of such entity, whether by
+ contract or otherwise, or (b) ownership of more than fifty percent
+ (50%) of the outstanding shares or beneficial ownership of such
+ entity.
+
+2. Source Code License.
+
+ 2.1. The Initial Developer Grant.
+ The Initial Developer hereby grants You a world-wide, royalty-free,
+ non-exclusive license, subject to third party intellectual property
+ claims:
+ (a) under intellectual property rights (other than patent or
+ trademark) Licensable by Initial Developer to use, reproduce,
+ modify, display, perform, sublicense and distribute the Original
+ Code (or portions thereof) with or without Modifications, and/or
+ as part of a Larger Work; and
+
+ (b) under Patents Claims infringed by the making, using or
+ selling of Original Code, to make, have made, use, practice,
+ sell, and offer for sale, and/or otherwise dispose of the
+ Original Code (or portions thereof).
+
+ (c) the licenses granted in this Section 2.1(a) and (b) are
+ effective on the date Initial Developer first distributes
+ Original Code under the terms of this License.
+
+ (d) Notwithstanding Section 2.1(b) above, no patent license is
+ granted: 1) for code that You delete from the Original Code; 2)
+ separate from the Original Code; or 3) for infringements caused
+ by: i) the modification of the Original Code or ii) the
+ combination of the Original Code with other software or devices.
+
+ 2.2. Contributor Grant.
+ Subject to third party intellectual property claims, each Contributor
+ hereby grants You a world-wide, royalty-free, non-exclusive license
+
+ (a) under intellectual property rights (other than patent or
+ trademark) Licensable by Contributor, to use, reproduce, modify,
+ display, perform, sublicense and distribute the Modifications
+ created by such Contributor (or portions thereof) either on an
+ unmodified basis, with other Modifications, as Covered Code
+ and/or as part of a Larger Work; and
+
+ (b) under Patent Claims infringed by the making, using, or
+ selling of Modifications made by that Contributor either alone
+ and/or in combination with its Contributor Version (or portions
+ of such combination), to make, use, sell, offer for sale, have
+ made, and/or otherwise dispose of: 1) Modifications made by that
+ Contributor (or portions thereof); and 2) the combination of
+ Modifications made by that Contributor with its Contributor
+ Version (or portions of such combination).
+
+ (c) the licenses granted in Sections 2.2(a) and 2.2(b) are
+ effective on the date Contributor first makes Commercial Use of
+ the Covered Code.
+
+ (d) Notwithstanding Section 2.2(b) above, no patent license is
+ granted: 1) for any code that Contributor has deleted from the
+ Contributor Version; 2) separate from the Contributor Version;
+ 3) for infringements caused by: i) third party modifications of
+ Contributor Version or ii) the combination of Modifications made
+ by that Contributor with other software (except as part of the
+ Contributor Version) or other devices; or 4) under Patent Claims
+ infringed by Covered Code in the absence of Modifications made by
+ that Contributor.
+
+3. Distribution Obligations.
+
+ 3.1. Application of License.
+ The Modifications which You create or to which You contribute are
+ governed by the terms of this License, including without limitation
+ Section 2.2. The Source Code version of Covered Code may be
+ distributed only under the terms of this License or a future version
+ of this License released under Section 6.1, and You must include a
+ copy of this License with every copy of the Source Code You
+ distribute. You may not offer or impose any terms on any Source Code
+ version that alters or restricts the applicable version of this
+ License or the recipients' rights hereunder. However, You may include
+ an additional document offering the additional rights described in
+ Section 3.5.
+
+ 3.2. Availability of Source Code.
+ Any Modification which You create or to which You contribute must be
+ made available in Source Code form under the terms of this License
+ either on the same media as an Executable version or via an accepted
+ Electronic Distribution Mechanism to anyone to whom you made an
+ Executable version available; and if made available via Electronic
+ Distribution Mechanism, must remain available for at least twelve (12)
+ months after the date it initially became available, or at least six
+ (6) months after a subsequent version of that particular Modification
+ has been made available to such recipients. You are responsible for
+ ensuring that the Source Code version remains available even if the
+ Electronic Distribution Mechanism is maintained by a third party.
+
+ 3.3. Description of Modifications.
+ You must cause all Covered Code to which You contribute to contain a
+ file documenting the changes You made to create that Covered Code and
+ the date of any change. You must include a prominent statement that
+ the Modification is derived, directly or indirectly, from Original
+ Code provided by the Initial Developer and including the name of the
+ Initial Developer in (a) the Source Code, and (b) in any notice in an
+ Executable version or related documentation in which You describe the
+ origin or ownership of the Covered Code.
+
+ 3.4. Intellectual Property Matters
+ (a) Third Party Claims.
+ If Contributor has knowledge that a license under a third party's
+ intellectual property rights is required to exercise the rights
+ granted by such Contributor under Sections 2.1 or 2.2,
+ Contributor must include a text file with the Source Code
+ distribution titled "LEGAL" which describes the claim and the
+ party making the claim in sufficient detail that a recipient will
+ know whom to contact. If Contributor obtains such knowledge after
+ the Modification is made available as described in Section 3.2,
+ Contributor shall promptly modify the LEGAL file in all copies
+ Contributor makes available thereafter and shall take other steps
+ (such as notifying appropriate mailing lists or newsgroups)
+ reasonably calculated to inform those who received the Covered
+ Code that new knowledge has been obtained.
+
+ (b) Contributor APIs.
+ If Contributor's Modifications include an application programming
+ interface and Contributor has knowledge of patent licenses which
+ are reasonably necessary to implement that API, Contributor must
+ also include this information in the LEGAL file.
+
+ (c) Representations.
+ Contributor represents that, except as disclosed pursuant to
+ Section 3.4(a) above, Contributor believes that Contributor's
+ Modifications are Contributor's original creation(s) and/or
+ Contributor has sufficient rights to grant the rights conveyed by
+ this License.
+
+ 3.5. Required Notices.
+ You must duplicate the notice in Exhibit A in each file of the Source
+ Code. If it is not possible to put such notice in a particular Source
+ Code file due to its structure, then You must include such notice in a
+ location (such as a relevant directory) where a user would be likely
+ to look for such a notice. If You created one or more Modification(s)
+ You may add your name as a Contributor to the notice described in
+ Exhibit A. You must also duplicate this License in any documentation
+ for the Source Code where You describe recipients' rights or ownership
+ rights relating to Covered Code. You may choose to offer, and to
+ charge a fee for, warranty, support, indemnity or liability
+ obligations to one or more recipients of Covered Code. However, You
+ may do so only on Your own behalf, and not on behalf of the Initial
+ Developer or any Contributor. You must make it absolutely clear than
+ any such warranty, support, indemnity or liability obligation is
+ offered by You alone, and You hereby agree to indemnify the Initial
+ Developer and every Contributor for any liability incurred by the
+ Initial Developer or such Contributor as a result of warranty,
+ support, indemnity or liability terms You offer.
+
+ 3.6. Distribution of Executable Versions.
+ You may distribute Covered Code in Executable form only if the
+ requirements of Section 3.1-3.5 have been met for that Covered Code,
+ and if You include a notice stating that the Source Code version of
+ the Covered Code is available under the terms of this License,
+ including a description of how and where You have fulfilled the
+ obligations of Section 3.2. The notice must be conspicuously included
+ in any notice in an Executable version, related documentation or
+ collateral in which You describe recipients' rights relating to the
+ Covered Code. You may distribute the Executable version of Covered
+ Code or ownership rights under a license of Your choice, which may
+ contain terms different from this License, provided that You are in
+ compliance with the terms of this License and that the license for the
+ Executable version does not attempt to limit or alter the recipient's
+ rights in the Source Code version from the rights set forth in this
+ License. If You distribute the Executable version under a different
+ license You must make it absolutely clear that any terms which differ
+ from this License are offered by You alone, not by the Initial
+ Developer or any Contributor. You hereby agree to indemnify the
+ Initial Developer and every Contributor for any liability incurred by
+ the Initial Developer or such Contributor as a result of any such
+ terms You offer.
+
+ 3.7. Larger Works.
+ You may create a Larger Work by combining Covered Code with other code
+ not governed by the terms of this License and distribute the Larger
+ Work as a single product. In such a case, You must make sure the
+ requirements of this License are fulfilled for the Covered Code.
+
+4. Inability to Comply Due to Statute or Regulation.
+
+ If it is impossible for You to comply with any of the terms of this
+ License with respect to some or all of the Covered Code due to
+ statute, judicial order, or regulation then You must: (a) comply with
+ the terms of this License to the maximum extent possible; and (b)
+ describe the limitations and the code they affect. Such description
+ must be included in the LEGAL file described in Section 3.4 and must
+ be included with all distributions of the Source Code. Except to the
+ extent prohibited by statute or regulation, such description must be
+ sufficiently detailed for a recipient of ordinary skill to be able to
+ understand it.
+
+5. Application of this License.
+
+ This License applies to code to which the Initial Developer has
+ attached the notice in Exhibit A and to related Covered Code.
+
+6. Versions of the License.
+
+ 6.1. New Versions.
+ Netscape Communications Corporation ("Netscape") may publish revised
+ and/or new versions of the License from time to time. Each version
+ will be given a distinguishing version number.
+
+ 6.2. Effect of New Versions.
+ Once Covered Code has been published under a particular version of the
+ License, You may always continue to use it under the terms of that
+ version. You may also choose to use such Covered Code under the terms
+ of any subsequent version of the License published by Netscape. No one
+ other than Netscape has the right to modify the terms applicable to
+ Covered Code created under this License.
+
+ 6.3. Derivative Works.
+ If You create or use a modified version of this License (which you may
+ only do in order to apply it to code which is not already Covered Code
+ governed by this License), You must (a) rename Your license so that
+ the phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape",
+ "MPL", "NPL" or any confusingly similar phrase do not appear in your
+ license (except to note that your license differs from this License)
+ and (b) otherwise make it clear that Your version of the license
+ contains terms which differ from the Mozilla Public License and
+ Netscape Public License. (Filling in the name of the Initial
+ Developer, Original Code or Contributor in the notice described in
+ Exhibit A shall not of themselves be deemed to be modifications of
+ this License.)
+
+7. DISCLAIMER OF WARRANTY.
+
+ COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF
+ DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING.
+ THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE
+ IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT,
+ YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE
+ COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER
+ OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF
+ ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
+
+8. TERMINATION.
+
+ 8.1. This License and the rights granted hereunder will terminate
+ automatically if You fail to comply with terms herein and fail to cure
+ such breach within 30 days of becoming aware of the breach. All
+ sublicenses to the Covered Code which are properly granted shall
+ survive any termination of this License. Provisions which, by their
+ nature, must remain in effect beyond the termination of this License
+ shall survive.
+
+ 8.2. If You initiate litigation by asserting a patent infringement
+ claim (excluding declatory judgment actions) against Initial Developer
+ or a Contributor (the Initial Developer or Contributor against whom
+ You file such action is referred to as "Participant") alleging that:
+
+ (a) such Participant's Contributor Version directly or indirectly
+ infringes any patent, then any and all rights granted by such
+ Participant to You under Sections 2.1 and/or 2.2 of this License
+ shall, upon 60 days notice from Participant terminate prospectively,
+ unless if within 60 days after receipt of notice You either: (i)
+ agree in writing to pay Participant a mutually agreeable reasonable
+ royalty for Your past and future use of Modifications made by such
+ Participant, or (ii) withdraw Your litigation claim with respect to
+ the Contributor Version against such Participant. If within 60 days
+ of notice, a reasonable royalty and payment arrangement are not
+ mutually agreed upon in writing by the parties or the litigation claim
+ is not withdrawn, the rights granted by Participant to You under
+ Sections 2.1 and/or 2.2 automatically terminate at the expiration of
+ the 60 day notice period specified above.
+
+ (b) any software, hardware, or device, other than such Participant's
+ Contributor Version, directly or indirectly infringes any patent, then
+ any rights granted to You by such Participant under Sections 2.1(b)
+ and 2.2(b) are revoked effective as of the date You first made, used,
+ sold, distributed, or had made, Modifications made by that
+ Participant.
+
+ 8.3. If You assert a patent infringement claim against Participant
+ alleging that such Participant's Contributor Version directly or
+ indirectly infringes any patent where such claim is resolved (such as
+ by license or settlement) prior to the initiation of patent
+ infringement litigation, then the reasonable value of the licenses
+ granted by such Participant under Sections 2.1 or 2.2 shall be taken
+ into account in determining the amount or value of any payment or
+ license.
+
+ 8.4. In the event of termination under Sections 8.1 or 8.2 above,
+ all end user license agreements (excluding distributors and resellers)
+ which have been validly granted by You or any distributor hereunder
+ prior to termination shall survive termination.
+
+9. LIMITATION OF LIABILITY.
+
+ UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
+ (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL
+ DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE,
+ OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR
+ ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY
+ CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL,
+ WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER
+ COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN
+ INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF
+ LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY
+ RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW
+ PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE
+ EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO
+ THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
+
+10. U.S. GOVERNMENT END USERS.
+
+ The Covered Code is a "commercial item," as that term is defined in
+ 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer
+ software" and "commercial computer software documentation," as such
+ terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48
+ C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995),
+ all U.S. Government End Users acquire Covered Code with only those
+ rights set forth herein.
+
+11. MISCELLANEOUS.
+
+ This License represents the complete agreement concerning subject
+ matter hereof. If any provision of this License is held to be
+ unenforceable, such provision shall be reformed only to the extent
+ necessary to make it enforceable. This License shall be governed by
+ California law provisions (except to the extent applicable law, if
+ any, provides otherwise), excluding its conflict-of-law provisions.
+ With respect to disputes in which at least one party is a citizen of,
+ or an entity chartered or registered to do business in the United
+ States of America, any litigation relating to this License shall be
+ subject to the jurisdiction of the Federal Courts of the Northern
+ District of California, with venue lying in Santa Clara County,
+ California, with the losing party responsible for costs, including
+ without limitation, court costs and reasonable attorneys' fees and
+ expenses. The application of the United Nations Convention on
+ Contracts for the International Sale of Goods is expressly excluded.
+ Any law or regulation which provides that the language of a contract
+ shall be construed against the drafter shall not apply to this
+ License.
+
+12. RESPONSIBILITY FOR CLAIMS.
+
+ As between Initial Developer and the Contributors, each party is
+ responsible for claims and damages arising, directly or indirectly,
+ out of its utilization of rights under this License and You agree to
+ work with Initial Developer and Contributors to distribute such
+ responsibility on an equitable basis. Nothing herein is intended or
+ shall be deemed to constitute any admission of liability.
+
+13. MULTIPLE-LICENSED CODE.
+
+ Initial Developer may designate portions of the Covered Code as
+ "Multiple-Licensed". "Multiple-Licensed" means that the Initial
+ Developer permits you to utilize portions of the Covered Code under
+ Your choice of the NPL or the alternative licenses, if any, specified
+ by the Initial Developer in the file described in Exhibit A.
+
+EXHIBIT A -Mozilla Public License.
+
+ ``The contents of this file are subject to the Mozilla Public License
+ Version 1.1 (the "License"); you may not use this file except in
+ compliance with the License. You may obtain a copy of the License at
+ http://www.mozilla.org/MPL/
+
+ Software distributed under the License is distributed on an "AS IS"
+ basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ License for the specific language governing rights and limitations
+ under the License.
+
+ The Original Code is ______________________________________.
+
+ The Initial Developer of the Original Code is ________________________.
+ Portions created by ______________________ are Copyright (C) ______
+ _______________________. All Rights Reserved.
+
+ Contributor(s): ______________________________________.
+
+ Alternatively, the contents of this file may be used under the terms
+ of the _____ license (the "[___] License"), in which case the
+ provisions of [______] License are applicable instead of those
+ above. If you wish to allow use of your version of this file only
+ under the terms of the [____] License and not to allow others to use
+ your version of this file under the MPL, indicate your decision by
+ deleting the provisions above and replace them with the notice and
+ other provisions required by the [___] License. If you do not delete
+ the provisions above, a recipient may use your version of this file
+ under either the MPL or the [___] License."
+
+ [NOTE: The text of this Exhibit A may differ slightly from the text of
+ the notices in the Source Code files of the Original Code. You should
+ use the text of this Exhibit A rather than the text found in the
+ Original Code Source Code for Your Modifications.]
+
+
+===============================================================================
+
+For the JAX-WS Reference Implementation component:
+
+COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
+
+
+ 1. Definitions.
+
+ 1.1. "Contributor" means each individual or entity that
+ creates or contributes to the creation of Modifications.
+
+ 1.2. "Contributor Version" means the combination of the
+ Original Software, prior Modifications used by a
+ Contributor (if any), and the Modifications made by that
+ particular Contributor.
+
+ 1.3. "Covered Software" means (a) the Original Software, or
+ (b) Modifications, or (c) the combination of files
+ containing Original Software with files containing
+ Modifications, in each case including portions thereof.
+
+ 1.4. "Executable" means the Covered Software in any form
+ other than Source Code.
+
+ 1.5. "Initial Developer" means the individual or entity
+ that first makes Original Software available under this
+ License.
+
+ 1.6. "Larger Work" means a work which combines Covered
+ Software or portions thereof with code not governed by the
+ terms of this License.
+
+ 1.7. "License" means this document.
+
+ 1.8. "Licensable" means having the right to grant, to the
+ maximum extent possible, whether at the time of the initial
+ grant or subsequently acquired, any and all of the rights
+ conveyed herein.
+
+ 1.9. "Modifications" means the Source Code and Executable
+ form of any of the following:
+
+ A. Any file that results from an addition to,
+ deletion from or modification of the contents of a
+ file containing Original Software or previous
+ Modifications;
+
+ B. Any new file that contains any part of the
+ Original Software or previous Modification; or
+
+ C. Any new file that is contributed or otherwise made
+ available under the terms of this License.
+
+ 1.10. "Original Software" means the Source Code and
+ Executable form of computer software code that is
+ originally released under this License.
+
+ 1.11. "Patent Claims" means any patent claim(s), now owned
+ or hereafter acquired, including without limitation,
+ method, process, and apparatus claims, in any patent
+ Licensable by grantor.
+
+ 1.12. "Source Code" means (a) the common form of computer
+ software code in which modifications are made and (b)
+ associated documentation included in or with such code.
+
+ 1.13. "You" (or "Your") means an individual or a legal
+ entity exercising rights under, and complying with all of
+ the terms of, this License. For legal entities, "You"
+ includes any entity which controls, is controlled by, or is
+ under common control with You. For purposes of this
+ definition, "control" means (a) the power, direct or
+ indirect, to cause the direction or management of such
+ entity, whether by contract or otherwise, or (b) ownership
+ of more than fifty percent (50%) of the outstanding shares
+ or beneficial ownership of such entity.
+
+ 2. License Grants.
+
+ 2.1. The Initial Developer Grant.
+
+ Conditioned upon Your compliance with Section 3.1 below and
+ subject to third party intellectual property claims, the
+ Initial Developer hereby grants You a world-wide,
+ royalty-free, non-exclusive license:
+
+ (a) under intellectual property rights (other than
+ patent or trademark) Licensable by Initial Developer,
+ to use, reproduce, modify, display, perform,
+ sublicense and distribute the Original Software (or
+ portions thereof), with or without Modifications,
+ and/or as part of a Larger Work; and
+
+ (b) under Patent Claims infringed by the making,
+ using or selling of Original Software, to make, have
+ made, use, practice, sell, and offer for sale, and/or
+ otherwise dispose of the Original Software (or
+ portions thereof).
+
+ (c) The licenses granted in Sections 2.1(a) and (b)
+ are effective on the date Initial Developer first
+ distributes or otherwise makes the Original Software
+ available to a third party under the terms of this
+ License.
+
+ (d) Notwithstanding Section 2.1(b) above, no patent
+ license is granted: (1) for code that You delete from
+ the Original Software, or (2) for infringements
+ caused by: (i) the modification of the Original
+ Software, or (ii) the combination of the Original
+ Software with other software or devices.
+
+ 2.2. Contributor Grant.
+
+ Conditioned upon Your compliance with Section 3.1 below and
+ subject to third party intellectual property claims, each
+ Contributor hereby grants You a world-wide, royalty-free,
+ non-exclusive license:
+
+ (a) under intellectual property rights (other than
+ patent or trademark) Licensable by Contributor to
+ use, reproduce, modify, display, perform, sublicense
+ and distribute the Modifications created by such
+ Contributor (or portions thereof), either on an
+ unmodified basis, with other Modifications, as
+ Covered Software and/or as part of a Larger Work; and
+
+
+ (b) under Patent Claims infringed by the making,
+ using, or selling of Modifications made by that
+ Contributor either alone and/or in combination with
+ its Contributor Version (or portions of such
+ combination), to make, use, sell, offer for sale,
+ have made, and/or otherwise dispose of: (1)
+ Modifications made by that Contributor (or portions
+ thereof); and (2) the combination of Modifications
+ made by that Contributor with its Contributor Version
+ (or portions of such combination).
+
+ (c) The licenses granted in Sections 2.2(a) and
+ 2.2(b) are effective on the date Contributor first
+ distributes or otherwise makes the Modifications
+ available to a third party.
+
+ (d) Notwithstanding Section 2.2(b) above, no patent
+ license is granted: (1) for any code that Contributor
+ has deleted from the Contributor Version; (2) for
+ infringements caused by: (i) third party
+ modifications of Contributor Version, or (ii) the
+ combination of Modifications made by that Contributor
+ with other software (except as part of the
+ Contributor Version) or other devices; or (3) under
+ Patent Claims infringed by Covered Software in the
+ absence of Modifications made by that Contributor.
+
+ 3. Distribution Obligations.
+
+ 3.1. Availability of Source Code.
+
+ Any Covered Software that You distribute or otherwise make
+ available in Executable form must also be made available in
+ Source Code form and that Source Code form must be
+ distributed only under the terms of this License. You must
+ include a copy of this License with every copy of the
+ Source Code form of the Covered Software You distribute or
+ otherwise make available. You must inform recipients of any
+ such Covered Software in Executable form as to how they can
+ obtain such Covered Software in Source Code form in a
+ reasonable manner on or through a medium customarily used
+ for software exchange.
+
+ 3.2. Modifications.
+
+ The Modifications that You create or to which You
+ contribute are governed by the terms of this License. You
+ represent that You believe Your Modifications are Your
+ original creation(s) and/or You have sufficient rights to
+ grant the rights conveyed by this License.
+
+ 3.3. Required Notices.
+
+ You must include a notice in each of Your Modifications
+ that identifies You as the Contributor of the Modification.
+ You may not remove or alter any copyright, patent or
+ trademark notices contained within the Covered Software, or
+ any notices of licensing or any descriptive text giving
+ attribution to any Contributor or the Initial Developer.
+
+ 3.4. Application of Additional Terms.
+
+ You may not offer or impose any terms on any Covered
+ Software in Source Code form that alters or restricts the
+ applicable version of this License or the recipients'
+ rights hereunder. You may choose to offer, and to charge a
+ fee for, warranty, support, indemnity or liability
+ obligations to one or more recipients of Covered Software.
+ However, you may do so only on Your own behalf, and not on
+ behalf of the Initial Developer or any Contributor. You
+ must make it absolutely clear that any such warranty,
+ support, indemnity or liability obligation is offered by
+ You alone, and You hereby agree to indemnify the Initial
+ Developer and every Contributor for any liability incurred
+ by the Initial Developer or such Contributor as a result of
+ warranty, support, indemnity or liability terms You offer.
+
+
+ 3.5. Distribution of Executable Versions.
+
+ You may distribute the Executable form of the Covered
+ Software under the terms of this License or under the terms
+ of a license of Your choice, which may contain terms
+ different from this License, provided that You are in
+ compliance with the terms of this License and that the
+ license for the Executable form does not attempt to limit
+ or alter the recipient's rights in the Source Code form
+ from the rights set forth in this License. If You
+ distribute the Covered Software in Executable form under a
+ different license, You must make it absolutely clear that
+ any terms which differ from this License are offered by You
+ alone, not by the Initial Developer or Contributor. You
+ hereby agree to indemnify the Initial Developer and every
+ Contributor for any liability incurred by the Initial
+ Developer or such Contributor as a result of any such terms
+ You offer.
+
+ 3.6. Larger Works.
+
+ You may create a Larger Work by combining Covered Software
+ with other code not governed by the terms of this License
+ and distribute the Larger Work as a single product. In such
+ a case, You must make sure the requirements of this License
+ are fulfilled for the Covered Software.
+
+ 4. Versions of the License.
+
+ 4.1. New Versions.
+
+ Sun Microsystems, Inc. is the initial license steward and
+ may publish revised and/or new versions of this License
+ from time to time. Each version will be given a
+ distinguishing version number. Except as provided in
+ Section 4.3, no one other than the license steward has the
+ right to modify this License.
+
+ 4.2. Effect of New Versions.
+
+ You may always continue to use, distribute or otherwise
+ make the Covered Software available under the terms of the
+ version of the License under which You originally received
+ the Covered Software. If the Initial Developer includes a
+ notice in the Original Software prohibiting it from being
+ distributed or otherwise made available under any
+ subsequent version of the License, You must distribute and
+ make the Covered Software available under the terms of the
+ version of the License under which You originally received
+ the Covered Software. Otherwise, You may also choose to
+ use, distribute or otherwise make the Covered Software
+ available under the terms of any subsequent version of the
+ License published by the license steward.
+
+ 4.3. Modified Versions.
+
+ When You are an Initial Developer and You want to create a
+ new license for Your Original Software, You may create and
+ use a modified version of this License if You: (a) rename
+ the license and remove any references to the name of the
+ license steward (except to note that the license differs
+ from this License); and (b) otherwise make it clear that
+ the license contains terms which differ from this License.
+
+
+ 5. DISCLAIMER OF WARRANTY.
+
+ COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS"
+ BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
+ INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED
+ SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR
+ PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND
+ PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY
+ COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE
+ INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF
+ ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF
+ WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF
+ ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS
+ DISCLAIMER.
+
+ 6. TERMINATION.
+
+ 6.1. This License and the rights granted hereunder will
+ terminate automatically if You fail to comply with terms
+ herein and fail to cure such breach within 30 days of
+ becoming aware of the breach. Provisions which, by their
+ nature, must remain in effect beyond the termination of
+ this License shall survive.
+
+ 6.2. If You assert a patent infringement claim (excluding
+ declaratory judgment actions) against Initial Developer or
+ a Contributor (the Initial Developer or Contributor against
+ whom You assert such claim is referred to as "Participant")
+ alleging that the Participant Software (meaning the
+ Contributor Version where the Participant is a Contributor
+ or the Original Software where the Participant is the
+ Initial Developer) directly or indirectly infringes any
+ patent, then any and all rights granted directly or
+ indirectly to You by such Participant, the Initial
+ Developer (if the Initial Developer is not the Participant)
+ and all Contributors under Sections 2.1 and/or 2.2 of this
+ License shall, upon 60 days notice from Participant
+ terminate prospectively and automatically at the expiration
+ of such 60 day notice period, unless if within such 60 day
+ period You withdraw Your claim with respect to the
+ Participant Software against such Participant either
+ unilaterally or pursuant to a written agreement with
+ Participant.
+
+ 6.3. In the event of termination under Sections 6.1 or 6.2
+ above, all end user licenses that have been validly granted
+ by You or any distributor hereunder prior to termination
+ (excluding licenses granted to You by any distributor)
+ shall survive termination.
+
+ 7. LIMITATION OF LIABILITY.
+
+ UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
+ (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE
+ INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF
+ COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE
+ LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT
+ LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK
+ STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER
+ COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN
+ INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF
+ LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL
+ INJURY RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT
+ APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO
+ NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR
+ CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT
+ APPLY TO YOU.
+
+ 8. U.S. GOVERNMENT END USERS.
+
+ The Covered Software is a "commercial item," as that term is
+ defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial
+ computer software" (as that term is defined at 48 C.F.R.
+ 252.227-7014(a)(1)) and "commercial computer software
+ documentation" as such terms are used in 48 C.F.R. 12.212 (Sept.
+ 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1
+ through 227.7202-4 (June 1995), all U.S. Government End Users
+ acquire Covered Software with only those rights set forth herein.
+ This U.S. Government Rights clause is in lieu of, and supersedes,
+ any other FAR, DFAR, or other clause or provision that addresses
+ Government rights in computer software under this License.
+
+ 9. MISCELLANEOUS.
+
+ This License represents the complete agreement concerning subject
+ matter hereof. If any provision of this License is held to be
+ unenforceable, such provision shall be reformed only to the
+ extent necessary to make it enforceable. This License shall be
+ governed by the law of the jurisdiction specified in a notice
+ contained within the Original Software (except to the extent
+ applicable law, if any, provides otherwise), excluding such
+ jurisdiction's conflict-of-law provisions. Any litigation
+ relating to this License shall be subject to the jurisdiction of
+ the courts located in the jurisdiction and venue specified in a
+ notice contained within the Original Software, with the losing
+ party responsible for costs, including, without limitation, court
+ costs and reasonable attorneys' fees and expenses. The
+ application of the United Nations Convention on Contracts for the
+ International Sale of Goods is expressly excluded. Any law or
+ regulation which provides that the language of a contract shall
+ be construed against the drafter shall not apply to this License.
+ You agree that You alone are responsible for compliance with the
+ United States export administration regulations (and the export
+ control laws and regulation of any other countries) when You use,
+ distribute or otherwise make available any Covered Software.
+
+ 10. RESPONSIBILITY FOR CLAIMS.
+
+ As between Initial Developer and the Contributors, each party is
+ responsible for claims and damages arising, directly or
+ indirectly, out of its utilization of rights under this License
+ and You agree to work with Initial Developer and Contributors to
+ distribute such responsibility on an equitable basis. Nothing
+ herein is intended or shall be deemed to constitute any admission
+ of liability.
+
diff --git a/tags/java/tsss-demo/runtime/itest/smoketest/NOTICE.txt b/tags/java/tsss-demo/runtime/itest/smoketest/NOTICE.txt
new file mode 100644
index 0000000000..d83ebbe236
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/smoketest/NOTICE.txt
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/runtime/itest/smoketest/pom.xml b/tags/java/tsss-demo/runtime/itest/smoketest/pom.xml
new file mode 100644
index 0000000000..d6a2023c91
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/smoketest/pom.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca.runtime</groupId>
+ <artifactId>itest</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.runtime.itest</groupId>
+ <artifactId>itest-smoketest</artifactId>
+ <name>Apache Tuscany Integration Test Smoketest</name>
+ <description>Smoketest for the ITest plugin</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osoa</groupId>
+ <artifactId>sca-api-r1.0</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.tuscany</groupId>
+ <artifactId>tuscany-itest-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tags/java/tsss-demo/runtime/itest/smoketest/src/main/java/org/apache/tuscany/sca/runtime/itest/smoketest/HelloService.java b/tags/java/tsss-demo/runtime/itest/smoketest/src/main/java/org/apache/tuscany/sca/runtime/itest/smoketest/HelloService.java
new file mode 100644
index 0000000000..34c7a1ec12
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/smoketest/src/main/java/org/apache/tuscany/sca/runtime/itest/smoketest/HelloService.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.runtime.itest.smoketest;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface HelloService {
+ String getGreeting();
+}
diff --git a/tags/java/tsss-demo/runtime/itest/smoketest/src/main/java/org/apache/tuscany/sca/runtime/itest/smoketest/HelloServiceImpl.java b/tags/java/tsss-demo/runtime/itest/smoketest/src/main/java/org/apache/tuscany/sca/runtime/itest/smoketest/HelloServiceImpl.java
new file mode 100644
index 0000000000..f269dc09c1
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/smoketest/src/main/java/org/apache/tuscany/sca/runtime/itest/smoketest/HelloServiceImpl.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.runtime.itest.smoketest;
+
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class HelloServiceImpl implements HelloService {
+ private final String greeting;
+
+ public HelloServiceImpl(@Property(name="greeting")String greeting) {
+ this.greeting = greeting;
+ }
+
+ public String getGreeting() {
+ return greeting;
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/itest/smoketest/src/main/resources/META-INF/sca/default.scdl b/tags/java/tsss-demo/runtime/itest/smoketest/src/main/resources/META-INF/sca/default.scdl
new file mode 100644
index 0000000000..bc000a9365
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/smoketest/src/main/resources/META-INF/sca/default.scdl
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ name="ITestSmoketestComposite">
+
+ <component name="Hello">
+ <implementation.java class="org.apache.tuscany.sca.runtime.itest.smoketest.HelloServiceImpl"/>
+ <property name="greeting">Hello World</property>
+ </component>
+</composite>
diff --git a/tags/java/tsss-demo/runtime/itest/smoketest/src/test/java/org/apache/tuscany/sca/runtime/itest/smoketest/BasicTestComponent.java b/tags/java/tsss-demo/runtime/itest/smoketest/src/test/java/org/apache/tuscany/sca/runtime/itest/smoketest/BasicTestComponent.java
new file mode 100644
index 0000000000..895989330b
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/smoketest/src/test/java/org/apache/tuscany/sca/runtime/itest/smoketest/BasicTestComponent.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.itest.smoketest;
+
+import junit.framework.TestCase;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class BasicTestComponent extends TestCase {
+ @Reference
+ public HelloService hello;
+
+ public void testGreeting() {
+ assertEquals("Hello World", hello.getGreeting());
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/itest/smoketest/src/test/resources/itest.scdl b/tags/java/tsss-demo/runtime/itest/smoketest/src/test/resources/itest.scdl
new file mode 100644
index 0000000000..2cfa767a34
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/itest/smoketest/src/test/resources/itest.scdl
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/2.0-alpha"
+ name="TestHarnessComposite">
+
+ <include name="ITestSmoketestComposite" scdlResource="META-INF/sca/default.scdl"/>
+
+ <component name="testComponent">
+ <tuscany:junit class="org.apache.tuscany.sca.runtime.itest.smoketest.BasicTestComponent"/>
+ <reference name="hello" target="Hello"/>
+ </component>
+</composite>
diff --git a/tags/java/tsss-demo/runtime/pom.xml b/tags/java/tsss-demo/runtime/pom.xml
new file mode 100644
index 0000000000..07e958a11c
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/pom.xml
@@ -0,0 +1,166 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany</groupId>
+ <artifactId>sca</artifactId>
+ <version>1.0-incubating</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>runtime</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ <packaging>pom</packaging>
+ <name>Apache Tuscany SCA Runtime Environments</name>
+ <description>Parent POM for all runtime environments</description>
+
+ <properties>
+ <!-- version the SCA API that we implement -->
+ <scaSpecVersion>1.0</scaSpecVersion>
+
+ <!-- version the Apache Tuscany kernel that the runtimes work with -->
+ <kernelVersion>2.0-alpha2-incubating-SNAPSHOT</kernelVersion>
+ </properties>
+
+ <!-- definition of repositories where the parent pom can be found -->
+ <repositories>
+ <repository>
+ <id>apache.incubator</id>
+ <name>Apache Incubator Repository</name>
+ <url>http://people.apache.org/repo/m2-incubating-repository/</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+
+ <dependencyManagement>
+ <dependencies>
+ <!-- org.osoa.sca API -->
+ <dependency>
+ <groupId>org.osoa</groupId>
+ <artifactId>sca-api-r${scaSpecVersion}</artifactId>
+ <version>1.0-incubating</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Apache Tuscany kernel artifacts -->
+ <dependency>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-api</artifactId>
+ <version>${kernelVersion}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-host-api</artifactId>
+ <version>${kernelVersion}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-spi</artifactId>
+ <version>${kernelVersion}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-core</artifactId>
+ <version>${kernelVersion}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <!-- StAX implementation -->
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ <version>3.2.0</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <!-- junit version -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- EasyMock version -->
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>2.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ <version>2.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <modules>
+ <module>services</module>
+ <module>standalone</module>
+ <module>webapp</module>
+ <module>itest</module>
+ </modules>
+
+ <profiles>
+ <profile>
+ <!-- default profile that just builds the jar files -->
+ <id>default</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <build>
+ <defaultGoal>install</defaultGoal>
+ </build>
+ </profile>
+
+ <profile>
+ <!-- release profile that prepares artifacts for release -->
+ <id>release</id>
+ <build>
+ <defaultGoal>verify</defaultGoal>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-gpg-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>sign</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+</project>
diff --git a/tags/java/tsss-demo/runtime/services/contribution/.checkstyle b/tags/java/tsss-demo/runtime/services/contribution/.checkstyle
new file mode 100644
index 0000000000..e3c216986d
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/contribution/.checkstyle
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<fileset-config file-format-version="1.2.0" simple-config="true">
+ <fileset name="all" enabled="true" check-config-name="Tuscany Checks" local="false">
+ <file-match-pattern match-pattern="." include-pattern="true"/>
+ </fileset>
+</fileset-config>
diff --git a/tags/java/tsss-demo/runtime/services/contribution/.pmd b/tags/java/tsss-demo/runtime/services/contribution/.pmd
new file mode 100644
index 0000000000..84af2f4d5d
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/contribution/.pmd
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<pmd><useProjectRuleSet>true</useProjectRuleSet><rules/></pmd>
diff --git a/tags/java/tsss-demo/runtime/services/contribution/.ruleset b/tags/java/tsss-demo/runtime/services/contribution/.ruleset
new file mode 100644
index 0000000000..ac8671859d
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/contribution/.ruleset
@@ -0,0 +1,190 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<ruleset name="pmd-eclipse">
+ <description>PMD Plugin preferences rule set</description>
+
+
+ <rule ref="rulesets/basic.xml/BooleanInstantiation"/>
+ <rule ref="rulesets/basic.xml/CollapsibleIfStatements"/>
+ <rule ref="rulesets/basic.xml/DoubleCheckedLocking"/>
+<!--<rule ref="rulesets/basic.xml/EmptyCatchBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyFinallyBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyIfStmt"/>-->
+ <rule ref="rulesets/basic.xml/EmptyStatementNotInLoop"/>
+<!--<rule ref="rulesets/basic.xml/EmptyStaticInitializer"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptySwitchStatements"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptySynchronizedBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyTryBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyWhileStmt"/>-->
+ <rule ref="rulesets/basic.xml/ForLoopShouldBeWhileLoop"/>
+ <rule ref="rulesets/basic.xml/JumbledIncrementer"/>
+<!--<rule ref="rulesets/basic.xml/OverrideBothEqualsAndHashcode"/>-->
+ <rule ref="rulesets/basic.xml/ReturnFromFinallyBlock"/>
+ <rule ref="rulesets/basic.xml/UnconditionalIfStatement"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryConversionTemporary"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryFinalModifier"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryReturn"/>
+<!--<rule ref="rulesets/basic.xml/UselessOverridingMethod"/>-->
+
+<!--<rule ref="rulesets/braces.xml/ForLoopsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/IfElseStmtsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/IfStmtsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/WhileLoopsMustUseBraces"/>-->
+
+<!--<rule ref="rulesets/clone.xml/CloneMethodMustImplementCloneable"/>-->
+<!--<rule ref="rulesets/clone.xml/CloneThrowsCloneNotSupportedException"/>-->
+<!--<rule ref="rulesets/clone.xml/ProperCloneImplementation"/>-->
+
+<!--<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>-->
+<!--<rule ref="rulesets/codesize.xml/TooManyFields"/>-->
+
+<rule ref="rulesets/controversial.xml/AssignmentInOperand"/>
+<!--<rule ref="rulesets/controversial.xml/AtLeastOneConstructor"/>-->
+<!--<rule ref="rulesets/controversial.xml/CallSuperInConstructor"/>-->
+<!--<rule ref="rulesets/controversial.xml/DontImportSun"/>-->
+<!--<rule ref="rulesets/controversial.xml/NullAssignment"/>-->
+<!--<rule ref="rulesets/controversial.xml/OnlyOneReturn"/>-->
+<!--<rule ref="rulesets/controversial.xml/SingularField"/>-->
+<!--<rule ref="rulesets/controversial.xml/SuspiciousOctalEscape"/>-->
+<!--<rule ref="rulesets/controversial.xml/UnnecessaryConstructor"/>-->
+<rule ref="rulesets/controversial.xml/UnnecessaryParentheses"/>
+<!--<rule ref="rulesets/controversial.xml/UnusedModifier"/>-->
+
+<!--<rule ref="rulesets/coupling.xml/CouplingBetweenObjects"/>-->
+<!--<rule ref="rulesets/coupling.xml/ExcessiveImports"/>-->
+<!--<rule ref="rulesets/coupling.xml/LooseCoupling"/>-->
+
+<!--<rule ref="rulesets/design.xml/AbstractClassWithoutAbstractMethod"/>-->
+<!--<rule ref="rulesets/design.xml/AccessorClassGeneration"/>-->
+<!--<rule ref="rulesets/design.xml/AssignmentToNonFinalStatic"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidDeeplyNestedIfStmts"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidInstanceofChecksInCatchClause"/>-->
+<rule ref="rulesets/design.xml/AvoidProtectedFieldInFinalClass"/>
+<!--<rule ref="rulesets/design.xml/AvoidReassigningParameters"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidSynchronizedAtMethodLevel"/>-->
+<!--<rule ref="rulesets/design.xml/BadComparison"/>-->
+<!--<rule ref="rulesets/design.xml/CloseConnection"/>-->
+<!--<rule ref="rulesets/design.xml/CompareObjectsWithEquals"/>-->
+<!--<rule ref="rulesets/design.xml/ConfusingTernary"/>-->
+<rule ref="rulesets/design.xml/ConstructorCallsOverridableMethod"/>
+<!--<rule ref="rulesets/design.xml/DefaultLabelNotLastInSwitchStmt"/>-->
+<!--<rule ref="rulesets/design.xml/FinalFieldCouldBeStatic"/>-->
+<rule ref="rulesets/design.xml/IdempotentOperations"/>
+<!--<rule ref="rulesets/design.xml/ImmutableField"/>-->
+<!--<rule ref="rulesets/design.xml/InstantiationToGetClass"/>-->
+<!--<rule ref="rulesets/design.xml/MissingBreakInSwitch"/>-->
+<!--<rule ref="rulesets/design.xml/MissingStaticMethodInNonInstantiatableClass"/>-->
+<!--<rule ref="rulesets/design.xml/NonCaseLabelInSwitchStatement"/>-->
+<!--<rule ref="rulesets/design.xml/NonStaticInitializer"/>-->
+<rule ref="rulesets/design.xml/OptimizableToArrayCall"/>
+<rule ref="rulesets/design.xml/PositionLiteralsFirstInComparisons"/>
+<rule ref="rulesets/design.xml/SimplifyBooleanExpressions"/>
+<rule ref="rulesets/design.xml/SimplifyBooleanReturns"/>
+<rule ref="rulesets/design.xml/SimplifyConditional"/>
+<!--<rule ref="rulesets/design.xml/SwitchDensity"/>-->
+<!--<rule ref="rulesets/design.xml/SwitchStmtsShouldHaveDefault"/>-->
+<rule ref="rulesets/design.xml/UnnecessaryLocalBeforeReturn"/>
+<!--<rule ref="rulesets/design.xml/UseLocaleWithCaseConversions"/>-->
+<!--<rule ref="rulesets/design.xml/UseNotifyAllInsteadOfNotify"/>-->
+<!--<rule ref="rulesets/design.xml/UseSingleton"/>-->
+
+<!--<rule ref="rulesets/finalizers.xml/EmptyFinalizer"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeOnlyCallsSuperFinalize"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeOverloaded"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeDoesNotCallSuperFinalize"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeShouldBeProtected"/>-->
+<!--<rule ref="rulesets/finalizers.xml/AvoidCallingFinalize"/>-->
+
+<!--<rule ref="rulesets/imports.xml/DuplicateImports"/>-->
+<!--<rule ref="rulesets/imports.xml/DontImportJavaLang"/>-->
+<!--<rule ref="rulesets/imports.xml/UnusedImports"/>-->
+<!--<rule ref="rulesets/imports.xml/ImportFromSamePackage"/>-->
+
+<!--<rule ref="rulesets/javabeans.xml/BeanMembersShouldSerialize"/>-->
+<!--<rule ref="rulesets/javabeans.xml/MissingSerialVersionUID"/>-->
+
+<!--<rule ref="rulesets/junit.xml/JUnitStaticSuite"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitSpelling"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitAssertionsShouldIncludeMessage"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitTestsShouldIncludeAssert"/>-->
+<!--<rule ref="rulesets/junit.xml/TestClassWithoutTestCases"/>-->
+<!--<rule ref="rulesets/junit.xml/UnnecessaryBooleanAssertion"/>-->
+<!--<rule ref="rulesets/junit.xml/UseAssertEqualsInsteadOfAssertTrue"/>-->
+<!--<rule ref="rulesets/junit.xml/UseAssertSameInsteadOfAssertTrue"/>-->
+
+ <!--<rule ref="rulesets/logging-java.xml/AvoidPrintStackTrace"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/MoreThanOneLogger"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LogBlockWithoutIf"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/SystemPrintln"/>-->
+ <!--<rule ref="rulesets/logging-jakarta-commons.xml/UseCorrectExceptionLogging"/>-->
+ <!--<rule ref="rulesets/logging-jakarta-commons.xml/ProperLogger"/>-->
+
+ <!--<rule ref="rulesets/naming.xml/ShortVariable"/>-->
+ <!--<rule ref="rulesets/naming.xml/LongVariable"/>-->
+ <!--<rule ref="rulesets/naming.xml/ShortMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/VariableNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/MethodNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/ClassNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/AbstractNaming"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidDollarSigns"/>-->
+ <!--<rule ref="rulesets/naming.xml/MethodWithSameNameAsEnclosingClass"/>-->
+ <!--<rule ref="rulesets/naming.xml/SuspiciousHashcodeMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/SuspiciousConstantFieldName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingTypeName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidNonConstructorMethodsWithClassName"/>-->
+ <!--<rule ref="rulesets/naming.xml/NoPackage"/>-->
+ <!--<rule ref="rulesets/naming.xml/PackageCase"/>-->
+
+ <!--<rule ref="rulesets/optimizations.xml/LocalVariableCouldBeFinal"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/MethodArgumentCouldBeFinal"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/AvoidInstantiatingObjectsInLoops"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/UseArrayListInsteadOfVector"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/SimplifyStartsWith"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/UseStringBufferForStringAppends"/>-->
+
+ <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingThrowable"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/SignatureDeclareThrowsException"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/ExceptionAsFlowControl"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingNPE"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingRawExceptionTypes"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingNullPointerException"/>-->
+
+ <!--<rule ref="rulesets/strings.xml/AvoidDuplicateLiterals"/>-->
+ <!--<rule ref="rulesets/strings.xml/StringInstantiation"/>-->
+ <!--<rule ref="rulesets/strings.xml/StringToString"/>-->
+ <!--<rule ref="rulesets/strings.xml/AvoidConcatenatingNonLiteralsInStringBuffer"/>-->
+ <!--<rule ref="rulesets/strings.xml/UnnecessaryCaseChange"/>-->
+
+ <!--<rule ref="rulesets/sunsecure.xml/MethodReturnsInternalArray"/>-->
+ <!--<rule ref="rulesets/sunsecure.xml/ArrayIsStoredDirectly"/>-->
+
+ <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/>
+ <rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/>
+ <rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/>
+ <!--<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>-->
+
+</ruleset>
diff --git a/tags/java/tsss-demo/runtime/services/contribution/LICENSE.txt b/tags/java/tsss-demo/runtime/services/contribution/LICENSE.txt
new file mode 100644
index 0000000000..5f6ab3e05c
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/contribution/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, serviceDefinition marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/runtime/services/contribution/NOTICE.txt b/tags/java/tsss-demo/runtime/services/contribution/NOTICE.txt
new file mode 100644
index 0000000000..ecc68a9614
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/contribution/NOTICE.txt
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/runtime/services/contribution/pom.xml b/tags/java/tsss-demo/runtime/services/contribution/pom.xml
new file mode 100644
index 0000000000..d1ca2c0225
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/contribution/pom.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca.runtime</groupId>
+ <artifactId>services</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.runtime.services.contribution</groupId>
+ <artifactId>contribution</artifactId>
+ <name>Apache Tuscany SCA Contribution Services</name>
+ <description>Apache Tuscany SCA Contribution Services</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osoa</groupId>
+ <artifactId>sca-api-r${scaSpecVersion}</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/tags/java/tsss-demo/runtime/services/management/jmx/LICENSE.txt b/tags/java/tsss-demo/runtime/services/management/jmx/LICENSE.txt
new file mode 100644
index 0000000000..0084319535
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/management/jmx/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, serviceDefinition marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/runtime/services/management/jmx/NOTICE.txt b/tags/java/tsss-demo/runtime/services/management/jmx/NOTICE.txt
new file mode 100644
index 0000000000..d83ebbe236
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/management/jmx/NOTICE.txt
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/runtime/services/management/jmx/pom.xml b/tags/java/tsss-demo/runtime/services/management/jmx/pom.xml
new file mode 100644
index 0000000000..fb49a0dcc0
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/management/jmx/pom.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+
+ <parent>
+ <groupId>org.apache.tuscany.sca.runtime.services</groupId>
+ <artifactId>management</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.runtime.services.management</groupId>
+ <artifactId>management-jmx</artifactId>
+ <packaging>jar</packaging>
+ <name>Apache Tuscany JMX Management</name>
+ <description>Apache Tuscany JMX Management</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-spi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/JmxException.java b/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/JmxException.java
new file mode 100644
index 0000000000..58e205189c
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/JmxException.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.service.management.jmx;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * Maps JMX exceptions to runtime exceptions.
+ *
+ * @version $Revision$ $Date$
+ */
+@SuppressWarnings("serial")
+public class JmxException extends TuscanyRuntimeException {
+
+ /**
+ * Initializes the root cause.
+ * @param cause Initializes the root cause.
+ */
+ public JmxException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Initializes the root cause.
+ * @param message Message for the exception.
+ * @param cause Initializes the root cause.
+ */
+ public JmxException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/JmxManagementService.java b/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/JmxManagementService.java
new file mode 100644
index 0000000000..2fa3675b4f
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/JmxManagementService.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.service.management.jmx;
+
+import javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.tuscany.service.management.jmx.instrument.InstrumentedComponent;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.services.management.TuscanyManagementService;
+
+/**
+ * JMX implementation of the management service.
+ *
+ * @version $Revision$ $Date$
+ */
+public class JmxManagementService implements TuscanyManagementService {
+
+ /**
+ * MBean server used by the JMX management service.
+ */
+ private final MBeanServer mBeanServer;
+
+ /**
+ * Management domain used by the runtime.
+ */
+ private final String managementDomain;
+
+
+ /**
+ * Constructor that initializes the MBeanServer and domain to use for registering components.
+ *
+ * @param mBeanServer the MBeanServer components should be registered with
+ * @param managementDomain the JMX domain to use when generating ObjectNames
+ */
+ public JmxManagementService(MBeanServer mBeanServer, String managementDomain) {
+ this.mBeanServer = mBeanServer;
+ this.managementDomain = managementDomain;
+ }
+
+ /**
+ * @throws JmxException In case of an unexpected JMX exception.
+ * @see org.apache.tuscany.spi.services.management.TuscanyManagementService#registerComponent(
+ *java.lang.String,org.apache.tuscany.spi.component.Component)
+ */
+ public final void registerComponent(String name, Component component) throws JmxException {
+
+ try {
+ name = name.replace(":", "-");
+ ObjectName on = new ObjectName(managementDomain + ":" + "type=component,name=" + name);
+ InstrumentedComponent mbean = new InstrumentedComponent(component);
+ mBeanServer.registerMBean(mbean, on);
+ } catch (JMException ex) {
+ throw new JmxException("Unable to register " + name, ex);
+ }
+
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/AbstractAgent.java b/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/AbstractAgent.java
new file mode 100644
index 0000000000..0172b15d8c
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/AbstractAgent.java
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.service.management.jmx.agent;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnectorServer;
+import javax.management.remote.JMXConnectorServerFactory;
+import javax.management.remote.JMXServiceURL;
+
+/**
+ * Abstract super class for all the agents.
+ * @version $Revison$ $Date$
+ *
+ */
+public abstract class AbstractAgent implements Agent {
+
+ /** Root domain */
+ private static final String DOMAIN = "tuscany";
+
+ /** MBean server to use. */
+ private MBeanServer mBeanServer;
+
+ /** Start flag. */
+ private AtomicBoolean started = new AtomicBoolean();
+
+ /** RMI connector adaptor. */
+ private JMXConnectorServer connectorServer;
+
+ /**
+ * Initialies the server.
+ * @throws ManagementException If unable to start the agent.
+ */
+ protected AbstractAgent() throws ManagementException {
+ mBeanServer = MBeanServerFactory.createMBeanServer(DOMAIN);
+ }
+
+ /**
+ * @see org.apache.tuscany.service.management.jmx.agent.Agent#getMBeanServer()
+ */
+ public MBeanServer getMBeanServer() {
+ return mBeanServer;
+ }
+
+ /**
+ * @see org.apache.tuscany.service.management.jmx.agent.Agent#register(java.lang.Object, java.lang.String)
+ */
+ public final void register(Object instance, String name) throws ManagementException {
+
+ try {
+ mBeanServer.registerMBean(instance, new ObjectName(name));
+ } catch (Exception ex) {
+ throw new ManagementException(ex);
+ }
+
+ }
+
+ /**
+ * @see org.apache.tuscany.service.management.jmx.agent.Agent#start()
+ */
+ public final void start() throws ManagementException {
+
+ try {
+
+ if(started.get()) {
+ throw new IllegalArgumentException("Agent already started");
+ }
+
+ preStart();
+
+ JMXServiceURL url = getAdaptorUrl();
+ connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mBeanServer);
+
+ connectorServer.start();
+
+ started.set(true);
+
+ } catch (MalformedURLException ex) {
+ throw new ManagementException(ex);
+ } catch (IOException ex) {
+ throw new ManagementException(ex);
+ }
+
+ }
+
+ /**
+ * @see org.apache.tuscany.service.management.jmx.agent.Agent#shutdown()
+ */
+ public final void shutdown() throws ManagementException {
+
+ try {
+
+ if(!started.get()) {
+ throw new IllegalArgumentException("Agent not started");
+ }
+
+ connectorServer.stop();
+ postStop();
+ started.set(false);
+
+ } catch (IOException ex) {
+ throw new ManagementException(ex);
+ }
+
+ }
+
+ /**
+ * Gets the underlying MBean server.
+ * @return A reference to the mbean server.
+ */
+ protected MBeanServer getMbeanServer() {
+ return mBeanServer;
+ }
+
+ /**
+ * Gets the adaptor URL.
+ * @return Adaptor URL.
+ */
+ protected abstract JMXServiceURL getAdaptorUrl();
+
+ /**
+ * Any initialiation required for protocol specific agent.
+ *
+ */
+ protected abstract void preStart();
+
+ /**
+ * Any initialiation required for protocol specific agent.
+ *
+ */
+ protected abstract void postStop();
+
+}
diff --git a/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/Agent.java b/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/Agent.java
new file mode 100644
index 0000000000..30727e21bf
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/Agent.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.service.management.jmx.agent;
+
+import javax.management.MBeanServer;
+
+/**
+ * Interface to a JMX agent.
+ * @version $Revision$ $Date$
+ *
+ */
+public interface Agent {
+
+ /**
+ * Registers a managed bean.
+ * @param instance Instance to be registered.
+ * @param name Object name of the instance.
+ * @throws ManagementException If unable to register the object.
+ */
+ void register(Object instance, String name) throws ManagementException;
+
+ /**
+ * Starts the JMX server.
+ * @throws ManagementException If unable to start the server.
+ */
+ void start() throws ManagementException;
+
+ /**
+ * Shuts down the JMX server.
+ * @throws ManagementException If unable to shutdown the server.
+ */
+ void shutdown() throws ManagementException;
+
+ /**
+ * Gets the MBean server used by the agent.
+ * @return MBean server used by the agent.
+ */
+ MBeanServer getMBeanServer();
+
+}
diff --git a/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/ManagementException.java b/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/ManagementException.java
new file mode 100644
index 0000000000..6ff8c14ac6
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/ManagementException.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.service.management.jmx.agent;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * @version $Revision$ $Date$
+ *
+ */
+@SuppressWarnings("serial")
+public class ManagementException extends TuscanyRuntimeException {
+
+ /**
+ * Initializes the root cause.
+ * @param th Root cause.
+ */
+ public ManagementException(Throwable th) {
+ super(th);
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/RmiAgent.java b/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/RmiAgent.java
new file mode 100644
index 0000000000..f6fa58a77c
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/RmiAgent.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.service.management.jmx.agent;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.rmi.RemoteException;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+import java.rmi.server.UnicastRemoteObject;
+
+import javax.management.remote.JMXServiceURL;
+
+/**
+ * Utility for starting the JMX server with an RMI agent.
+ *
+ * @version $Revsion$ $Date$
+ *
+ */
+public class RmiAgent extends AbstractAgent {
+
+ /** Administration port system property. */
+ private static final String ADMIN_PORT_PROPERTY = "tuscany.adminPort";
+
+ /** Default admin port. */
+ private static final int DEFAULT_ADMIN_PORT = 1099;
+
+ /** Instance */
+ private static final Agent INSTANCE = new RmiAgent();
+
+ /** RMI registry. */
+ private Registry registry;
+
+ /** Listen port */
+ private int port = DEFAULT_ADMIN_PORT;
+
+ /**
+ * Gets the adaptor URL.
+ * @return Adaptor URL used by the agent.
+ * @throws ManagementException If unable to start the agent.
+ */
+ protected JMXServiceURL getAdaptorUrl() throws ManagementException {
+
+ try {
+
+ String portValue = System.getProperty(ADMIN_PORT_PROPERTY);
+ if(portValue != null) {
+ port = Integer.parseInt(portValue);
+ }
+
+ // service:jmx:rmi:///jndi/rmi://localhost:1099/server
+ return new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + port + "/server");
+
+
+ } catch (MalformedURLException ex) {
+ throw new ManagementException(ex);
+ }
+
+ }
+
+ /**
+ * Returns the singleton agent instance.
+ * @return Agent instance.
+ * @throws ManagementException If unable to start the agent.
+ */
+ public static Agent getInstance() throws ManagementException {
+ return INSTANCE;
+ }
+
+ /**
+ * @see org.apache.tuscany.service.management.jmx.agent.AbstractAgent#preStart()
+ */
+ @Override
+ public void preStart() throws ManagementException {
+
+ try {
+
+ String portValue = System.getProperty(ADMIN_PORT_PROPERTY);
+ if(portValue != null) {
+ port = Integer.parseInt(portValue);
+ }
+
+ registry = LocateRegistry.createRegistry(port);
+ } catch (RemoteException ex) {
+ throw new ManagementException(ex);
+ }
+
+ }
+
+ /**
+ * @see org.apache.tuscany.service.management.jmx.agent.AbstractAgent#postStop()
+ */
+ @Override
+ public void postStop() throws ManagementException {
+
+ try {
+ UnicastRemoteObject.unexportObject(registry, true);
+ } catch (IOException ex) {
+ throw new ManagementException(ex);
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/AnnotationDrivenDynamicMBean.java b/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/AnnotationDrivenDynamicMBean.java
new file mode 100644
index 0000000000..3d16ff6a2a
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/AnnotationDrivenDynamicMBean.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.service.management.jmx.instrument;
+
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.DynamicMBean;
+import javax.management.InvalidAttributeValueException;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.ReflectionException;
+
+/**
+ * Dynamic MBean based on management annotations.
+ *
+ * @version $Revision$ $Date$
+ */
+public class AnnotationDrivenDynamicMBean implements DynamicMBean {
+
+ /**
+ * @see javax.management.DynamicMBean#getAttribute(java.lang.String)
+ */
+ public Object getAttribute(String attribute)
+ throws AttributeNotFoundException, MBeanException, ReflectionException {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @see javax.management.DynamicMBean#getAttributes(java.lang.String[])
+ */
+ public AttributeList getAttributes(String[] attributes) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @see javax.management.DynamicMBean#getMBeanInfo()
+ */
+ public MBeanInfo getMBeanInfo() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @see javax.management.DynamicMBean#invoke(java.lang.String,java.lang.Object[],java.lang.String[])
+ */
+ public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException,
+ ReflectionException {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @see javax.management.DynamicMBean#setAttribute(javax.management.Attribute)
+ */
+ public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException,
+ MBeanException, ReflectionException {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @see javax.management.DynamicMBean#setAttributes(javax.management.AttributeList)
+ */
+ public AttributeList setAttributes(AttributeList attributes) {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/InstrumentationException.java b/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/InstrumentationException.java
new file mode 100644
index 0000000000..a8ad1666d5
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/InstrumentationException.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.service.management.jmx.instrument;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * Excpetion thrown when there is an instrumentation error.
+ *
+ * @version $Revison$ $Date$
+ *
+ */
+@SuppressWarnings("serial")
+public class InstrumentationException extends TuscanyRuntimeException {
+
+ /**
+ * Initializes the root cause.
+ * @param cause Initializes the root cause.
+ */
+ public InstrumentationException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Initializes the message.
+ * @param message Initializes the message.
+ */
+ public InstrumentationException(String message) {
+ super(message);
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/InstrumentedComponent.java b/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/InstrumentedComponent.java
new file mode 100644
index 0000000000..9e0f06ec13
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/InstrumentedComponent.java
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.service.management.jmx.instrument;
+
+import java.util.Map;
+import java.net.URI;
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.DynamicMBean;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanConstructorInfo;
+import javax.management.MBeanInfo;
+import javax.management.MBeanNotificationInfo;
+import javax.management.MBeanOperationInfo;
+
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.model.PropertyValue;
+
+/**
+ * This is Ruscany component exposed as a dynamic MBean. Currently it only supports a read-only vew of all the
+ * properties on the component.
+ *
+ * @version $Revision$ $Date$
+ */
+public class InstrumentedComponent implements DynamicMBean {
+
+ /**
+ * Properties available on the component.
+ */
+ private final Map<String, PropertyValue<?>> properties;
+
+ /**
+ * Name of the component.
+ */
+ private URI componentId;
+
+ /**
+ * Initializes the property values.
+ *
+ * @param component Component that is being managed.
+ */
+ @SuppressWarnings("unchecked")
+ public InstrumentedComponent(final Component component) {
+ this.properties = component.getDefaultPropertyValues();
+ this.componentId = component.getUri();
+ }
+
+ /**
+ * @see javax.management.DynamicMBean#getAttribute(java.lang.String)
+ */
+ public final Object getAttribute(final String attribute) throws AttributeNotFoundException {
+ PropertyValue<?> propertyValue = properties.get(attribute);
+ if (propertyValue != null) {
+ return propertyValue.getValueFactory().getInstance();
+ }
+ throw new AttributeNotFoundException(attribute + " not found.");
+ }
+
+ /**
+ * @see javax.management.DynamicMBean#getAttributes(java.lang.String[])
+ */
+ public final AttributeList getAttributes(final String[] attributes) {
+
+ AttributeList list = new AttributeList();
+ for (String attribute : attributes) {
+ try {
+ list.add(new Attribute(attribute, getAttribute(attribute)));
+ } catch (AttributeNotFoundException ex) {
+ throw new InstrumentationException(ex);
+ }
+ }
+ return list;
+
+ }
+
+ /**
+ * @see javax.management.DynamicMBean#getMBeanInfo()
+ */
+ public final MBeanInfo getMBeanInfo() {
+
+ final MBeanConstructorInfo[] constructors = null;
+ final MBeanOperationInfo[] operations = null;
+ final MBeanNotificationInfo[] notifications = null;
+
+ int size = properties != null ? properties.size() : 0;
+ final MBeanAttributeInfo[] attributes = new MBeanAttributeInfo[size];
+
+ if(properties != null) {
+ int i = 0;
+ for (PropertyValue<?> propertyValue : properties.values()) {
+ attributes[i++] =
+ new MBeanAttributeInfo(propertyValue.getName(), String.class.getName(), null, true, false, false);
+ }
+ }
+
+ return new MBeanInfo(componentId.toString(), null, attributes, constructors, operations, notifications);
+
+ }
+
+ /**
+ * @see javax.management.DynamicMBean#invoke(java.lang.String,java.lang.Object[],java.lang.String[])
+ */
+ public final Object invoke(final String actionName, final Object[] params, final String[] signature) {
+ throw new UnsupportedOperationException("Managed ops not supported");
+ }
+
+ /**
+ * @see javax.management.DynamicMBean#setAttribute(javax.management.Attribute)
+ */
+ public final void setAttribute(final Attribute attribute) {
+ throw new UnsupportedOperationException("Mutable props not supported");
+ }
+
+ /**
+ * @see javax.management.DynamicMBean#setAttributes(javax.management.AttributeList)
+ */
+ public final AttributeList setAttributes(final AttributeList attributes) {
+ throw new UnsupportedOperationException("Mutable props not supported");
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/ReflectedDynamicMBean.java b/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/ReflectedDynamicMBean.java
new file mode 100644
index 0000000000..b07787208c
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/ReflectedDynamicMBean.java
@@ -0,0 +1,353 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.service.management.jmx.instrument;
+
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.MethodDescriptor;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.DynamicMBean;
+import javax.management.InvalidAttributeValueException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.ReflectionException;
+
+/**
+ * Uses JMX dynamic MBean to expose management information of a delegate instance using reflection. Currently
+ * constructor and notification metadata are not supported. Any attribute or operation that needs to be excluded from
+ * the management information can be specified optionally in the factory method.
+ * <p/>
+ * All the methods and properties on <code>java.lang.Object</code> are excluded by default. Also only public and
+ * non-static members are made available for management.
+ * <p/>
+ * TODO Find a homw other than server.start for this class. TODO Tidy up, unit tests
+ *
+ * @version $Revsion$ $Date$
+ */
+public class ReflectedDynamicMBean implements DynamicMBean {
+
+ /**
+ * Excluded methods.
+ */
+ private static final List<String> DEFAULT_EXCLUDED_METHODS =
+ Arrays.asList(new String[]{"wait", "toString", "hashCode", "notify", "equals", "notifyAll", "getClass"});
+
+ /**
+ * Excluded properties.
+ */
+ private static final List<String> DEFAULT_EXCLUDED_PROPERTIES = Arrays.asList(new String[]{"class"});
+
+ /**
+ * Proxied object that is managed.
+ */
+ private Object delegate;
+
+ /**
+ * Runtime type of the managed object.
+ */
+ private Class delegateClass;
+
+ /**
+ * Delegate class name.
+ */
+ private String delegateClassName;
+
+ /**
+ * Cache of property write methods.
+ */
+ private Map<String, Method> propertyWriteMethods = new HashMap<String, Method>();
+
+ /**
+ * Cache of property read methods.
+ */
+ private Map<String, Method> propertyReadMethods = new HashMap<String, Method>();
+
+ /**
+ * Managed operation cache.
+ */
+ private Map<String, Method> methods = new HashMap<String, Method>();
+
+ /**
+ * Property descriptor cache.
+ */
+ private Map<String, PropertyDescriptor> properties = new HashMap<String, PropertyDescriptor>();
+
+ /**
+ * Excluded methods.
+ */
+ private final List<String> excludedMethods = new ArrayList<String>();
+
+ /**
+ * Excluded properties.
+ */
+ private final List<String> excludedProperties = new ArrayList<String>();
+
+ /**
+ * Introspects the bean and populate meta information.
+ *
+ * @param delegate Proxied managed instance.
+ */
+ private ReflectedDynamicMBean(Object delegate) {
+ this(delegate, new ArrayList<String>(), new ArrayList<String>());
+ }
+
+ /**
+ * Introspects the bean and populate meta information.
+ *
+ * @param delegate Proxied managed instance.
+ * @param excludedMethods Operations excluded from managed view.
+ * @param excludedProperties Properties excluded from managed view.
+ */
+ private ReflectedDynamicMBean(Object delegate, List<String> excludedMethods, List<String> excludedProperties) {
+
+ this.delegate = delegate;
+ this.delegateClass = delegate.getClass();
+ this.delegateClassName = delegateClass.getName();
+
+ this.excludedMethods.addAll(excludedMethods);
+ this.excludedMethods.addAll(DEFAULT_EXCLUDED_METHODS);
+ this.excludedProperties.addAll(excludedProperties);
+ this.excludedProperties.addAll(DEFAULT_EXCLUDED_PROPERTIES);
+
+ BeanInfo beanInfo;
+ try {
+ beanInfo = Introspector.getBeanInfo(delegateClass);
+ } catch (IntrospectionException ex) {
+ throw new InstrumentationException(ex);
+ }
+
+ cacheProperties(beanInfo);
+
+ cacheMethods(beanInfo);
+ }
+
+ /**
+ * Factory method for creating the management view.
+ *
+ * @param delegate Proxied managed instance.
+ * @param excludedMethods Operations excluded from managed view.
+ * @param excludedProperties Properties excluded from managed view.
+ * @return Proxy for the managed instance.
+ */
+ public static ReflectedDynamicMBean newInstance(Object delegate, List<String> excludedMethods,
+ List<String> excludedProperties) {
+ return new ReflectedDynamicMBean(delegate, excludedMethods, excludedProperties);
+ }
+
+ /**
+ * Factory method for creating the management view.
+ *
+ * @param delegate Proxied managed instance.
+ * @return Proxy for the managed instance.
+ */
+ public static ReflectedDynamicMBean newInstance(Object delegate) {
+ return new ReflectedDynamicMBean(delegate);
+ }
+
+ /**
+ * @see javax.management.DynamicMBean#getAttribute(java.lang.String)
+ */
+ public Object getAttribute(String attribute)
+ throws AttributeNotFoundException, MBeanException, ReflectionException {
+
+ Method readMethod = propertyReadMethods.get(attribute);
+ if (readMethod == null) {
+ throw new AttributeNotFoundException(attribute + " not found");
+ }
+ try {
+ return readMethod.invoke(delegate);
+ } catch (IllegalAccessException ex) {
+ throw new ReflectionException(ex);
+ } catch (InvocationTargetException ex) {
+ throw new ReflectionException(ex);
+ }
+
+ }
+
+ /**
+ * @see javax.management.DynamicMBean#getAttributes(java.lang.String[])
+ */
+ public AttributeList getAttributes(String[] attributes) {
+
+ AttributeList list = new AttributeList();
+ for (String attribute : attributes) {
+ try {
+ list.add(new Attribute(attribute, getAttribute(attribute)));
+ } catch (AttributeNotFoundException ex) {
+ throw new InstrumentationException(ex);
+ } catch (MBeanException ex) {
+ throw new InstrumentationException(ex);
+ } catch (ReflectionException ex) {
+ throw new InstrumentationException(ex);
+ }
+ }
+ return list;
+
+ }
+
+ /**
+ * @see javax.management.DynamicMBean#getMBeanInfo()
+ */
+ public MBeanInfo getMBeanInfo() {
+
+ try {
+
+ MBeanAttributeInfo[] attrs = new MBeanAttributeInfo[properties.keySet().size()];
+ int count = 0;
+ for (String property : properties.keySet()) {
+ Method readMethod = propertyReadMethods.get(property);
+ Method writeMethod = propertyWriteMethods.get(property);
+ attrs[count++] = new MBeanAttributeInfo(property, "", readMethod, writeMethod);
+ }
+
+ MBeanOperationInfo[] ops = new MBeanOperationInfo[methods.keySet().size()];
+ count = 0;
+ for (Method method : methods.values()) {
+ ops[count++] = new MBeanOperationInfo("", method);
+ }
+
+ MBeanInfo mBeanInfo = new MBeanInfo(delegateClassName, "", attrs, null, ops, null);
+ return mBeanInfo;
+
+ } catch (javax.management.IntrospectionException ex) {
+ throw new InstrumentationException(ex);
+ }
+
+ }
+
+ /**
+ * @see javax.management.DynamicMBean#invoke(java.lang.String,java.lang.Object[],java.lang.String[])
+ */
+ public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException,
+ ReflectionException {
+
+ Method method = methods.get(actionName);
+ if (method == null) {
+ throw new InstrumentationException("Operation not found: " + actionName);
+ }
+ try {
+ return method.invoke(delegate, params);
+ } catch (IllegalAccessException ex) {
+ throw new ReflectionException(ex);
+ } catch (InvocationTargetException ex) {
+ throw new ReflectionException(ex);
+ }
+
+ }
+
+ /**
+ * @see javax.management.DynamicMBean#setAttribute(javax.management.Attribute)
+ */
+ public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException,
+ MBeanException, ReflectionException {
+
+ Method writeMethod = propertyWriteMethods.get(attribute.getName());
+ if (writeMethod == null) {
+ throw new AttributeNotFoundException(attribute + " not found");
+ }
+ try {
+ writeMethod.invoke(delegate, attribute.getValue());
+ } catch (IllegalAccessException ex) {
+ throw new ReflectionException(ex);
+ } catch (InvocationTargetException ex) {
+ throw new ReflectionException(ex);
+ }
+
+ }
+
+ /**
+ * @see javax.management.DynamicMBean#setAttributes(javax.management.AttributeList)
+ */
+ public AttributeList setAttributes(AttributeList attributes) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Caches managed operations.
+ *
+ * @param beanInfo Bean info for the managed instance.
+ */
+ private void cacheMethods(BeanInfo beanInfo) {
+
+ for (MethodDescriptor methodDescriptor : beanInfo.getMethodDescriptors()) {
+
+ Method method = methodDescriptor.getMethod();
+ String name = method.getName();
+
+ if (excludedMethods.contains(name)) {
+ continue;
+ }
+ int modifiers = method.getModifiers();
+ if (!Modifier.isPublic(modifiers) || Modifier.isStatic(modifiers)) {
+ continue;
+ }
+ if (propertyReadMethods.values().contains(method) || propertyWriteMethods.values().contains(method)) {
+ continue;
+ }
+
+ // TODO Add support for overloaded methods
+ methods.put(name, method);
+
+ }
+
+ }
+
+ /**
+ * Caches managed properties.
+ *
+ * @param beanInfo Bean info for the managed instance.
+ */
+ private void cacheProperties(BeanInfo beanInfo) {
+ for (PropertyDescriptor propertyDescriptor : beanInfo.getPropertyDescriptors()) {
+
+ String name = propertyDescriptor.getName();
+
+ if (excludedProperties.contains(name)) {
+ continue;
+ }
+ properties.put(name, propertyDescriptor);
+
+ Method readMethod = propertyDescriptor.getReadMethod();
+ if (readMethod != null && Modifier.isPublic(readMethod.getModifiers())) {
+ propertyReadMethods.put(name, readMethod);
+ }
+
+ Method writeMethod = propertyDescriptor.getWriteMethod();
+ if (writeMethod != null && Modifier.isPublic(writeMethod.getModifiers())) {
+ propertyWriteMethods.put(name, writeMethod);
+ }
+
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/services/management/pom.xml b/tags/java/tsss-demo/runtime/services/management/pom.xml
new file mode 100644
index 0000000000..cb360e5b55
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/management/pom.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca.runtime</groupId>
+ <artifactId>services</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.runtime.services</groupId>
+ <artifactId>management</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache Tuscany SCA Management Services</name>
+
+ <modules>
+ <module>jmx</module>
+ </modules>
+</project>
diff --git a/tags/java/tsss-demo/runtime/services/maven/LICENSE.txt b/tags/java/tsss-demo/runtime/services/maven/LICENSE.txt
new file mode 100644
index 0000000000..75b52484ea
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/maven/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/runtime/services/maven/NOTICE.txt b/tags/java/tsss-demo/runtime/services/maven/NOTICE.txt
new file mode 100644
index 0000000000..ecc68a9614
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/maven/NOTICE.txt
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/runtime/services/maven/pom.xml b/tags/java/tsss-demo/runtime/services/maven/pom.xml
new file mode 100644
index 0000000000..99f0575d61
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/maven/pom.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca.runtime</groupId>
+ <artifactId>services</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.runtime.services</groupId>
+ <artifactId>maven</artifactId>
+ <name>Apache Tuscany Maven Service</name>
+ <description>Tuscany Maven Service</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-spi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-embedder</artifactId>
+ <version>2.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/tags/java/tsss-demo/runtime/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenArtifactRepository.java b/tags/java/tsss-demo/runtime/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenArtifactRepository.java
new file mode 100644
index 0000000000..517565b17b
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenArtifactRepository.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.services.maven;
+
+import java.util.Collection;
+
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.services.artifact.Artifact;
+import org.apache.tuscany.spi.services.artifact.ArtifactRepository;
+
+import org.apache.tuscany.host.RuntimeInfo;
+
+/**
+ * Artifact repository used for resolving artifacts.
+ * <p/>
+ * This is used by the composite loader for resolving artifacts transitively. The repository uses the Maven API for
+ * resolving dependencies and hence expects the artifacts to be stored in a structure similar to the Maven repository
+ * layout. The repository first looks within the deployed unit (WAR for example), before resorting to a local and set of
+ * remote Maven repositories.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MavenArtifactRepository implements ArtifactRepository {
+
+ /**
+ * Maven helper
+ */
+ private MavenHelper mavenHelper;
+
+ /**
+ * WAR repository helper
+ */
+ private WarRepositoryHelper warRepositoryHelper;
+
+ /**
+ * Conctructs a new artifact repository.
+ */
+ public MavenArtifactRepository(@Property(name = "remoteRepoUrl")
+ String remoteRepoUrl, @Reference
+ RuntimeInfo runtimeInfo) {
+ mavenHelper = new MavenHelper(remoteRepoUrl, runtimeInfo.isOnline());
+ warRepositoryHelper = new WarRepositoryHelper(runtimeInfo.getBaseURL());
+ mavenHelper.start();
+ }
+
+ /**
+ * Resolve an artifact. This ensures that the information associated with an artifact is fully populated;
+ * Specifically, after this operation the URL should contain a location where the artifact can be obtained.
+ *
+ * @param rootArtifact the artifact to be resolved
+ */
+ public void resolve(Artifact rootArtifact) {
+ if (warRepositoryHelper.resolveTransitively(rootArtifact)) {
+ return;
+ }
+ if (mavenHelper.resolveTransitively(rootArtifact)) {
+ return;
+ }
+ throw new TuscanyDependencyException("Unable to resolve artifact", rootArtifact.toString());
+ }
+
+ /**
+ * Resolve a collection of Artifacts.
+ *
+ * @param artifacts a collection of artifacts to be resolved
+ * @see #resolve(Artifact)
+ */
+ public void resolve(Collection<? extends Artifact> artifacts) {
+ for (Artifact artifact : artifacts) {
+ resolve(artifact);
+ }
+ }
+
+ /**
+ * Destroy method.
+ */
+ @Destroy
+ public void destroy() {
+ mavenHelper.stop();
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenHelper.java b/tags/java/tsss-demo/runtime/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenHelper.java
new file mode 100644
index 0000000000..f82756afbd
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenHelper.java
@@ -0,0 +1,296 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.services.maven;
+
+import java.io.File;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.metadata.ResolutionGroup;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.settings.MavenSettingsBuilder;
+import org.apache.maven.settings.Settings;
+import org.apache.tuscany.spi.services.artifact.Artifact;
+import org.codehaus.classworlds.ClassWorld;
+import org.codehaus.classworlds.DefaultClassRealm;
+import org.codehaus.classworlds.DuplicateRealmException;
+import org.codehaus.plexus.PlexusContainerException;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.embed.Embedder;
+
+/**
+ * Utility class for embedding Maven.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MavenHelper {
+
+ /** Local repository */
+// private static final File LOCAL_REPO = new File(System.getProperty("user.home") + File.separator + ".m2" + File.separator + "repository");
+
+ /** Remote repository URLs */
+ private final String[] remoteRepositoryUrls;
+
+ /** Maven metadata source */
+ private ArtifactMetadataSource metadataSource;
+
+ /** Artifact factory */
+ private ArtifactFactory artifactFactory;
+
+ /** Local artifact repository */
+ private ArtifactRepository localRepository;
+
+ /** Remote artifact repositories */
+ private List<ArtifactRepository> remoteRepositories = new LinkedList<ArtifactRepository>();
+
+ /** Artifact resolver */
+ private ArtifactResolver artifactResolver;
+
+ /** Online */
+ private boolean online;
+
+ /**
+ * Initialize the remote repository URLs.
+ *
+ * @param remoteRepositoryUrls
+ * Remote repository URLS.
+ * @param runtimeInfo
+ * Runtime information.
+ */
+ public MavenHelper(String remoteRepositoryUrl, boolean online) {
+ this.remoteRepositoryUrls = remoteRepositoryUrl.split(",");
+ this.online = online;
+ }
+
+ /**
+ * Starts the embedder.
+ *
+ * @throws TuscanyDependencyException
+ * If unable to start the embedder.
+ */
+ public void start() throws TuscanyDependencyException {
+
+ try {
+
+ Embedder embedder = new Embedder();
+ ClassWorld classWorld = new ClassWorld();
+
+ classWorld.newRealm("plexus.core", getClass().getClassLoader());
+
+ // Evil hack for Tomcat classloader issue - starts
+ Field realmsField = ClassWorld.class.getDeclaredField("realms");
+ realmsField.setAccessible(true);
+ Map realms = (Map) realmsField.get(classWorld);
+ DefaultClassRealm realm = (DefaultClassRealm) realms.get("plexus.core");
+
+ Class clazz = Class.forName("org.codehaus.classworlds.RealmClassLoader");
+ Constructor ctr = clazz.getDeclaredConstructor(new Class[] { DefaultClassRealm.class, ClassLoader.class });
+ ctr.setAccessible(true);
+ Object realmClassLoader = ctr.newInstance(realm, getClass().getClassLoader());
+
+ Field realmClassLoaderField = DefaultClassRealm.class.getDeclaredField("classLoader");
+ realmClassLoaderField.setAccessible(true);
+ realmClassLoaderField.set(realm, realmClassLoader);
+ // Evil hack for Tomcat classloader issue - ends
+
+ embedder.start(classWorld);
+
+ metadataSource = (ArtifactMetadataSource) embedder.lookup(ArtifactMetadataSource.ROLE);
+ artifactFactory = (ArtifactFactory) embedder.lookup(ArtifactFactory.ROLE);
+ artifactResolver = (ArtifactResolver) embedder.lookup(ArtifactResolver.ROLE);
+
+ setUpRepositories(embedder);
+
+ embedder.stop();
+
+ } catch (DuplicateRealmException ex) {
+ throw new TuscanyDependencyException(ex);
+ } catch (PlexusContainerException ex) {
+ throw new TuscanyDependencyException(ex);
+ } catch (ComponentLookupException ex) {
+ throw new TuscanyDependencyException(ex);
+ } catch (NoSuchFieldException ex) {
+ throw new TuscanyDependencyException(ex);
+ } catch (IllegalAccessException ex) {
+ throw new TuscanyDependencyException(ex);
+ } catch (ClassNotFoundException ex) {
+ throw new TuscanyDependencyException(ex);
+ } catch (NoSuchMethodException ex) {
+ throw new TuscanyDependencyException(ex);
+ } catch (InstantiationException ex) {
+ throw new TuscanyDependencyException(ex);
+ } catch (InvocationTargetException ex) {
+ throw new TuscanyDependencyException(ex);
+ }
+
+ }
+
+ /**
+ * Stops the embedder.
+ *
+ * @throws TuscanyDependencyException
+ * If unable to stop the embedder.
+ */
+ public void stop() throws TuscanyDependencyException {
+ }
+
+ /**
+ * Resolves the dependencies transitively.
+ *
+ * @param artifact
+ * Artifact whose dependencies need to be resolved.
+ * @throws TuscanyDependencyException
+ * If unable to resolve the dependencies.
+ */
+ public boolean resolveTransitively(Artifact rootArtifact) throws TuscanyDependencyException {
+
+ org.apache.maven.artifact.Artifact mavenRootArtifact = artifactFactory.createArtifact(rootArtifact.getGroup(), rootArtifact.getName(),
+ rootArtifact.getVersion(), org.apache.maven.artifact.Artifact.SCOPE_RUNTIME, rootArtifact.getType());
+
+ try {
+
+ if (resolve(mavenRootArtifact)) {
+ rootArtifact.setUrl(mavenRootArtifact.getFile().toURL());
+ if (resolveDependencies(rootArtifact, mavenRootArtifact)) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ } catch (MalformedURLException ex) {
+ throw new TuscanyDependencyException(ex);
+ }
+
+ }
+
+ /*
+ * Resolves the artifact.
+ */
+ private boolean resolve(org.apache.maven.artifact.Artifact mavenRootArtifact) {
+
+ try {
+ artifactResolver.resolve(mavenRootArtifact, remoteRepositories, localRepository);
+ return true;
+ } catch (ArtifactResolutionException ex) {
+ return false;
+ } catch (ArtifactNotFoundException ex) {
+ return false;
+ }
+
+ }
+
+ /*
+ * Sets up local and remote repositories.
+ */
+ private void setUpRepositories(Embedder embedder) {
+
+ try {
+
+ ArtifactRepositoryFactory artifactRepositoryFactory = (ArtifactRepositoryFactory) embedder.lookup(ArtifactRepositoryFactory.ROLE);
+
+ ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) embedder.lookup(ArtifactRepositoryLayout.ROLE, "default");
+
+ String updatePolicy = online ? ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS : ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER;
+ ArtifactRepositoryPolicy snapshotsPolicy = new ArtifactRepositoryPolicy(true, updatePolicy, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
+ ArtifactRepositoryPolicy releasesPolicy = new ArtifactRepositoryPolicy(true, updatePolicy, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
+
+ MavenSettingsBuilder settingsBuilder = (MavenSettingsBuilder)embedder.lookup(MavenSettingsBuilder.ROLE);
+ Settings settings = settingsBuilder.buildSettings();
+ String localRepo = settings.getLocalRepository();
+
+ localRepository = artifactRepositoryFactory.createArtifactRepository("local", new File(localRepo).toURL().toString(), layout,
+ snapshotsPolicy, releasesPolicy);
+
+ if (!online) {
+ return;
+ }
+
+ for (String remoteRepositoryUrl : remoteRepositoryUrls) {
+ String repoid = remoteRepositoryUrl.replace(':', '_');
+ repoid = repoid.replace('/', '_');
+ repoid = repoid.replace('\\', '_');
+ remoteRepositories.add(artifactRepositoryFactory.createArtifactRepository(repoid, remoteRepositoryUrl, layout, snapshotsPolicy,
+ releasesPolicy));
+ }
+
+ } catch (Exception ex) {
+ throw new TuscanyDependencyException(ex);
+ }
+
+ }
+
+ /*
+ * Resolves transitive dependencies.
+ */
+ private boolean resolveDependencies(Artifact rootArtifact, org.apache.maven.artifact.Artifact mavenRootArtifact) {
+
+ try {
+
+ ResolutionGroup resolutionGroup = null;
+ ArtifactResolutionResult result = null;
+
+ resolutionGroup = metadataSource.retrieve(mavenRootArtifact, localRepository, remoteRepositories);
+ result = artifactResolver.resolveTransitively(resolutionGroup.getArtifacts(), mavenRootArtifact, remoteRepositories, localRepository,
+ metadataSource);
+
+ // Add the artifacts to the deployment unit
+ for (Object obj : result.getArtifacts()) {
+ org.apache.maven.artifact.Artifact depArtifact = (org.apache.maven.artifact.Artifact) obj;
+ Artifact artifact = new Artifact();
+ artifact.setName(depArtifact.getArtifactId());
+ artifact.setGroup(depArtifact.getGroupId());
+ artifact.setType(depArtifact.getType());
+ artifact.setVersion(depArtifact.getVersion());
+ artifact.setClassifier(depArtifact.getClassifier());
+ artifact.setUrl(depArtifact.getFile().toURL());
+ rootArtifact.addDependency(artifact);
+ }
+
+ } catch (ArtifactMetadataRetrievalException ex) {
+ return false;
+ } catch (MalformedURLException ex) {
+ throw new TuscanyDependencyException(ex);
+ } catch (ArtifactResolutionException ex) {
+ return false;
+ } catch (ArtifactNotFoundException ex) {
+ return false;
+ }
+
+ return true;
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/services/maven/src/main/java/org/apache/tuscany/services/maven/TuscanyDependencyException.java b/tags/java/tsss-demo/runtime/services/maven/src/main/java/org/apache/tuscany/services/maven/TuscanyDependencyException.java
new file mode 100644
index 0000000000..a7817ff3be
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/maven/src/main/java/org/apache/tuscany/services/maven/TuscanyDependencyException.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.services.maven;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * Exception thrown in case of an artifact error.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TuscanyDependencyException extends TuscanyRuntimeException {
+
+ /**
+ * Initializes the cause.
+ *
+ * @param cause Cause of the exception.
+ */
+ public TuscanyDependencyException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Initializes the message.
+ *
+ * @param message Message of the exception.
+ */
+ public TuscanyDependencyException(String message) {
+ super(message);
+ }
+
+
+ /**
+ * Initializes the message.
+ *
+ * @param message Message of the exception.
+ * @param identifier an identifier for the exeption.
+ */
+ public TuscanyDependencyException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/services/maven/src/main/java/org/apache/tuscany/services/maven/WarRepositoryHelper.java b/tags/java/tsss-demo/runtime/services/maven/src/main/java/org/apache/tuscany/services/maven/WarRepositoryHelper.java
new file mode 100644
index 0000000000..6b3ba3ed10
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/maven/src/main/java/org/apache/tuscany/services/maven/WarRepositoryHelper.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.services.maven;
+
+import java.beans.XMLDecoder;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tuscany.spi.services.artifact.Artifact;
+import org.codehaus.plexus.util.IOUtil;
+
+/**
+ * Helper class for resolving dependencies from WAR files.
+ *
+ * @author Administrator
+ *
+ */
+public class WarRepositoryHelper {
+
+ /** WAR Repository URL */
+ private URL reporsitoryUrl;
+
+ /** Dependency metadata */
+ private Map<String, Set<String>> transDependencyMap = new HashMap<String, Set<String>>();
+
+ /**
+ * Initializes the repository URL.
+ * @param baseUrl Base URL.
+ */
+ @SuppressWarnings("unchecked")
+ public WarRepositoryHelper(URL baseUrl) {
+
+
+ InputStream transDepMapInputStream = null;
+ try {
+
+ reporsitoryUrl = new URL(baseUrl, "repository/");
+ URL transDependencyMapUrl = new URL(baseUrl, "repository/dependency.metadata");
+ transDepMapInputStream = transDependencyMapUrl.openStream();
+
+ XMLDecoder decoder = new XMLDecoder(transDepMapInputStream);
+ transDependencyMap = (Map<String, Set<String>>)decoder.readObject();
+ decoder.close();
+
+ } catch (MalformedURLException ex) {
+ // throw new TuscanyDependencyException(ex);
+ } catch (IOException ex) {
+ // throw new TuscanyDependencyException(ex);
+ } finally {
+ IOUtil.close(transDepMapInputStream);
+ }
+
+ }
+
+ /**
+ * Resolves the dependencies transitively.
+ *
+ * @param artifact
+ * Artifact whose dependencies need to be resolved.
+ * @throws TuscanyDependencyException
+ * If unable to resolve the dependencies.
+ */
+ public boolean resolveTransitively(Artifact rootArtifact) throws TuscanyDependencyException {
+
+ String artKey = rootArtifact.getGroup() + "/" + rootArtifact.getName() + "/" + rootArtifact.getVersion() + "/";
+ if(!transDependencyMap.containsKey(artKey)) {
+ return false;
+ }
+
+
+ for(String dep : transDependencyMap.get(artKey)) {
+
+ String[] tokens = dep.split("/");
+ String artName = tokens[1];
+
+ try {
+ if(artName.equals(rootArtifact.getName())) {
+ rootArtifact.setUrl(new URL(reporsitoryUrl, dep));
+ } else {
+ Artifact depArtifact = new Artifact();
+ depArtifact.setGroup(tokens[0]);
+ depArtifact.setName(tokens[1]);
+ depArtifact.setVersion(tokens[2]);
+ depArtifact.setUrl(new URL(reporsitoryUrl, dep));
+ rootArtifact.addDependency(depArtifact);
+
+ }
+ } catch (MalformedURLException ex) {
+ throw new TuscanyDependencyException(ex);
+ }
+ }
+ return rootArtifact.getUrl()!=null;
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/services/maven/src/test/java/org/apache/tuscany/services/maven/MavenArtifactRepositoryTestCase.java b/tags/java/tsss-demo/runtime/services/maven/src/test/java/org/apache/tuscany/services/maven/MavenArtifactRepositoryTestCase.java
new file mode 100644
index 0000000000..b4e9babd05
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/maven/src/test/java/org/apache/tuscany/services/maven/MavenArtifactRepositoryTestCase.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.services.maven;
+
+import java.io.File;
+import java.net.URL;
+import java.net.URI;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.host.RuntimeInfo;
+import org.apache.tuscany.spi.services.artifact.Artifact;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MavenArtifactRepositoryTestCase extends TestCase {
+
+ public MavenArtifactRepositoryTestCase(String arg0) {
+ super(arg0);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /*
+ * Test method for 'org.apache.tuscany.serviceBindings.maven.MavenArtifactRepository.resolve(Artifact)'
+ */
+ public void testResolveArtifact() throws Exception {
+
+ final URL BASE_URL = new File(System.getProperty("user.home") + File.separator + ".m2").toURL();
+ String remoteRepoUrl = "http://repo1.maven.org/maven2/";
+ MavenArtifactRepository repository = new MavenArtifactRepository(remoteRepoUrl, new RuntimeInfo() {
+ public File getApplicationRootDirectory() {
+ return null;
+ }
+
+ public URL getBaseURL() {
+ return BASE_URL;
+ }
+
+ public File getInstallDirectory() {
+ return null;
+ }
+
+ public boolean isOnline() {
+ return false;
+ }
+
+ public URI getDomain() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getRuntimeId() {
+ throw new UnsupportedOperationException();
+ }
+ });
+ Artifact artifact = new Artifact();
+ artifact.setGroup("junit");
+ artifact.setName("junit");
+ artifact.setVersion("3.8.1");
+ artifact.setType("jar");
+
+ repository.resolve(artifact);
+
+ Set<URL> urls = artifact.getUrls();
+
+ System.err.println(urls);
+
+ assertEquals(1, urls.size());
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/services/maven/src/test/java/org/apache/tuscany/services/maven/WarRepositoryHelperTestCase.java b/tags/java/tsss-demo/runtime/services/maven/src/test/java/org/apache/tuscany/services/maven/WarRepositoryHelperTestCase.java
new file mode 100644
index 0000000000..3a79599fa7
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/maven/src/test/java/org/apache/tuscany/services/maven/WarRepositoryHelperTestCase.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.services.maven;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import org.apache.tuscany.spi.services.artifact.Artifact;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Administrator
+ *
+ */
+public class WarRepositoryHelperTestCase extends TestCase {
+
+ /**
+ * @param arg0
+ */
+ public WarRepositoryHelperTestCase(String arg0) {
+ super(arg0);
+ }
+
+ /**
+ * Test method for {@link org.apache.tuscany.services.maven.WarRepositoryHelper#WarRepositoryHelper(java.net.URL)}.
+ */
+ public void testWarRepositoryHelper() {
+
+ URL warUrl = getClass().getClassLoader().getResource("webapp.war");
+ URLClassLoader urlc = new URLClassLoader(new URL[] {warUrl});
+
+ URL repoUrl = urlc.getResource("WEB-INF/tuscany/");
+ System.err.println(repoUrl);
+
+ WarRepositoryHelper warRepositoryHelper = new WarRepositoryHelper(repoUrl);
+ assertNotNull(warRepositoryHelper);
+
+ }
+
+ /**
+ * Test method for {@link org.apache.tuscany.services.maven.WarRepositoryHelper#WarRepositoryHelper(java.net.URL)}.
+ */
+ public void testResolveTransitively() {
+
+ URL warUrl = getClass().getClassLoader().getResource("webapp.war");
+ URLClassLoader urlc = new URLClassLoader(new URL[] {warUrl});
+
+ URL repoUrl = urlc.getResource("WEB-INF/tuscany/");
+ WarRepositoryHelper warRepositoryHelper = new WarRepositoryHelper(repoUrl);
+
+ Artifact artifact = new Artifact();
+ artifact.setGroup("commons-httpclient");
+ artifact.setName("commons-httpclient");
+ artifact.setVersion("3.0");
+
+ warRepositoryHelper.resolveTransitively(artifact);
+ assertEquals(4, artifact.getUrls().size());
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/services/maven/src/test/resources/webapp.war b/tags/java/tsss-demo/runtime/services/maven/src/test/resources/webapp.war
new file mode 100644
index 0000000000..4448aca8ff
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/maven/src/test/resources/webapp.war
Binary files differ
diff --git a/tags/java/tsss-demo/runtime/services/pom.xml b/tags/java/tsss-demo/runtime/services/pom.xml
new file mode 100644
index 0000000000..1171068aef
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/services/pom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>runtime</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.runtime</groupId>
+ <artifactId>services</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache Tuscany Runtime Services</name>
+
+ <modules>
+ <module>management</module>
+ <module>maven</module>
+ </modules>
+
+</project>
diff --git a/tags/java/tsss-demo/runtime/standalone/assembly/LICENSE.txt b/tags/java/tsss-demo/runtime/standalone/assembly/LICENSE.txt
new file mode 100644
index 0000000000..0084319535
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/assembly/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, serviceDefinition marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/runtime/standalone/assembly/NOTICE.txt b/tags/java/tsss-demo/runtime/standalone/assembly/NOTICE.txt
new file mode 100644
index 0000000000..b18217bd7a
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/assembly/NOTICE.txt
@@ -0,0 +1,163 @@
+${project.name}
+Copyright (c) 2005 - 2007 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
+----- NOTICE from LICENSE.txt file for classworlds project --------------------
+* profiles/launcher/boot/classworlds-1.1.jar
+-------------------------------------------------------------------------------
+
+/*
+ $Id$
+
+ Copyright 2002 (C) The Codehaus. All Rights Reserved.
+
+ Redistribution and use of this software and associated documentation
+ ("Software"), with or without modification, are permitted provided
+ that the following conditions are met:
+
+ 1. Redistributions of source code must retain copyright
+ statements and notices. Redistributions must also contain a
+ copy of this document.
+
+ 2. Redistributions in binary form must reproduce the
+ above copyright notice, this list of conditions and the
+ following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+ 3. The name "classworlds" must not be used to endorse or promote
+ products derived from this Software without prior written
+ permission of The Codehaus. For written permission, please
+ contact bob@codehaus.org.
+
+ 4. Products derived from this Software may not be called "classworlds"
+ nor may "classworlds" appear in their names without prior written
+ permission of The Codehaus. "classworlds" is a registered
+ trademark of The Codehaus.
+
+ 5. Due credit should be given to The Codehaus.
+ (http://classworlds.codehaus.org/).
+
+ THIS SOFTWARE IS PROVIDED BY THE CODEHAUS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ THE CODEHAUS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ */
+
+
+----- NOTICE from LICENSE.txt file in jsch-0.1.24 distribution ----------------
+* profiles/launcher/boot/jsch-0.1.24.jar
+-------------------------------------------------------------------------------
+
+JSch 0.0.* was released under the GNU LGPL license. Later, we have switched
+over to a BSD-style license.
+
+------------------------------------------------------------------------------
+Copyright (c) 2002,2003,2004,2005 Atsuhiko Yamanaka, JCraft,Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the distribution.
+
+ 3. The names of the authors may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
+INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+----- NOTICE from Codehaus for Plexus Project ---------------------------------
+* profiles/launcher/boot/plexus-container-default-1.0-alpha-9.jar
+* profiles/launcher/boot/plexus-interactivity-api-1.0-alpha-4.jar
+* profiles/launcher/boot/plexus-utils-1.1.jar
+-------------------------------------------------------------------------------
+
+ The MIT License
+
+ Copyright (c) 2004, The Codehaus
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
+ this software and associated documentation files (the "Software"), to deal in
+ the Software without restriction, including without limitation the rights to
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ of the Software, and to permit persons to whom the Software is furnished to do
+ so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+
+-----
+
+Some portions of Plexus are also distributed under other BSD-style licenses
+including the Apache License Version 2.0
+
+----- NOTICE from StAX project at http://svn.codehaus.org/stax/trunk/dev/README-API.txt
+* profiles/launcher/boot/stax-api-1.0.1.jar
+-------------------------------------------------------------------------------
+
+These files together comprise the API for JSR 173 (Streaming API for XML Specification), including its API classes and interfaces.
+
+
+The following lists the files in this distribution:
+
+README-API.txt [README file for JSR 173 api bundle.]
+ASF2.0.txt [Apache Software Foundation License 2.0.]
+jsr173_1.0_api.jar [The API classes and interfaces in binary format.]
+jsr173_1.0_src.jar [The API classes and interfaces in source format.]
+
+Your right to use the listed files, whether together or individually, is governed by the Apache Software Foundation License 2.0 included in this bundle.
+
+Please see the javadoc for information on how to get started.
+
+----- NOTICE from wstx-asl-3.2.0.jar ------------------------------------------
+* profiles/launcher/boot/wstx-asl-3.2.0.jar
+-------------------------------------------------------------------------------
+
+This product currently only contains code developed by authors
+of specific components, as identified by the source code files.
+
+Since product implements StAX API, it has dependencies to StAX API
+classes.
+
+For additional credits (generally to people who reported problems)
+see CREDITS file.
diff --git a/tags/java/tsss-demo/runtime/standalone/assembly/pom.xml b/tags/java/tsss-demo/runtime/standalone/assembly/pom.xml
new file mode 100644
index 0000000000..0e5e3af64d
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/assembly/pom.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca.runtime</groupId>
+ <artifactId>standalone</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.runtime.standalone</groupId>
+ <artifactId>assembly</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache Tuscany SCA Standalone Assembly</name>
+ <description>Module to smoketest the standalone runtime.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.runtime.standalone</groupId>
+ <artifactId>launcher</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.runtime.standalone</groupId>
+ <artifactId>standalone-host</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.2-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <descriptors>
+ <descriptor>standalone.xml</descriptor>
+ </descriptors>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tags/java/tsss-demo/runtime/standalone/assembly/src/main/assembly/README.txt b/tags/java/tsss-demo/runtime/standalone/assembly/src/main/assembly/README.txt
new file mode 100644
index 0000000000..40d0b7242f
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/assembly/src/main/assembly/README.txt
@@ -0,0 +1,18 @@
+Apache Tuscany Standalone Runtime Distribution
+----------------------------------------------
+
+This distribution provides support for running SCA composites in a
+standalone client environment using a client launcher. To launch
+a composite run:
+
+ $ java -jar bin/launcher.jar <yourComposite> [args ...]
+
+The configuration for the runtime environment used by the launcher is
+defined in the profiles/launcher directory.
+
+Detailed documentation on developing applications using SCA and running
+them on Apache Tuscany can be found on the project website at:
+ http://incubator.apache.org/tuscany/
+
+Alternatively questions can be sent to the mailing list at:
+ mailto:tuscany-user@ws.apache.org
diff --git a/tags/java/tsss-demo/runtime/standalone/assembly/src/main/assembly/profiles/admin/system.scdl b/tags/java/tsss-demo/runtime/standalone/assembly/src/main/assembly/profiles/admin/system.scdl
new file mode 100644
index 0000000000..66b3af958c
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/assembly/src/main/assembly/profiles/admin/system.scdl
@@ -0,0 +1,168 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<!--
+ Default system configuration for the launcher environment.
+
+ $Rev$ $Date$
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ name="org.apache.tuscany.launcher.System"
+ autowire="true">
+
+ <!-- Component that provides the Deployer service -->
+ <component name="deployer">
+ <system:implementation.system class="org.apache.tuscany.core.deployer.DeployerImpl"/>
+ </component>
+
+ <!-- Work management -->
+ <component name="workContext">
+ <system:implementation.system class="org.apache.tuscany.core.component.WorkContextImpl"/>
+ </component>
+
+ <!-- Wire service -->
+ <component name="proxyService">
+ <system:implementation.system class="org.apache.tuscany.core.wire.jdk.JDKProxyService"/>
+ </component>
+
+ <!-- Scope infrastructure -->
+ <component name="scopeRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.ScopeRegistryImpl"/>
+ </component>
+
+ <!-- Store infrastructure -->
+ <component name="store">
+ <system:implementation.system class="org.apache.tuscany.core.services.store.memory.MemoryStore"/>
+ </component>
+
+ <!-- Builder and BuilderRegistry -->
+ <component name="builder">
+ <system:implementation.system class="org.apache.tuscany.core.builder.BuilderRegistryImpl"/>
+ </component>
+
+ <!-- Resource host registry -->
+ <component name="resourceHostRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.services.host.DelegatingResourceHostRegistry"/>
+ </component>
+
+ <!-- Loader and LoaderRegistry -->
+ <component name="loader">
+ <system:implementation.system class="org.apache.tuscany.core.loader.LoaderRegistryImpl"/>
+ </component>
+
+ <!-- Introspector and IntrospectionRegistry -->
+ <component name="interfaceProcessorRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.IntrospectionRegistryImpl"/>
+ </component>
+
+ <!-- Connector infrastructure -->
+ <component name="connector">
+ <system:implementation.system class="org.apache.tuscany.core.builder.ConnectorImpl"/>
+ </component>
+
+ <component name="wirePostProcessorRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.builder.WirePostProcessorRegistryImpl"/>
+ </component>
+
+ <!-- Default scopes -->
+ <component name="scope.composite">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.CompositeScopeContainer"/>
+ </component>
+
+ <component name="scope.stateless">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.StatelessScopeContainer"/>
+ </component>
+<!--
+ <component name="scope.request">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.RequestScopeContainer"/>
+ </component>
+-->
+
+<!--
+ <component name="scope.conversational">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.ConversationalScopeContainer"/>
+ </component>
+-->
+
+ <!-- include loader configuration -->
+ <include name="org.apache.tuscany.core.Loader" scdlResource="org/apache/tuscany/core/loader.scdl"/>
+
+ <!-- include databinding configuration -->
+ <include name="org.apache.tuscany.core.DataBinding" scdlResource="org/apache/tuscany/core/databinding.scdl"/>
+
+ <!-- include implementation processor configuration -->
+ <include name="org.apache.tuscany.core.Implementation" scdlResource="org/apache/tuscany/core/implementation.scdl"/>
+
+ <!-- Java interface definition language -->
+ <include name="org.apache.tuscany.core.InterfaceJava" scdlResource="org/apache/tuscany/core/interfaceJava.scdl"/>
+
+ <!-- include omposite implementation type -->
+ <include name="org.apache.tuscany.core.Composite" scdlResource="org/apache/tuscany/core/composite.scdl"/>
+
+ <!-- System implementation type -->
+ <include name="org.apache.tuscany.core.SystemImplementation" scdlResource="org/apache/tuscany/core/systemImplementation.scdl"/>
+
+ <!-- Java implementation type -->
+ <include name="org.apache.tuscany.core.JavaImplementation" scdlResource="org/apache/tuscany/core/javaImplementation.scdl"/>
+
+ <!-- Include discovery -->
+ <include name="org.apache.tuscany.service.discovery" scdlResource="org/apache/tuscany/service/discovery/discovery.jxta.scdl"/>
+
+ <!-- service for resolving artifacts using Maven repositories -->
+ <component name="artifactRepository">
+ <system:implementation.system class="org.apache.tuscany.services.maven.MavenArtifactRepository"/>
+ <property name="remoteRepoUrl">http://repo1.maven.org/maven2/,http://people.apache.org/repo/m2-snapshot-repository,http://people.apache.org/repo/m2-incubating-repository/,http://people.apache.org/repo/m1-snapshot-repository/</property>
+ </component>
+
+ <!-- WorkScheduler service -->
+ <component name="workManager">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.work.jsr237.workmanager.ThreadPoolWorkManager"/>
+ <property name="poolSize">10</property>
+ </component>
+
+ <component name="workSchCompositeContextImplTestCaseeduler">
+ <system:implementation.system class="org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler"/>
+ </component>
+
+ <component name="policyBuilderRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.policy.PolicyBuilderRegistryImpl"/>
+ </component>
+
+ <component name="propertyFactory">
+ <system:implementation.system class="org.apache.tuscany.core.property.PropertyObjectFactoryImpl"/>
+ </component>
+
+ <!-- component that scans the extension directory -->
+ <component name="directoryScanExtender" initLevel="90">
+ <system:implementation.system class="org.apache.tuscany.runtime.standalone.host.DirectoryScanExtender"/>
+ <property name="path">extensions</property>
+ </component>
+
+ <!-- the local binding -->
+ <component name="localBindingLoader">
+ <system:implementation.system class="org.apache.tuscany.core.binding.local.LocalBindingLoader"/>
+ </component>
+
+ <component name="localBindingBuilder">
+ <system:implementation.system class="org.apache.tuscany.core.binding.local.LocalBindingBuilder"/>
+ </component>
+
+</composite>
diff --git a/tags/java/tsss-demo/runtime/standalone/assembly/src/main/assembly/profiles/launcher/system.scdl b/tags/java/tsss-demo/runtime/standalone/assembly/src/main/assembly/profiles/launcher/system.scdl
new file mode 100644
index 0000000000..852d10a709
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/assembly/src/main/assembly/profiles/launcher/system.scdl
@@ -0,0 +1,189 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<!--
+ Default system configuration for the launcher environment.
+
+ $Rev$ $Date$
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ name="org.apache.tuscany.launcher.System"
+ autowire="true">
+
+ <!-- Component that provides the Deployer service -->
+ <component name="deployer">
+ <system:implementation.system class="org.apache.tuscany.core.deployer.DeployerImpl"/>
+ </component>
+
+ <!-- Work management -->
+ <component name="WorkContext">
+ <system:implementation.system class="org.apache.tuscany.core.component.WorkContextImpl"/>
+ </component>
+
+ <!-- Wire service -->
+ <component name="proxyService">
+ <system:implementation.system class="org.apache.tuscany.core.wire.jdk.JDKProxyService"/>
+ </component>
+
+ <!-- Store infrastructure -->
+ <component name="store">
+ <system:implementation.system class="org.apache.tuscany.core.services.store.memory.MemoryStore"/>
+ </component>
+
+ <!-- Builder and BuilderRegistry -->
+ <component name="builder">
+ <system:implementation.system class="org.apache.tuscany.core.builder.BuilderRegistryImpl"/>
+ </component>
+
+ <!-- Resource host registry -->
+ <component name="resourceHostRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.services.host.DelegatingResourceHostRegistry"/>
+ </component>
+
+ <!-- Loader and LoaderRegistry -->
+ <component name="loader">
+ <system:implementation.system class="org.apache.tuscany.core.loader.LoaderRegistryImpl"/>
+ </component>
+
+ <!-- Introspector and IntrospectionRegistry -->
+ <component name="interfaceProcessorRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.IntrospectionRegistryImpl"/>
+ </component>
+
+ <!-- Connector infrastructure -->
+ <component name="connector">
+ <system:implementation.system class="org.apache.tuscany.core.builder.ConnectorImpl"/>
+ </component>
+
+ <component name="wirePostProcessorRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.builder.WirePostProcessorRegistryImpl"/>
+ </component>
+
+ <!-- Default scopes -->
+ <component name="scope.stateless">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.StatelessScopeContainer"/>
+ </component>
+<!--
+ <component name="scope.request">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.RequestScopeContainer"/>
+ </component>
+-->
+<!--
+ <component name="scope.conversational">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.ConversationalScopeContainer"/>
+ </component>
+-->
+
+ <!-- include loader configuration -->
+ <include name="org.apache.tuscany.core.Loader" scdlResource="org/apache/tuscany/core/loader.scdl"/>
+
+ <!-- include databinding configuration -->
+ <include name="org.apache.tuscany.core.DataBinding" scdlResource="org/apache/tuscany/core/databinding.scdl"/>
+
+ <!-- include implementation processor configuration -->
+ <include name="org.apache.tuscany.core.Implementation" scdlResource="org/apache/tuscany/core/implementation.scdl"/>
+
+ <!-- Java interface definition language -->
+ <include name="org.apache.tuscany.core.InterfaceJava" scdlResource="org/apache/tuscany/core/interfaceJava.scdl"/>
+
+ <!-- include omposite implementation type -->
+ <include name="org.apache.tuscany.core.Composite" scdlResource="org/apache/tuscany/core/composite.scdl"/>
+
+ <!-- System implementation type -->
+ <include name="org.apache.tuscany.core.SystemImplementation" scdlResource="org/apache/tuscany/core/systemImplementation.scdl"/>
+
+ <!-- Java implementation type -->
+ <include name="org.apache.tuscany.core.JavaImplementation" scdlResource="org/apache/tuscany/core/javaImplementation.scdl"/>
+
+ <!-- service for resolving artifacts using Maven repositories -->
+ <component name="artifactRepository">
+ <system:implementation.system class="org.apache.tuscany.services.maven.MavenArtifactRepository"/>
+ <property name="remoteRepoUrl">http://repo1.maven.org/maven2/,http://people.apache.org/repo/m2-snapshot-repository,http://people.apache.org/repo/m2-incubating-repository/,http://people.apache.org/repo/m1-snapshot-repository/</property>
+ </component>
+
+ <!-- WorkScheduler service -->
+ <component name="workManager">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.work.jsr237.workmanager.ThreadPoolWorkManager"/>
+ <property name="poolSize">10</property>
+ </component>
+
+ <component name="workSchCompositeContextImplTestCaseeduler">
+ <system:implementation.system class="org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler"/>
+ </component>
+
+ <component name="policyBuilderRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.policy.PolicyBuilderRegistryImpl"/>
+ </component>
+
+ <component name="propertyFactory">
+ <system:implementation.system class="org.apache.tuscany.core.property.PropertyObjectFactoryImpl"/>
+ </component>
+
+ <!-- component that scans the extension directory -->
+ <component name="directoryScanExtender" initLevel="90">
+ <system:implementation.system class="org.apache.tuscany.runtime.standalone.host.DirectoryScanExtender"/>
+ <property name="path">extensions</property>
+ </component>
+
+ <!-- the local binding -->
+ <component name="localBindingLoader">
+ <system:implementation.system class="org.apache.tuscany.core.binding.local.LocalBindingLoader"/>
+ </component>
+
+ <component name="localBindingBuilder">
+ <system:implementation.system class="org.apache.tuscany.core.binding.local.LocalBindingBuilder"/>
+ </component>
+
+ <component name="artifactRepository">
+ <system:implementation.system class="org.apache.tuscany.core.services.artifact.LocalMavenRepository"/>
+ <property name="repository">.m2/repository</property>
+ </component>
+
+ <component name="launchedLoader">
+ <system:implementation.system class="org.apache.tuscany.runtime.standalone.host.implementation.launched.LaunchedLoader"/>
+ </component>
+
+ <component name="launchedComponentLoader">
+ <system:implementation.system class="org.apache.tuscany.runtime.standalone.host.implementation.launched.LaunchedComponentTypeLoader"/>
+ </component>
+
+ <component name="launchedComponentBuilder">
+ <system:implementation.system class="org.apache.tuscany.runtime.standalone.host.implementation.launched.LaunchedComponentBuilder"/>
+ </component>
+
+ <component name="wiringExceptionFormatter">
+ <system:implementation.system class="org.apache.tuscany.core.builder.WiringExceptionFormatter"/>
+ </component>
+
+ <component name="wiringExceptionFormatter">
+ <system:implementation.system class="org.apache.tuscany.core.builder.WiringExceptionFormatter"/>
+ </component>
+
+ <component name="loaderExceptionFormatter">
+ <system:implementation.system class="org.apache.tuscany.core.loader.LoaderExceptionFormatter"/>
+ </component>
+
+ <component name="incompatibleServiceContractExceptionFormatter">
+ <system:implementation.system class="org.apache.tuscany.core.wire.IncompatibleServiceContractExceptionFormatter"/>
+ </component>
+
+
+</composite>
diff --git a/tags/java/tsss-demo/runtime/standalone/assembly/standalone.xml b/tags/java/tsss-demo/runtime/standalone/assembly/standalone.xml
new file mode 100644
index 0000000000..87745b7021
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/assembly/standalone.xml
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<assembly>
+ <id>bin</id>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <formats>
+ <format>zip</format>
+ <format>tar.gz</format>
+ </formats>
+
+ <files>
+ <!-- include legal and other files -->
+ <file>
+ <source>LICENSE.txt</source>
+ <outputDirectory>/</outputDirectory>
+ </file>
+ <file>
+ <source>NOTICE.txt</source>
+ <outputDirectory>/</outputDirectory>
+ <filtered>true</filtered>
+ </file>
+ </files>
+
+ <fileSets>
+ <!-- include assembly files -->
+ <fileSet>
+ <directory>src/main/assembly</directory>
+ <outputDirectory>/</outputDirectory>
+ </fileSet>
+ </fileSets>
+
+ <dependencySets>
+ <!-- copy executable commands to the bin directory without version info -->
+ <dependencySet>
+ <includes>
+ <include>org.apache.tuscany.sca.runtime.standalone:launcher</include>
+ </includes>
+ <excludes>
+ <exclude>org.apache.tuscany.sca.runtime.standalone:standalone-api</exclude>
+ </excludes>
+ <outputDirectory>bin</outputDirectory>
+ <outputFileNameMapping>${artifactId}.${extension}</outputFileNameMapping>
+ <fileMode>755</fileMode>
+ </dependencySet>
+
+ <!-- copy dependencies used by the executable commands to the lib directory -->
+ <dependencySet>
+ <includes>
+ <include>org.apache.tuscany.sca.runtime.standalone:standalone-api</include>
+ <include>org.osoa:sca-api-r1.0</include>
+ <include>org.apache.tuscany.sca.kernel:tuscany-api</include>
+ <include>org.apache.tuscany.sca.kernel:tuscany-host-api</include>
+ </includes>
+ <outputDirectory>lib</outputDirectory>
+ <outputFileNameMapping>${artifactId}-${baseVersion}.${extension}</outputFileNameMapping>
+ </dependencySet>
+
+ <!-- copy boot dependencies to launcher profile -->
+ <dependencySet>
+ <includes>
+ <include>org.apache.tuscany.sca.runtime.standalone:standalone-host</include>
+ </includes>
+ <excludes>
+ <exclude>junit:junit</exclude>
+ </excludes>
+ <outputDirectory>profiles/launcher/boot</outputDirectory>
+ </dependencySet>
+ </dependencySets>
+</assembly>
+
diff --git a/tags/java/tsss-demo/runtime/standalone/launcher/.ruleset b/tags/java/tsss-demo/runtime/standalone/launcher/.ruleset
new file mode 100644
index 0000000000..f27a8fe562
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/launcher/.ruleset
@@ -0,0 +1,190 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<ruleset name="pmd-eclipse">
+ <description>PMD Plugin preferences rule set</description>
+
+
+ <rule ref="rulesets/basic.xml/BooleanInstantiation"/>
+ <rule ref="rulesets/basic.xml/CollapsibleIfStatements"/>
+ <rule ref="rulesets/basic.xml/DoubleCheckedLocking"/>
+<!--<rule ref="rulesets/basic.xml/EmptyCatchBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyFinallyBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyIfStmt"/>-->
+ <rule ref="rulesets/basic.xml/EmptyStatementNotInLoop"/>
+<!--<rule ref="rulesets/basic.xml/EmptyStaticInitializer"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptySwitchStatements"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptySynchronizedBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyTryBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyWhileStmt"/>-->
+ <rule ref="rulesets/basic.xml/ForLoopShouldBeWhileLoop"/>
+ <rule ref="rulesets/basic.xml/JumbledIncrementer"/>
+<!--<rule ref="rulesets/basic.xml/OverrideBothEqualsAndHashcode"/>-->
+ <rule ref="rulesets/basic.xml/ReturnFromFinallyBlock"/>
+ <rule ref="rulesets/basic.xml/UnconditionalIfStatement"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryConversionTemporary"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryFinalModifier"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryReturn"/>
+<!--<rule ref="rulesets/basic.xml/UselessOverridingMethod"/>-->
+
+<!--<rule ref="rulesets/braces.xml/ForLoopsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/IfElseStmtsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/IfStmtsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/WhileLoopsMustUseBraces"/>-->
+
+<!--<rule ref="rulesets/clone.xml/CloneMethodMustImplementCloneable"/>-->
+<!--<rule ref="rulesets/clone.xml/CloneThrowsCloneNotSupportedException"/>-->
+<!--<rule ref="rulesets/clone.xml/ProperCloneImplementation"/>-->
+
+<!--<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>-->
+<!--<rule ref="rulesets/codesize.xml/TooManyFields"/>-->
+
+<rule ref="rulesets/controversial.xml/AssignmentInOperand"/>
+<!--<rule ref="rulesets/controversial.xml/AtLeastOneConstructor"/>-->
+<!--<rule ref="rulesets/controversial.xml/CallSuperInConstructor"/>-->
+<!--<rule ref="rulesets/controversial.xml/DontImportSun"/>-->
+<!--<rule ref="rulesets/controversial.xml/NullAssignment"/>-->
+<!--<rule ref="rulesets/controversial.xml/OnlyOneReturn"/>-->
+<!--<rule ref="rulesets/controversial.xml/SingularField"/>-->
+<!--<rule ref="rulesets/controversial.xml/SuspiciousOctalEscape"/>-->
+<!--<rule ref="rulesets/controversial.xml/UnnecessaryConstructor"/>-->
+<rule ref="rulesets/controversial.xml/UnnecessaryParentheses"/>
+<!--<rule ref="rulesets/controversial.xml/UnusedModifier"/>-->
+
+<!--<rule ref="rulesets/coupling.xml/CouplingBetweenObjects"/>-->
+<!--<rule ref="rulesets/coupling.xml/ExcessiveImports"/>-->
+<!--<rule ref="rulesets/coupling.xml/LooseCoupling"/>-->
+
+<!--<rule ref="rulesets/design.xml/AbstractClassWithoutAbstractMethod"/>-->
+<!--<rule ref="rulesets/design.xml/AccessorClassGeneration"/>-->
+<!--<rule ref="rulesets/design.xml/AssignmentToNonFinalStatic"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidDeeplyNestedIfStmts"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidInstanceofChecksInCatchClause"/>-->
+<rule ref="rulesets/design.xml/AvoidProtectedFieldInFinalClass"/>
+<!--<rule ref="rulesets/design.xml/AvoidReassigningParameters"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidSynchronizedAtMethodLevel"/>-->
+<!--<rule ref="rulesets/design.xml/BadComparison"/>-->
+<!--<rule ref="rulesets/design.xml/CloseConnection"/>-->
+<!--<rule ref="rulesets/design.xml/CompareObjectsWithEquals"/>-->
+<!--<rule ref="rulesets/design.xml/ConfusingTernary"/>-->
+<rule ref="rulesets/design.xml/ConstructorCallsOverridableMethod"/>
+<!--<rule ref="rulesets/design.xml/DefaultLabelNotLastInSwitchStmt"/>-->
+<!--<rule ref="rulesets/design.xml/FinalFieldCouldBeStatic"/>-->
+<rule ref="rulesets/design.xml/IdempotentOperations"/>
+<!--<rule ref="rulesets/design.xml/ImmutableField"/>-->
+<!--<rule ref="rulesets/design.xml/InstantiationToGetClass"/>-->
+<!--<rule ref="rulesets/design.xml/MissingBreakInSwitch"/>-->
+<!--<rule ref="rulesets/design.xml/MissingStaticMethodInNonInstantiatableClass"/>-->
+<!--<rule ref="rulesets/design.xml/NonCaseLabelInSwitchStatement"/>-->
+<!--<rule ref="rulesets/design.xml/NonStaticInitializer"/>-->
+<rule ref="rulesets/design.xml/OptimizableToArrayCall"/>
+<rule ref="rulesets/design.xml/PositionLiteralsFirstInComparisons"/>
+<rule ref="rulesets/design.xml/SimplifyBooleanExpressions"/>
+<rule ref="rulesets/design.xml/SimplifyBooleanReturns"/>
+<rule ref="rulesets/design.xml/SimplifyConditional"/>
+<!--<rule ref="rulesets/design.xml/SwitchDensity"/>-->
+<!--<rule ref="rulesets/design.xml/SwitchStmtsShouldHaveDefault"/>-->
+<!--<rule ref="rulesets/design.xml/UnnecessaryLocalBeforeReturn"/>-->
+<!--<rule ref="rulesets/design.xml/UseLocaleWithCaseConversions"/>-->
+<!--<rule ref="rulesets/design.xml/UseNotifyAllInsteadOfNotify"/>-->
+<!--<rule ref="rulesets/design.xml/UseSingleton"/>-->
+
+<!--<rule ref="rulesets/finalizers.xml/EmptyFinalizer"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeOnlyCallsSuperFinalize"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeOverloaded"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeDoesNotCallSuperFinalize"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeShouldBeProtected"/>-->
+<!--<rule ref="rulesets/finalizers.xml/AvoidCallingFinalize"/>-->
+
+<!--<rule ref="rulesets/imports.xml/DuplicateImports"/>-->
+<!--<rule ref="rulesets/imports.xml/DontImportJavaLang"/>-->
+<!--<rule ref="rulesets/imports.xml/UnusedImports"/>-->
+<!--<rule ref="rulesets/imports.xml/ImportFromSamePackage"/>-->
+
+<!--<rule ref="rulesets/javabeans.xml/BeanMembersShouldSerialize"/>-->
+<!--<rule ref="rulesets/javabeans.xml/MissingSerialVersionUID"/>-->
+
+<!--<rule ref="rulesets/junit.xml/JUnitStaticSuite"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitSpelling"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitAssertionsShouldIncludeMessage"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitTestsShouldIncludeAssert"/>-->
+<!--<rule ref="rulesets/junit.xml/TestClassWithoutTestCases"/>-->
+<!--<rule ref="rulesets/junit.xml/UnnecessaryBooleanAssertion"/>-->
+<!--<rule ref="rulesets/junit.xml/UseAssertEqualsInsteadOfAssertTrue"/>-->
+<!--<rule ref="rulesets/junit.xml/UseAssertSameInsteadOfAssertTrue"/>-->
+
+ <!--<rule ref="rulesets/logging-java.xml/AvoidPrintStackTrace"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/MoreThanOneLogger"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LogBlockWithoutIf"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/SystemPrintln"/>-->
+ <!--<rule ref="rulesets/logging-jakarta-commons.xml/UseCorrectExceptionLogging"/>-->
+ <!--<rule ref="rulesets/logging-jakarta-commons.xml/ProperLogger"/>-->
+
+ <!--<rule ref="rulesets/naming.xml/ShortVariable"/>-->
+ <!--<rule ref="rulesets/naming.xml/LongVariable"/>-->
+ <!--<rule ref="rulesets/naming.xml/ShortMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/VariableNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/MethodNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/ClassNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/AbstractNaming"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidDollarSigns"/>-->
+ <!--<rule ref="rulesets/naming.xml/MethodWithSameNameAsEnclosingClass"/>-->
+ <!--<rule ref="rulesets/naming.xml/SuspiciousHashcodeMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/SuspiciousConstantFieldName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingTypeName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidNonConstructorMethodsWithClassName"/>-->
+ <!--<rule ref="rulesets/naming.xml/NoPackage"/>-->
+ <!--<rule ref="rulesets/naming.xml/PackageCase"/>-->
+
+ <!--<rule ref="rulesets/optimizations.xml/LocalVariableCouldBeFinal"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/MethodArgumentCouldBeFinal"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/AvoidInstantiatingObjectsInLoops"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/UseArrayListInsteadOfVector"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/SimplifyStartsWith"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/UseStringBufferForStringAppends"/>-->
+
+ <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingThrowable"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/SignatureDeclareThrowsException"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/ExceptionAsFlowControl"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingNPE"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingRawExceptionTypes"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingNullPointerException"/>-->
+
+ <!--<rule ref="rulesets/strings.xml/AvoidDuplicateLiterals"/>-->
+ <!--<rule ref="rulesets/strings.xml/StringInstantiation"/>-->
+ <!--<rule ref="rulesets/strings.xml/StringToString"/>-->
+ <!--<rule ref="rulesets/strings.xml/AvoidConcatenatingNonLiteralsInStringBuffer"/>-->
+ <!--<rule ref="rulesets/strings.xml/UnnecessaryCaseChange"/>-->
+
+ <!--<rule ref="rulesets/sunsecure.xml/MethodReturnsInternalArray"/>-->
+ <!--<rule ref="rulesets/sunsecure.xml/ArrayIsStoredDirectly"/>-->
+
+ <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/>
+ <rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/>
+ <rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/>
+ <!--<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>-->
+
+</ruleset>
diff --git a/tags/java/tsss-demo/runtime/standalone/launcher/LICENSE.txt b/tags/java/tsss-demo/runtime/standalone/launcher/LICENSE.txt
new file mode 100644
index 0000000000..0084319535
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/launcher/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, serviceDefinition marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/runtime/standalone/launcher/NOTICE.txt b/tags/java/tsss-demo/runtime/standalone/launcher/NOTICE.txt
new file mode 100644
index 0000000000..d83ebbe236
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/launcher/NOTICE.txt
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/runtime/standalone/launcher/pom.xml b/tags/java/tsss-demo/runtime/standalone/launcher/pom.xml
new file mode 100644
index 0000000000..50db868b9d
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/launcher/pom.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca.runtime</groupId>
+ <artifactId>standalone</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.runtime.standalone</groupId>
+ <artifactId>launcher</artifactId>
+ <name>Apache Tuscany SCA Application Launcher</name>
+ <description>Standalone executable jar that can be used to launch a SCA application.</description>
+
+ <!--
+ This library will typically be added to the application's classpath and so should
+ should have as few dependencies as possible and nothing from the Tuscany runtime.
+ -->
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.runtime.standalone</groupId>
+ <artifactId>standalone-api</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>org.apache.tuscany.launcher.Main</mainClass>
+ <addClasspath>true</addClasspath>
+ <classpathPrefix>../lib/</classpathPrefix>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tags/java/tsss-demo/runtime/standalone/launcher/src/main/java/org/apache/tuscany/launcher/Main.java b/tags/java/tsss-demo/runtime/standalone/launcher/src/main/java/org/apache/tuscany/launcher/Main.java
new file mode 100644
index 0000000000..e011c5a3a5
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/launcher/src/main/java/org/apache/tuscany/launcher/Main.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.launcher;
+
+import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.text.MessageFormat;
+import java.util.ResourceBundle;
+
+import org.apache.tuscany.runtime.standalone.DirectoryHelper;
+import org.apache.tuscany.runtime.standalone.StandaloneRuntime;
+import org.apache.tuscany.runtime.standalone.StandaloneRuntimeInfo;
+
+/**
+ * Main class for launcher runtime environment. <code>
+ * usage: java [jvm-options] -jar launcher.jar <componentURI>
+ * </code>
+ * where the componentURI identifies a component in the assembly that should be
+ * called.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Main {
+
+ /**
+ * Main method.
+ *
+ * @param args the command line args
+ * @throws Throwable if there are problems launching the runtime or
+ * application
+ */
+ public static void main(String[] args) throws Throwable {
+
+ if (args.length < 1) {
+ usage();
+ throw new AssertionError();
+ }
+
+ File applicationFile = new File(args[0]);
+ if (!applicationFile.exists()) {
+ System.err.println(getMessage("org.apache.tuscany.launcher.NoComposite", applicationFile));
+ System.exit(2);
+ }
+
+ String[] appArgs = new String[0];
+ if(args.length > 1) {
+ appArgs = new String[args.length - 1];
+ System.arraycopy(args, 1, appArgs, 0, appArgs.length);
+ }
+
+ StandaloneRuntimeInfo runtimeInfo = DirectoryHelper.createRuntimeInfo("launcher", Main.class);
+ StandaloneRuntime runtime = (StandaloneRuntime)DirectoryHelper.createRuntime(runtimeInfo);
+
+ URL applicationJar = applicationFile.toURL();
+ ClassLoader applicationClassLoader =
+ new URLClassLoader(new URL[] {applicationJar}, runtime.getHostClassLoader());
+ String applicationScdl = System.getProperty("launcher.scdl", "META-INF/sca/default.scdl");
+ URL applicationScdlURL = applicationClassLoader.getResource(applicationScdl);
+ if (applicationScdlURL == null) {
+ System.err.println(getMessage("org.apache.tuscany.launcher.NoApplicationSCDL", applicationScdl));
+ System.exit(2);
+ }
+
+ // boot the runtime
+ runtime.initialize();
+
+ int status = runtime.deployAndRun(applicationScdlURL, applicationClassLoader, appArgs);
+ System.exit(status);
+ }
+
+ private static void usage() {
+ System.err.println(getMessage("org.apache.tuscany.launcher.Usage"));
+ System.exit(1);
+ }
+
+ private static String getMessage(String id, Object... params) {
+ ResourceBundle bundle = ResourceBundle.getBundle(Main.class.getName());
+ String message = bundle.getString(id);
+ return MessageFormat.format(message, params);
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/standalone/launcher/src/main/resources/org/apache/tuscany/launcher/Main.properties b/tags/java/tsss-demo/runtime/standalone/launcher/src/main/resources/org/apache/tuscany/launcher/Main.properties
new file mode 100644
index 0000000000..51cdb7087a
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/launcher/src/main/resources/org/apache/tuscany/launcher/Main.properties
@@ -0,0 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# $Rev$ $Date$
+#
+org.apache.tuscany.launcher.Usage=usage: java [jvm-options] -jar launcher.jar <componentJar> [apparg1, apparg2, ...]
+org.apache.tuscany.launcher.NoComponent=No component found with id "{0}"
+org.apache.tuscany.launcher.NoComposite=No composite archive found: {0}
+org.apache.tuscany.launcher.NoApplicationSCDL=No application SCDL found: {0}
diff --git a/tags/java/tsss-demo/runtime/standalone/pom.xml b/tags/java/tsss-demo/runtime/standalone/pom.xml
new file mode 100644
index 0000000000..1a38e942cc
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/pom.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>runtime</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.runtime</groupId>
+ <artifactId>standalone</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache Tuscany Standalone SCA Runtime</name>
+
+ <profiles>
+ <profile>
+ <id>default</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <modules>
+ <module>standalone-api</module>
+ <module>launcher</module>
+ <module>standalone-host</module>
+ <module>server.start</module>
+ <module>server.shutdown</module>
+ <module>assembly</module>
+ <module>smoketest</module>
+ </modules>
+ </profile>
+
+ <profile>
+ <!-- for the release profile exclude the smoketest -->
+ <id>release</id>
+ <modules>
+ <module>standalone-api</module>
+ <module>launcher</module>
+ <module>standalone-host</module>
+ <module>server.start</module>
+ <module>server.shutdown</module>
+ <module>assembly</module>
+ </modules>
+ </profile>
+ </profiles>
+</project>
diff --git a/tags/java/tsss-demo/runtime/standalone/server.shutdown/LICENSE.txt b/tags/java/tsss-demo/runtime/standalone/server.shutdown/LICENSE.txt
new file mode 100644
index 0000000000..0084319535
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/server.shutdown/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, serviceDefinition marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/runtime/standalone/server.shutdown/NOTICE.txt b/tags/java/tsss-demo/runtime/standalone/server.shutdown/NOTICE.txt
new file mode 100644
index 0000000000..d83ebbe236
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/server.shutdown/NOTICE.txt
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/runtime/standalone/server.shutdown/pom.xml b/tags/java/tsss-demo/runtime/standalone/server.shutdown/pom.xml
new file mode 100644
index 0000000000..17eaeaceed
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/server.shutdown/pom.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca.runtime</groupId>
+ <artifactId>standalone</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.runtime.standalone</groupId>
+ <artifactId>server.shutdown</artifactId>
+ <name>Apache Tuscany Standalone Server Shutdown</name>
+ <description>Standalone executable jar that can be used to shutdown the tuscany server.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.runtime.standalone</groupId>
+ <artifactId>standalone-api</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>org.apache.tuscany.standalone.server.ShutdownServer</mainClass>
+ <addClasspath>true</addClasspath>
+ <classpathPrefix>../lib/</classpathPrefix>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tags/java/tsss-demo/runtime/standalone/server.shutdown/src/main/java/org/apache/tuscany/standalone/server/ShutdownServer.java b/tags/java/tsss-demo/runtime/standalone/server.shutdown/src/main/java/org/apache/tuscany/standalone/server/ShutdownServer.java
new file mode 100644
index 0000000000..ada82c4bb3
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/server.shutdown/src/main/java/org/apache/tuscany/standalone/server/ShutdownServer.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.standalone.server;
+
+import java.io.IOException;
+
+import javax.management.JMException;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.management.remote.JMXServiceURL;
+import javax.management.remote.rmi.RMIConnector;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ *
+ */
+public class ShutdownServer {
+
+ /** Tuscany admin host. */
+ private static final String ADMIN_HOST_PROPERTY = "tuscany.adminHost";
+
+ /** Tuscany admin port. */
+ private static final String ADMIN_PORT_PROPERTY = "tuscany.adminPort";
+
+ /** Default host. */
+ private static final String DEFAULT_ADMIN_HOST = "localhost";
+
+ /** Default port. */
+ private static final int DEFAULT_ADMIN_PORT = 1099;
+
+ /** Host. */
+ private String host = DEFAULT_ADMIN_HOST;
+
+ /** Port. */
+ private int port = DEFAULT_ADMIN_PORT;
+
+ /**
+ *
+ * @param args Commandline arguments.
+ */
+ public static void main(String[] args) throws Exception {
+
+ ShutdownServer shutdownServer = new ShutdownServer();
+ shutdownServer.shutdown();
+
+ }
+
+ /**
+ * Initializes the host and the port.
+ *
+ */
+ private ShutdownServer() {
+
+ if(System.getProperty(ADMIN_HOST_PROPERTY) != null) {
+ host = System.getProperty(ADMIN_HOST_PROPERTY);
+ }
+
+ if(System.getProperty(ADMIN_PORT_PROPERTY) != null) {
+ port = Integer.parseInt(System.getProperty(ADMIN_PORT_PROPERTY));
+ }
+
+ }
+
+ /**
+ * Shuts down the server.
+ * @throws IOException
+ * @throws JMException
+ *
+ */
+ private void shutdown() throws IOException, JMException {
+
+ RMIConnector rmiConnector = null;
+
+ try {
+
+ JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/server");
+ rmiConnector = new RMIConnector(url, null);
+ rmiConnector.connect();
+
+ MBeanServerConnection con = rmiConnector.getMBeanServerConnection();
+ con.invoke(new ObjectName("tuscany:name=tuscanyServer"), "shutdown", null, null);
+
+ } finally {
+ if(rmiConnector != null) {
+ rmiConnector.close();
+ }
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/standalone/server.start/LICENSE.txt b/tags/java/tsss-demo/runtime/standalone/server.start/LICENSE.txt
new file mode 100644
index 0000000000..0084319535
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/server.start/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, serviceDefinition marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/runtime/standalone/server.start/NOTICE.txt b/tags/java/tsss-demo/runtime/standalone/server.start/NOTICE.txt
new file mode 100644
index 0000000000..d83ebbe236
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/server.start/NOTICE.txt
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/runtime/standalone/server.start/pom.xml b/tags/java/tsss-demo/runtime/standalone/server.start/pom.xml
new file mode 100644
index 0000000000..e9d8cbcdb1
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/server.start/pom.xml
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca.runtime</groupId>
+ <artifactId>standalone</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.runtime.standalone</groupId>
+ <artifactId>server.start</artifactId>
+ <name>Apache Tuscany Standalone Server Start</name>
+ <description>Standalone executable jar that can be used to start the tuscany server.</description>
+
+ <!--
+ This library will typically be added to the application's classpath and so should
+ should have as few dependencies as possible and nothing from the Tuscany runtime.
+ -->
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.runtime.standalone</groupId>
+ <artifactId>standalone-api</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.runtime.services.management</groupId>
+ <artifactId>management-jmx</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>org.apache.tuscany.standalone.server.TuscanyServer</mainClass>
+ <addClasspath>true</addClasspath>
+ <classpathPrefix>../lib/</classpathPrefix>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tags/java/tsss-demo/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/TuscanyServer.java b/tags/java/tsss-demo/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/TuscanyServer.java
new file mode 100644
index 0000000000..de23beb613
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/TuscanyServer.java
@@ -0,0 +1,264 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.standalone.server;
+
+import java.beans.Beans;
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.management.MBeanServer;
+
+import org.apache.tuscany.host.management.ManagementService;
+import org.apache.tuscany.host.runtime.InitializationException;
+import org.apache.tuscany.host.runtime.ShutdownException;
+import org.apache.tuscany.host.runtime.TuscanyRuntime;
+import org.apache.tuscany.runtime.standalone.DirectoryHelper;
+import org.apache.tuscany.runtime.standalone.StandaloneRuntime;
+import org.apache.tuscany.runtime.standalone.StandaloneRuntimeInfo;
+import org.apache.tuscany.runtime.standalone.StandaloneRuntimeInfoImpl;
+import org.apache.tuscany.service.management.jmx.JmxManagementService;
+import org.apache.tuscany.service.management.jmx.agent.Agent;
+import org.apache.tuscany.service.management.jmx.agent.RmiAgent;
+
+/**
+ * This class provides the commandline interface for starting the
+ * tuscany standalone server.
+ * <p/>
+ * <p/>
+ * The class boots the tuscany server and also starts a JMX server
+ * and listens for shutdown command. The server itself is available
+ * by the object name <code>tuscany:type=server,name=tuscanyServer
+ * </code>. It also allows a runtime to be booted given a bootpath.
+ * The JMX domain in which the runtime is registered si definied in
+ * the file <code>$bootPath/etc/runtime.properties</code>. The properties
+ * defined are <code>jmx.domain</code> and <code>offline</code>.
+ * </p>
+ * <p/>
+ * <p/>
+ * The install directory can be specified using the system property
+ * <code>tuscany.installDir</code>. If not specified it is asumed to
+ * be the directory from where the JAR file containing the main class
+ * is loaded.
+ * </p>
+ * <p/>
+ * <p/>
+ * The administration port can be specified using the system property
+ * <code>tuscany.adminPort</tuscany>.If not specified the default port
+ * that is used is <code>1099</code>
+ *
+ * @version $Rev$ $Date$
+ */
+public class TuscanyServer implements TuscanyServerMBean {
+
+ /**
+ * Agent
+ */
+ private final Agent agent;
+
+ /**
+ * Install directory
+ */
+ private final File installDirectory;
+
+ /**
+ * Started runtimes.
+ */
+ private final Map<String, TuscanyRuntime> bootedRuntimes = new ConcurrentHashMap<String, TuscanyRuntime>();
+
+ /**
+ * @param args Commandline arguments.
+ */
+ public static void main(String[] args) throws Exception {
+ TuscanyServer server = new TuscanyServer();
+ server.start();
+
+ // Start any runtimes specified in the cli
+ for(String profile : args) {
+ server.startRuntime(profile);
+ }
+ }
+
+ /**
+ * Constructor initializes all the required classloaders.
+ *
+ * @throws MalformedURLException
+ */
+ private TuscanyServer() throws MalformedURLException {
+ installDirectory = DirectoryHelper.getInstallDirectory(TuscanyServer.class);
+ agent = RmiAgent.getInstance();
+ }
+
+ /**
+ * Starts a runtime specified by the bootpath.
+ *
+ * @param profileName Profile for the runtime.
+ */
+ public final void startRuntime(final String profileName) {
+
+ try {
+
+ final File profileDirectory = DirectoryHelper.getProfileDirectory(installDirectory, profileName);
+ final File bootDirectory = DirectoryHelper.getBootDirectory(installDirectory, profileDirectory, null);
+
+ final MBeanServer mBeanServer = agent.getMBeanServer();
+ final StandaloneRuntimeInfo runtimeInfo = createRuntimeInfo(profileName);
+ final ManagementService<?> managementService = new JmxManagementService(mBeanServer, profileName);
+ final TuscanyRuntime<?> runtime = createRuntime(bootDirectory, runtimeInfo);
+ runtime.setManagementService(managementService);
+ runtime.initialize();
+
+ bootedRuntimes.put(profileName, runtime);
+
+ } catch (InitializationException ex) {
+ ex.printStackTrace();
+ throw new TuscanyServerException(ex);
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ throw new TuscanyServerException(ex);
+ } catch (ClassNotFoundException ex) {
+ ex.printStackTrace();
+ throw new TuscanyServerException(ex);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ throw new TuscanyServerException(ex);
+ } catch (Throwable ex) {
+ ex.printStackTrace();
+ throw new TuscanyServerException(ex);
+ }
+
+ System.err.println("Started");
+
+ }
+
+ /**
+ * @see org.apache.tuscany.standalone.server.TuscanyServerMBean#shutdownRuntime(java.lang.String)
+ */
+ public final void shutdownRuntime(String bootPath) {
+
+ try {
+ TuscanyRuntime runtime = bootedRuntimes.get(bootPath);
+ if (runtime != null) {
+ runtime.destroy();
+ bootedRuntimes.remove(runtime);
+ runtime = null;
+ }
+ } catch (ShutdownException ex) {
+ throw new TuscanyServerException(ex);
+ }
+
+ }
+
+ /**
+ * Starts the server.
+ */
+ public final void shutdown() {
+
+ for (String bootPath : bootedRuntimes.keySet()) {
+ shutdownRuntime(bootPath);
+ }
+ agent.shutdown();
+ System.err.println("Shutdown");
+ System.exit(0);
+
+ }
+
+ /**
+ * TODO Share this code with launcher.
+ *
+ * Creates the runtime info.
+ *
+ * @param profile profile for which runtime info is created.
+ * @return Runtime info.
+ * @throws IOException If unable to read the runtime properties.
+ * @throws URISyntaxException
+ */
+ private StandaloneRuntimeInfo createRuntimeInfo(String profile) throws IOException, URISyntaxException {
+
+ File profileDir = DirectoryHelper.getProfileDirectory(installDirectory, profile);
+
+ // load properties for this runtime
+ File propFile = new File(profileDir, "etc/runtime.properties");
+ Properties props = DirectoryHelper.loadProperties(propFile, System.getProperties());
+ String domain = props.getProperty("domain");
+
+ // online unless the offline property is set
+ boolean online = !Boolean.parseBoolean(props.getProperty("offline", "false"));
+
+
+ return new StandaloneRuntimeInfoImpl(new URI(domain), profile, installDirectory, profileDir, null, online, props);
+ }
+
+ /**
+ * TODO Share this code with launcher.
+ *
+ * Creates the runtime.
+ *
+ * @param bootDirectory Boot directory for the runtime.
+ * @param runtimeInfo Runtime info.
+ * @return Runtime.
+ */
+ private TuscanyRuntime createRuntime(final File bootDirectory, final StandaloneRuntimeInfo runtimeInfo) throws IOException, ClassNotFoundException {
+
+ final URL profileUrl = runtimeInfo.getProfileDirectory().toURL();
+ final ClassLoader hostClassLoader = ClassLoader.getSystemClassLoader();
+ final ClassLoader bootClassLoader = DirectoryHelper.createClassLoader(hostClassLoader, bootDirectory);
+
+ final URL systemScdl = getSystemScdl(profileUrl, runtimeInfo);
+ if (systemScdl == null) {
+ throw new TuscanyServerException("Unable to find system scdl");
+ }
+
+ final String className =
+ runtimeInfo.getProperty("tuscany.launcherClass",
+ "org.apache.tuscany.runtime.standalone.host.StandaloneRuntimeImpl");
+ final StandaloneRuntime runtime = (StandaloneRuntime) Beans.instantiate(bootClassLoader, className);
+ runtime.setSystemScdl(systemScdl);
+ runtime.setHostClassLoader(hostClassLoader);
+
+ runtime.setRuntimeInfo(runtimeInfo);
+ return runtime;
+
+ }
+
+ /**
+ * Gets the system SCDL.
+ *
+ * @param bootClassLoader Boot classloader.
+ * @return URL to the system SCDL.
+ * @throws MalformedURLException
+ */
+ private URL getSystemScdl(URL profileUrl, StandaloneRuntimeInfo runtimeInfo) throws MalformedURLException {
+ return new URL(profileUrl, runtimeInfo.getProperty("tuscany.systemSCDL", "system.scdl"));
+ }
+
+ /**
+ * Starts the server and starts the JMX agent.
+ */
+ private void start() {
+ agent.start();
+ agent.register(this, "tuscany:type=server,name=tuscanyServer");
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/TuscanyServerException.java b/tags/java/tsss-demo/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/TuscanyServerException.java
new file mode 100644
index 0000000000..97a81162ee
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/TuscanyServerException.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.standalone.server;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * Exception thrown by the tuscany server during startup and shutdown.
+ *
+ * @version $Revisiion$ $Date$
+ *
+ */
+
+@SuppressWarnings("serial")
+public class TuscanyServerException extends TuscanyRuntimeException {
+
+ /**
+ * Initializes the cause.
+ * @param cause Root cause of the exception.
+ */
+ public TuscanyServerException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Initializes the message.
+ * @param message Message of the exception.
+ */
+ public TuscanyServerException(String message) {
+ super(message);
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/TuscanyServerMBean.java b/tags/java/tsss-demo/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/TuscanyServerMBean.java
new file mode 100644
index 0000000000..a3bc6291b2
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/TuscanyServerMBean.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.standalone.server;
+
+/**
+ * Management interface for the tuscany server.
+ *
+ * @version $Revision$ $Date$
+ *
+ */
+public interface TuscanyServerMBean {
+
+ /**
+ * Starts a runtime specified by the bootpath.
+ *
+ * @param profileName Profile for the runtime.
+ */
+ public void startRuntime(String profileName);
+
+ /**
+ * Shuts down a runtime specified by the bootpath.
+ *
+ * @param bootPath Bootpath for the runtime.
+ */
+ public void shutdownRuntime(String bootPath);
+
+ /**
+ * Starts the server.
+ *
+ */
+ public void shutdown();
+
+}
diff --git a/tags/java/tsss-demo/runtime/standalone/smoketest/pom.xml b/tags/java/tsss-demo/runtime/standalone/smoketest/pom.xml
new file mode 100644
index 0000000000..5aec4763e3
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/smoketest/pom.xml
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca.runtime</groupId>
+ <artifactId>standalone</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.runtime.standalone</groupId>
+ <artifactId>smoketest</artifactId>
+ <name>Apache Tuscany SCA Standalone Smoketest</name>
+ <description>Module to smoketest the standalone runtime.</description>
+
+ <properties>
+ <tuscany.installDir>${project.build.directory}/assembly</tuscany.installDir>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osoa</groupId>
+ <artifactId>sca-api-r${scaSpecVersion}</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <finalName>smoketest</finalName>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>unpack</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.apache.tuscany.sca.runtime.standalone</groupId>
+ <artifactId>assembly</artifactId>
+ <version>${project.version}</version>
+ <classifier>bin</classifier>
+ <type>zip</type>
+ <overWrite>true</overWrite>
+ <outputDirectory>${tuscany.installDir}</outputDirectory>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>integration-test</phase>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <includes>
+ <include>**/SmokeTest*.java</include>
+ </includes>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tags/java/tsss-demo/runtime/standalone/smoketest/src/main/java/org/apache/tuscany/sca/runtime/standalone/smoketest/HelloService.java b/tags/java/tsss-demo/runtime/standalone/smoketest/src/main/java/org/apache/tuscany/sca/runtime/standalone/smoketest/HelloService.java
new file mode 100644
index 0000000000..7d45d73183
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/smoketest/src/main/java/org/apache/tuscany/sca/runtime/standalone/smoketest/HelloService.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.runtime.standalone.smoketest;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface HelloService {
+ String getGreeting();
+}
diff --git a/tags/java/tsss-demo/runtime/standalone/smoketest/src/main/java/org/apache/tuscany/sca/runtime/standalone/smoketest/HelloServiceImpl.java b/tags/java/tsss-demo/runtime/standalone/smoketest/src/main/java/org/apache/tuscany/sca/runtime/standalone/smoketest/HelloServiceImpl.java
new file mode 100644
index 0000000000..a2d367096a
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/smoketest/src/main/java/org/apache/tuscany/sca/runtime/standalone/smoketest/HelloServiceImpl.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.runtime.standalone.smoketest;
+
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class HelloServiceImpl implements HelloService {
+ private final String greeting;
+
+ public HelloServiceImpl(@Property(name="greeting") String greeting) {
+ this.greeting = greeting;
+ }
+
+ public String getGreeting() {
+ return greeting;
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/standalone/smoketest/src/main/java/org/apache/tuscany/sca/runtime/standalone/smoketest/Launched.java b/tags/java/tsss-demo/runtime/standalone/smoketest/src/main/java/org/apache/tuscany/sca/runtime/standalone/smoketest/Launched.java
new file mode 100644
index 0000000000..271f9e8273
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/smoketest/src/main/java/org/apache/tuscany/sca/runtime/standalone/smoketest/Launched.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.runtime.standalone.smoketest;
+
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class Launched {
+ private HelloService hello;
+
+ @Reference
+ public void setHello(HelloService hello) {
+ this.hello = hello;
+ }
+
+ public int main(String[] args) throws Exception {
+ if (args.length == 0) {
+ System.out.println("No Args");
+ return 0;
+ }
+ String command = args[0];
+ if ("testReference".equals(command)) {
+ if ("Hello World".equals(hello.getGreeting())) {
+ return 0;
+ } else {
+ return 1;
+ }
+ }
+ return 1;
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/standalone/smoketest/src/main/resources/META-INF/sca/default.scdl b/tags/java/tsss-demo/runtime/standalone/smoketest/src/main/resources/META-INF/sca/default.scdl
new file mode 100644
index 0000000000..ca2ac88a01
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/smoketest/src/main/resources/META-INF/sca/default.scdl
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/2.0-alpha"
+ name="SmoketestComposite">
+
+ <component name="Main">
+ <tuscany:launched class="org.apache.tuscany.sca.runtime.standalone.smoketest.Launched"/>
+ <reference name="hello" target="Hello"/>
+ </component>
+
+ <component name="Hello">
+ <implementation.java class="org.apache.tuscany.sca.runtime.standalone.smoketest.HelloServiceImpl"/>
+ <property name="greeting">Hello World</property>
+ </component>
+</composite>
diff --git a/tags/java/tsss-demo/runtime/standalone/smoketest/src/test/java/org/apache/tuscany/sca/runtime/standalone/smoketest/CommandTestCase.java b/tags/java/tsss-demo/runtime/standalone/smoketest/src/test/java/org/apache/tuscany/sca/runtime/standalone/smoketest/CommandTestCase.java
new file mode 100644
index 0000000000..64d5c02192
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/smoketest/src/test/java/org/apache/tuscany/sca/runtime/standalone/smoketest/CommandTestCase.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.standalone.smoketest;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.BufferedInputStream;
+import java.io.File;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public abstract class CommandTestCase extends TestCase {
+ protected File buildDir;
+ protected File installDir;
+
+ public void compareOutput(String master, InputStream is) throws Exception {
+ String processText = readStream(is);
+ assertEquals(master, processText);
+ }
+
+ public String loadResource(String resource) throws IOException {
+ InputStream is = getClass().getResourceAsStream(resource);
+ assertNotNull(is);
+ return readStream(is);
+ }
+
+ public String readStream(InputStream is) throws IOException {
+ assertNotNull(is);
+ StringBuilder sb = new StringBuilder();
+ is = new BufferedInputStream(is);
+ int ch;
+ while ((ch = is.read()) != -1) {
+ sb.append((char)ch);
+ }
+ is.close();
+ return sb.toString();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ buildDir = new File(System.getProperty("basedir"), "target");
+ installDir = new File(buildDir, "assembly");
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/standalone/smoketest/src/test/java/org/apache/tuscany/sca/runtime/standalone/smoketest/ProcessDrainer.java b/tags/java/tsss-demo/runtime/standalone/smoketest/src/test/java/org/apache/tuscany/sca/runtime/standalone/smoketest/ProcessDrainer.java
new file mode 100644
index 0000000000..31e697bb23
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/smoketest/src/test/java/org/apache/tuscany/sca/runtime/standalone/smoketest/ProcessDrainer.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.runtime.standalone.smoketest;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Stream drainer used for draining the out and err streams of an external
+ * process to avoid buffer overflow and deadlock.
+ *
+ * @version $Revision$ $Date$
+ *
+ */
+public class ProcessDrainer {
+
+ // Default time out in seconds
+ private static final int DEFAULT_TIMEOUT = 60;
+
+ // Process whose streams are being drained
+ private Process process;
+
+ // Timeout to wait for the extrenal process to whutdown
+ private int timeout = DEFAULT_TIMEOUT;
+
+ // Executor that is scheduling the draining
+ private ExecutorService executor = Executors.newFixedThreadPool(2);
+
+ /*
+ * Initializes the process to drained.
+ */
+ private ProcessDrainer(Process process) {
+ this.process = process;
+ }
+
+ /*
+ * Initializes the process to drained.
+ */
+ private ProcessDrainer(Process process, int timeout) {
+ this.process = process;
+ this.timeout = timeout;
+ }
+
+ /**
+ * Creates a new instance of the stream drainer for the processed.
+ * @param process Process to be drained.
+ * @return An instance of the stream drainer.
+ */
+ public static ProcessDrainer newInstance(Process process) {
+ return new ProcessDrainer(process);
+ }
+
+ /**
+ * Creates a new instance of the stream drainer for the processed.
+ * @param process Process to be drained.
+ * @param timeout Timeout before which teh drainer stops.
+ * @return An instance of the stream drainer.
+ */
+ public static ProcessDrainer newInstance(Process process, int timeout) {
+ return new ProcessDrainer(process, timeout);
+ }
+
+ /**
+ * Starts draining the stream.
+ */
+ public void drain() {
+
+ executor.execute(new StreamDrainer(process.getErrorStream()));
+ executor.execute(new StreamDrainer(process.getInputStream()));
+
+ executor.shutdown();
+ try {
+ executor.awaitTermination(timeout, TimeUnit.SECONDS);
+ } catch (InterruptedException ex) {
+ return;
+ }
+
+ }
+
+ /*
+ * Scheduled stream drainer.
+ */
+ private class StreamDrainer implements Runnable {
+
+ // Stream to be drained
+ private final InputStream inputStream;
+
+ /*
+ * Initializes the stream to drained.
+ */
+ private StreamDrainer(InputStream inputStream) {
+ this.inputStream = inputStream;
+ }
+
+ /*
+ * Starts draing the stream.
+ */
+ public void run() {
+ try {
+ int count = 0;
+ byte[] buffer = new byte[4096];
+ count = inputStream.read(buffer);
+ while (count != -1) {
+ count = inputStream.read(buffer);
+ }
+ } catch (IOException ex) {
+ }
+ }
+
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/standalone/smoketest/src/test/java/org/apache/tuscany/sca/runtime/standalone/smoketest/SmokeTestAssemblyContent.java b/tags/java/tsss-demo/runtime/standalone/smoketest/src/test/java/org/apache/tuscany/sca/runtime/standalone/smoketest/SmokeTestAssemblyContent.java
new file mode 100644
index 0000000000..7ac45268ae
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/smoketest/src/test/java/org/apache/tuscany/sca/runtime/standalone/smoketest/SmokeTestAssemblyContent.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.runtime.standalone.smoketest;
+
+import java.io.File;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SmokeTestAssemblyContent extends CommandTestCase {
+ public void testLegalFilesArePresent() {
+ assertTrue(installDir.exists());
+ assertTrue(installDir.isDirectory());
+ assertTrue(new File(installDir, "LICENSE.txt").exists());
+ assertTrue(new File(installDir, "NOTICE.txt").exists());
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/standalone/smoketest/src/test/java/org/apache/tuscany/sca/runtime/standalone/smoketest/SmokeTestLauncher.java b/tags/java/tsss-demo/runtime/standalone/smoketest/src/test/java/org/apache/tuscany/sca/runtime/standalone/smoketest/SmokeTestLauncher.java
new file mode 100644
index 0000000000..f3e7c3e40c
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/smoketest/src/test/java/org/apache/tuscany/sca/runtime/standalone/smoketest/SmokeTestLauncher.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.runtime.standalone.smoketest;
+
+import java.io.File;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SmokeTestLauncher extends CommandTestCase {
+ private static final String LF = System.getProperty("line.separator");
+ private File launcher;
+ private File testJar;
+
+ public void testLauncherCommandIsPresent() {
+ assertTrue(launcher.exists());
+ }
+
+ public void testLauncherUsage() throws Exception {
+ ProcessBuilder pb = new ProcessBuilder("java", "-jar", launcher.getAbsolutePath());
+ pb.directory(installDir);
+ Process process = pb.start();
+ try {
+ compareOutput(loadResource("LauncherUsage.txt"), process.getErrorStream());
+ ProcessDrainer drainer = ProcessDrainer.newInstance(process);
+ drainer.drain();
+ process.waitFor();
+ assertEquals(1, process.exitValue());
+ } finally {
+ process.destroy();
+ }
+ }
+
+ public void testLauncherWithNoArgs() throws Exception {
+ ProcessBuilder pb = new ProcessBuilder("java", "-jar", launcher.getAbsolutePath(), testJar.getAbsolutePath());
+ pb.directory(installDir);
+ Process process = pb.start();
+ try {
+ compareOutput("No Args" + LF, process.getInputStream());
+ ProcessDrainer drainer = ProcessDrainer.newInstance(process);
+ drainer.drain();
+ process.waitFor();
+ assertEquals(0, process.exitValue());
+ } finally {
+ process.destroy();
+ }
+ }
+
+ public void testReference() throws Exception {
+ ProcessBuilder pb = new ProcessBuilder("java",
+ "-jar",
+ launcher.getAbsolutePath(),
+ testJar.getAbsolutePath(),
+ "testReference");
+ pb.directory(installDir);
+ Process process = pb.start();
+ try {
+ ProcessDrainer drainer = ProcessDrainer.newInstance(process);
+ drainer.drain();
+ process.waitFor();
+ assertEquals(0, process.exitValue());
+ } finally {
+ process.destroy();
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ launcher = new File(installDir, "bin/launcher.jar");
+ testJar = new File(buildDir, "smoketest.jar");
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/standalone/smoketest/src/test/resources/org/apache/tuscany/sca/runtime/standalone/smoketest/LauncherNoComponent.txt b/tags/java/tsss-demo/runtime/standalone/smoketest/src/test/resources/org/apache/tuscany/sca/runtime/standalone/smoketest/LauncherNoComponent.txt
new file mode 100644
index 0000000000..c77e130b05
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/smoketest/src/test/resources/org/apache/tuscany/sca/runtime/standalone/smoketest/LauncherNoComponent.txt
@@ -0,0 +1 @@
+No component found with id "http://no.such.component"
diff --git a/tags/java/tsss-demo/runtime/standalone/smoketest/src/test/resources/org/apache/tuscany/sca/runtime/standalone/smoketest/LauncherUsage.txt b/tags/java/tsss-demo/runtime/standalone/smoketest/src/test/resources/org/apache/tuscany/sca/runtime/standalone/smoketest/LauncherUsage.txt
new file mode 100644
index 0000000000..d2b766f8ae
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/smoketest/src/test/resources/org/apache/tuscany/sca/runtime/standalone/smoketest/LauncherUsage.txt
@@ -0,0 +1 @@
+usage: java [jvm-options] -jar launcher.jar <componentJar> [apparg1, apparg2, ...]
diff --git a/tags/java/tsss-demo/runtime/standalone/standalone-api/LICENSE.txt b/tags/java/tsss-demo/runtime/standalone/standalone-api/LICENSE.txt
new file mode 100644
index 0000000000..0084319535
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/standalone-api/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, serviceDefinition marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/runtime/standalone/standalone-api/NOTICE.txt b/tags/java/tsss-demo/runtime/standalone/standalone-api/NOTICE.txt
new file mode 100644
index 0000000000..d83ebbe236
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/standalone-api/NOTICE.txt
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/runtime/standalone/standalone-api/pom.xml b/tags/java/tsss-demo/runtime/standalone/standalone-api/pom.xml
new file mode 100644
index 0000000000..fa737b4c07
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/standalone-api/pom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca.runtime</groupId>
+ <artifactId>standalone</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.runtime.standalone</groupId>
+ <artifactId>standalone-api</artifactId>
+ <packaging>jar</packaging>
+ <name>Apache Tuscany Standalone Runtime</name>
+ <description>Code to run Tuscany in a standalone application.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-host-api</artifactId>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/tags/java/tsss-demo/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/DirectoryHelper.java b/tags/java/tsss-demo/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/DirectoryHelper.java
new file mode 100644
index 0000000000..abacda879b
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/DirectoryHelper.java
@@ -0,0 +1,303 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.runtime.standalone;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Properties;
+import java.util.jar.JarFile;
+
+import org.apache.tuscany.host.runtime.TuscanyRuntime;
+
+/**
+ * Utility class for installation directory related operations.
+ *
+ * @version $Revision$ $Date$
+ */
+public final class DirectoryHelper {
+
+ /**
+ * Installation directory system property name.
+ */
+ private static final String INSTALL_DIRECTORY_PROPERTY = "tuscany.installDir";
+
+ private DirectoryHelper() {
+ }
+
+ /**
+ * Gets the installation directory based on the location of a class file.
+ * If the system property <code>tuscany.installDir</code> is set then its value is used as the
+ * location of the installation directory. Otherwise, we assume we are running from an
+ * executable jar containing the supplied class and the installation directory is assumed to
+ * be the parent of the directory containing that jar.
+ *
+ * @param clazz the class to use as a way to find the executable jar
+ * @return directory where tuscany standalone server is installed.
+ * @throws IllegalArgumentException if the property is set but its value is not an existing directory
+ * @throws IllegalStateException if the location could not be determined from the location of the class file
+ */
+ public static File getInstallDirectory(Class clazz) throws IllegalStateException, IllegalArgumentException {
+
+ String installDirectoryPath = System.getProperty(INSTALL_DIRECTORY_PROPERTY);
+
+ if (installDirectoryPath != null) {
+ File installDirectory = new File(installDirectoryPath);
+ if (!installDirectory.exists()) {
+ throw new IllegalArgumentException(INSTALL_DIRECTORY_PROPERTY
+ + " property does not refer to an existing directory: " + installDirectory);
+ }
+ return installDirectory;
+ }
+
+ // get the name of the Class's bytecode
+ String name = clazz.getName();
+ int last = name.lastIndexOf('.');
+ if (last != -1) {
+ name = name.substring(last + 1);
+ }
+ name = name + ".class";
+
+ // get location of the bytecode - should be a jar: URL
+ URL url = clazz.getResource(name);
+ if (url == null) {
+ throw new IllegalStateException("Unable to get location of bytecode resource " + name);
+ }
+
+ String jarLocation = url.toString();
+ if (!jarLocation.startsWith("jar:")) {
+ throw new IllegalStateException("Must be run from a jar: " + url);
+ }
+
+ // extract the location of thr jar from the resource URL
+ jarLocation = jarLocation.substring(4, jarLocation.lastIndexOf("!/"));
+ if (!jarLocation.startsWith("file:")) {
+ throw new IllegalStateException("Must be run from a local filesystem: " + jarLocation);
+ }
+
+ File jarFile = new File(URI.create(jarLocation));
+ return jarFile.getParentFile().getParentFile();
+ }
+
+ /**
+ * Get the directory associated with a runtime profile.
+ * If the system property <code>tuscany.profileDir.${profileName}</code> is set then its value
+ * is used as the value for the profile directory. Otherwise, the directory ${installDir}/profiles/${profileName}
+ * is used.
+ *
+ * @param installDir the installation directory
+ * @param profileName tha name of the profile
+ * @return the directory for the the specified profile
+ * @throws FileNotFoundException if the directory does not exist
+ */
+ public static File getProfileDirectory(File installDir, String profileName) throws FileNotFoundException {
+ String propName = "tuscany.profileDir." + profileName;
+ String profilePath = System.getProperty(propName);
+ File profileDir;
+ if (profilePath != null) {
+ profileDir = new File(profilePath);
+ } else {
+ profileDir = new File(new File(installDir, "profiles"), profileName);
+ }
+
+ if (!profileDir.isDirectory()) {
+ throw new FileNotFoundException("Unable to locate profile directory: " + profileDir.toString());
+ }
+ return profileDir;
+ }
+
+ /**
+ * Gets the boot directory where all the boot libraries are stored. This
+ * is expected to be a directory named <code>boot</code> under the install
+ * directory.
+ *
+ * @param installDirectory Tuscany install directory.
+ * @param bootPath Boot path for the runtime.
+ * @return Tuscany boot directory.
+ */
+ public static File getBootDirectory(File installDirectory, String bootPath) {
+
+ File bootDirectory = new File(installDirectory, bootPath);
+ if (!bootDirectory.exists()) {
+ throw new IllegalStateException("Boot directory doesn't exist: " + bootDirectory.getAbsolutePath());
+ }
+ return bootDirectory;
+
+ }
+
+ /**
+ * Gets the boot directory for the specified profile.
+ * If the bootPath is not null then it is used to specify the location of the boot directory
+ * relative to the profile directory. Otherwise, if there is a directory named "boot" relative
+ * to the profile or install directory then it is used.
+ *
+ * @param installDir the installation directory
+ * @param profileDir the profile directory
+ * @param bootPath the path to the boot directory
+ * @return the boot directory
+ * @throws FileNotFoundException if the boot directory does not exist
+ */
+ public static File getBootDirectory(File installDir, File profileDir, String bootPath)
+ throws FileNotFoundException {
+ File bootDir;
+ if (bootPath != null) {
+ bootDir = new File(profileDir, bootPath);
+ } else {
+ bootDir = new File(profileDir, "boot");
+ if (!bootDir.isDirectory()) {
+ bootDir = new File(installDir, "boot");
+ }
+ }
+ if (!bootDir.isDirectory()) {
+ throw new FileNotFoundException("Unable to locate boot directory: " + bootDir);
+ }
+ return bootDir;
+ }
+
+ /**
+ * Create a classloader from all the jar files or subdirectories in a directory.
+ * The classpath for the returned classloader will comprise all jar files and subdirectories
+ * of the supplied directory. Hidden files and those that do not contain a valid manifest will
+ * be silently ignored.
+ *
+ * @param parent the parent for the new classloader
+ * @param directory the directory to scan
+ * @return a classloader whose classpath includes all jar files and subdirectories of the supplied directory
+ */
+ public static ClassLoader createClassLoader(ClassLoader parent, File directory) {
+ File[] jars = directory.listFiles(new FileFilter() {
+ public boolean accept(File file) {
+ if (file.isHidden()) {
+ return false;
+ }
+ if (file.isDirectory()) {
+ return true;
+ }
+ try {
+ JarFile jar = new JarFile(file);
+ return jar.getManifest() != null;
+ } catch (IOException e) {
+ return false;
+ }
+ }
+ });
+
+ URL[] urls = new URL[jars.length];
+ for (int i = 0; i < jars.length; i++) {
+ try {
+ urls[i] = jars[i].toURI().toURL();
+ } catch (MalformedURLException e) {
+ // toURI should have escaped the URL
+ throw new AssertionError();
+ }
+ }
+
+ return new URLClassLoader(urls, parent);
+ }
+
+ /**
+ * Load properties from the specified file.
+ * If the file does not exist then an empty properties object is returned.
+ *
+ * @param propFile the file to load from
+ * @param defaults defaults for the properties
+ * @return a Properties object loaded from the file
+ * @throws IOException if there was a problem loading the properties
+ */
+ public static Properties loadProperties(File propFile, Properties defaults) throws IOException {
+ Properties props = defaults == null ? new Properties() : new Properties(defaults);
+ FileInputStream is;
+ try {
+ is = new FileInputStream(propFile);
+ } catch (FileNotFoundException e) {
+ return props;
+ }
+ try {
+ props.load(is);
+ return props;
+ } finally {
+ is.close();
+ }
+ }
+
+ /**
+ * Convert a File to a URL. Equivalent to file.toURI().toURL()
+ *
+ * @param file the file to convert
+ * @return the URL for the File
+ */
+ public static URL toURL(File file) {
+ try {
+ return file.toURI().toURL();
+ } catch (MalformedURLException e) {
+ // toURI should have escaped this
+ throw new AssertionError();
+ }
+ }
+
+ public static StandaloneRuntimeInfo createRuntimeInfo(String defaultProfile, Class<?> markerClass) throws IOException {
+ // get profile to use, defaulting to "launcher"
+ String profile = System.getProperty("tuscany.profile", defaultProfile);
+
+ File installDir = getInstallDirectory(markerClass);
+ File profileDir = getProfileDirectory(installDir, profile);
+
+ // load properties for this runtime
+ File propFile = new File(profileDir, "etc/runtime.properties");
+ Properties props = loadProperties(propFile, System.getProperties());
+
+ // online unless the offline property is set
+ boolean online = !Boolean.parseBoolean(props.getProperty("offline", "false"));
+
+ return new StandaloneRuntimeInfoImpl(null, profile, installDir, profileDir, null, online, props);
+
+ }
+
+ public static TuscanyRuntime createRuntime(StandaloneRuntimeInfo runtimeInfo) throws Exception {
+ File installDir = runtimeInfo.getInstallDirectory();
+ File profileDir = runtimeInfo.getProfileDirectory();
+ URL profileURL = toURL(profileDir);
+ ClassLoader hostClassLoader = ClassLoader.getSystemClassLoader();
+
+ // create the classloader for booting the runtime
+ String bootPath = runtimeInfo.getProperty("tuscany.bootDir", null);
+ File bootDir = getBootDirectory(installDir, profileDir, bootPath);
+ ClassLoader bootClassLoader = createClassLoader(hostClassLoader, bootDir);
+
+ // locate the system SCDL
+ URL systemSCDL = new URL(profileURL, runtimeInfo.getProperty("tuscany.systemSCDL", "system.scdl"));
+
+ // locate the implementation
+ String className = runtimeInfo.getProperty("tuscany.runtimeClass",
+ "org.apache.tuscany.runtime.standalone.host.StandaloneRuntimeImpl");
+ Class<?> implClass = Class.forName(className, true, bootClassLoader);
+
+ TuscanyRuntime runtime = (TuscanyRuntime) implClass.newInstance();
+ runtime.setHostClassLoader(hostClassLoader);
+ runtime.setSystemScdl(systemSCDL);
+ runtime.setRuntimeInfo(runtimeInfo);
+ return runtime;
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/StandaloneRuntime.java b/tags/java/tsss-demo/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/StandaloneRuntime.java
new file mode 100644
index 0000000000..0ccb26a7dd
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/StandaloneRuntime.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.runtime.standalone;
+
+import java.net.URL;
+
+import org.apache.tuscany.host.runtime.TuscanyRuntime;
+
+/**
+ * Extends the tuscany runtime to add the behavious to deploy an
+ * application SCDL.
+ *
+ * @version $Revision$ $Date$
+ *
+ */
+public interface StandaloneRuntime extends TuscanyRuntime<StandaloneRuntimeInfo> {
+
+ /**
+ * Deploys the specified application SCDL and runs the lauched component within the deployed composite.
+ *
+ * @param applicationScdl Application SCDL that implements the composite.
+ * @param applicationClassLoader Classloader used to deploy the composite.
+ * @param args Arguments to be passed to the lauched component.
+ * @deprecated This is a hack for deployment and should be removed.
+ */
+ int deployAndRun(URL applicationScdl, ClassLoader applicationClassLoader, String[] args) throws Exception;
+
+}
diff --git a/tags/java/tsss-demo/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/StandaloneRuntimeInfo.java b/tags/java/tsss-demo/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/StandaloneRuntimeInfo.java
new file mode 100644
index 0000000000..8e5e18b198
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/StandaloneRuntimeInfo.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.runtime.standalone;
+
+import java.io.File;
+import java.net.URI;
+
+import org.apache.tuscany.host.RuntimeInfo;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface StandaloneRuntimeInfo extends RuntimeInfo {
+
+ URI STANDALONE_COMPONENT_URI = URI.create("sca://StandaloneRuntimeInfo");
+
+ /**
+ * Return the directory where the standalone distribution was installed.
+ *
+ * @return the directory where the standalone distribution was installed
+ */
+ File getInstallDirectory();
+
+ /**
+ * Returns the name of this runtime's profile.
+ *
+ * @return the name of this runtime's profile
+ */
+ String getProfileName();
+
+ /**
+ * Returns the directory containing this runtime's profile.
+ *
+ * @return the directory containing this runtime's profile
+ */
+ File getProfileDirectory();
+
+ /**
+ * Return the value of the named property.
+ *
+ * @param name the name of the property
+ * @param defaultValue default value to return if the property is not defined
+ * @return the value of the named property
+ */
+ String getProperty(String name, String defaultValue);
+}
diff --git a/tags/java/tsss-demo/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/StandaloneRuntimeInfoImpl.java b/tags/java/tsss-demo/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/StandaloneRuntimeInfoImpl.java
new file mode 100644
index 0000000000..bf1e92b407
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/StandaloneRuntimeInfoImpl.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.runtime.standalone;
+
+import java.io.File;
+import java.net.URI;
+import java.util.Properties;
+
+import org.apache.tuscany.host.AbstractRuntimeInfo;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class StandaloneRuntimeInfoImpl extends AbstractRuntimeInfo implements StandaloneRuntimeInfo {
+ private final String profileName;
+ private final File profileDirectory;
+ private final File installDirectory;
+ private final Properties properties;
+
+ /**
+ * Initializes the base URL, install directory, application root directory and
+ * online mode.
+ *
+ * @param domain the SCA domain this runtime belongs to
+ * @param profileName the runtime's profile name
+ * @param installDirectory directory containing the standalone installation
+ * @param profileDirectory directory containing this runtime's profile
+ * @param applicationRootDirectory Application root directory.
+ * @param online true if this runtime should consider itself online
+ * @param properties properties for this runtime
+ */
+ public StandaloneRuntimeInfoImpl(final URI domain,
+ final String profileName,
+ final File installDirectory,
+ final File profileDirectory,
+ final File applicationRootDirectory,
+ final boolean online,
+ final Properties properties) {
+ super(domain, applicationRootDirectory, DirectoryHelper.toURL(installDirectory), online, profileName);
+ this.profileName = profileName;
+ this.profileDirectory = profileDirectory;
+ this.properties = properties;
+ this.installDirectory = installDirectory;
+
+ }
+
+ public String getProfileName() {
+ return profileName;
+ }
+
+ public File getProfileDirectory() {
+ return profileDirectory;
+ }
+
+ public File getInstallDirectory() {
+ return installDirectory;
+ }
+
+ public String getProperty(String name, String defaultValue) {
+ return properties.getProperty(name, defaultValue);
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/standalone/standalone-host/LICENSE.txt b/tags/java/tsss-demo/runtime/standalone/standalone-host/LICENSE.txt
new file mode 100644
index 0000000000..0084319535
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/standalone-host/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, serviceDefinition marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/runtime/standalone/standalone-host/NOTICE.txt b/tags/java/tsss-demo/runtime/standalone/standalone-host/NOTICE.txt
new file mode 100644
index 0000000000..d83ebbe236
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/standalone-host/NOTICE.txt
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/runtime/standalone/standalone-host/pom.xml b/tags/java/tsss-demo/runtime/standalone/standalone-host/pom.xml
new file mode 100644
index 0000000000..f8ef044ab6
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/standalone-host/pom.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca.runtime</groupId>
+ <artifactId>standalone</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.runtime.standalone</groupId>
+ <artifactId>standalone-host</artifactId>
+ <packaging>jar</packaging>
+ <name>Apache Tuscany Standalone Runtime Host</name>
+ <description>Host code to support a standalone runtime</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.runtime.standalone</groupId>
+ <artifactId>standalone-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.runtime.services</groupId>
+ <artifactId>maven</artifactId>
+ <version>${project.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/DirectoryScanExtender.java b/tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/DirectoryScanExtender.java
new file mode 100644
index 0000000000..038df9e3b9
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/DirectoryScanExtender.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.runtime.standalone.host;
+
+import java.io.File;
+
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.loader.IllegalSCDLNameException;
+import org.apache.tuscany.spi.services.VoidService;
+
+import org.apache.tuscany.core.services.extension.AbstractExtensionDeployer;
+import org.apache.tuscany.runtime.standalone.StandaloneRuntimeInfo;
+
+/**
+ * Service that extends the runtime by loading composites located in a directory.
+ *
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+public class DirectoryScanExtender extends AbstractExtensionDeployer implements VoidService {
+ private final StandaloneRuntimeInfo runtimeInfo;
+ private final String path;
+
+ public DirectoryScanExtender(@Reference StandaloneRuntimeInfo runtimeInfo,
+ @Property(name = "path")String path) {
+ this.runtimeInfo = runtimeInfo;
+ this.path = path;
+ }
+
+ @Init
+ public void init() throws IllegalSCDLNameException {
+ assert runtimeInfo != null;
+ File extensionDir = new File(runtimeInfo.getInstallDirectory(), path);
+ if (!extensionDir.isDirectory()) {
+ // we don't have an extension directory, there's nothing to do
+ return;
+ }
+
+ File[] files = extensionDir.listFiles();
+ for (File file : files) {
+ deployExtension(file);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/StandaloneRuntimeImpl.java b/tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/StandaloneRuntimeImpl.java
new file mode 100644
index 0000000000..23811743e4
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/StandaloneRuntimeImpl.java
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.runtime.standalone.host;
+
+import java.lang.reflect.InvocationTargetException;
+import java.net.URI;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.tuscany.api.annotation.LogLevel;
+import org.apache.tuscany.core.implementation.PojoWorkContextTunnel;
+import org.apache.tuscany.core.monitor.JavaLoggingMonitorFactory;
+import org.apache.tuscany.core.runtime.AbstractRuntime;
+import org.apache.tuscany.core.component.SimpleWorkContext;
+import org.apache.tuscany.runtime.standalone.StandaloneRuntime;
+import org.apache.tuscany.runtime.standalone.StandaloneRuntimeInfo;
+import org.apache.tuscany.runtime.standalone.host.implementation.launched.Launched;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.CompositeComponentType;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class StandaloneRuntimeImpl extends AbstractRuntime<StandaloneRuntimeInfo> implements StandaloneRuntime {
+ JavaLoggingMonitorFactory monitorFactory;
+ StandaloneMonitor monitor;
+
+ public StandaloneRuntimeImpl() {
+ super(StandaloneRuntimeInfo.class);
+ monitorFactory = new JavaLoggingMonitorFactory();
+ setMonitorFactory(monitorFactory);
+ monitor = monitorFactory.getMonitor(StandaloneMonitor.class);
+ }
+
+ /**
+ * Deploys the specified application SCDL and runs the lauched component within the deployed composite.
+ *
+ * @param applicationScdl Application SCDL that implements the composite.
+ * @param applicationClassLoader Classloader used to deploy the composite.
+ * @param args Arguments to be passed to the lauched component.
+ * @deprecated This is a hack for deployment and should be removed.
+ */
+ public int deployAndRun(URL applicationScdl, ClassLoader applicationClassLoader, String[] args) throws Exception {
+
+ URI compositeUri = new URI("/test/composite");
+ URI compositeBase = new URI("/test/composite/");
+
+ CompositeImplementation impl = new CompositeImplementation();
+ impl.setScdlLocation(applicationScdl);
+ impl.setClassLoader(applicationClassLoader);
+
+ ComponentDefinition<CompositeImplementation> definition =
+ new ComponentDefinition<CompositeImplementation>(compositeUri, impl);
+ try {
+ Collection<Component> components = getDeployer().deploy(null, definition);
+ for (Component component : components) {
+ component.start();
+ }
+ ScopeRegistry scopeRegistry = getScopeRegistry();
+ ScopeContainer<URI> container = scopeRegistry.getScopeContainer(Scope.COMPOSITE);
+ container.startContext(compositeUri, compositeUri);
+ getWorkContext().setIdentifier(Scope.COMPOSITE, compositeUri);
+ WorkContext workContext = new SimpleWorkContext();
+ workContext.setIdentifier(Scope.COMPOSITE, compositeUri);
+ PojoWorkContextTunnel.setThreadWorkContext(workContext);
+ try {
+ return run(impl, args, compositeBase, workContext);
+ } finally {
+ container.stopContext(compositeUri);
+ getWorkContext().setIdentifier(Scope.COMPOSITE, null);
+ }
+ } catch (Exception e) {
+ monitor.runError(e);
+ }
+ return -1;
+
+ }
+
+ private int run(CompositeImplementation impl, String[] args, URI compositeUri, WorkContext workContext) throws Exception {
+ CompositeComponentType<?, ?, ?> componentType = impl.getComponentType();
+ Map<String, ComponentDefinition<? extends Implementation<?>>> components = componentType.getComponents();
+ for (Map.Entry<String, ComponentDefinition<? extends Implementation<?>>> entry : components.entrySet()) {
+ String name = entry.getKey();
+ ComponentDefinition<? extends Implementation<?>> launchedDefinition = entry.getValue();
+ Implementation implementation = launchedDefinition.getImplementation();
+ if (implementation.getClass().isAssignableFrom(Launched.class)) {
+ return run(compositeUri.resolve(name), implementation, args, workContext);
+ }
+ }
+ return -1;
+ }
+
+ private int run(URI componentUri, Implementation implementation, String[] args, WorkContext workContext)
+ throws TargetInvokerCreationException, InvocationTargetException {
+ Launched launched = (Launched) implementation;
+ PojoComponentType launchedType = launched.getComponentType();
+ Map services = launchedType.getServices();
+ JavaMappedService testService = (JavaMappedService) services.get("main");
+ Operation<?> operation = testService.getServiceContract().getOperations().get("main");
+ Component component = getComponentManager().getComponent(componentUri);
+ TargetInvoker targetInvoker = component.createTargetInvoker("main", operation);
+ Object result = targetInvoker.invokeTarget(new Object[]{args}, TargetInvoker.NONE, workContext);
+ try {
+ return int.class.cast(result);
+ } catch (ClassCastException e) {
+ return 0;
+ }
+ }
+
+ public interface StandaloneMonitor {
+ @LogLevel("SEVERE")
+ void runError(Exception e);
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/Launched.java b/tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/Launched.java
new file mode 100644
index 0000000000..93771ee942
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/Launched.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.runtime.standalone.host.implementation.launched;
+
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.model.AtomicImplementation;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class Launched extends AtomicImplementation<PojoComponentType> {
+ private String className;
+ private String factoryName;
+
+ public Launched(String className, String factoryName) {
+ this.className = className;
+ this.factoryName = factoryName;
+ }
+
+ public String getClassName() {
+ return className;
+ }
+
+ public void setClassName(String className) {
+ this.className = className;
+ }
+
+ public String getFactoryName() {
+ return factoryName;
+ }
+
+ public void setFactoryName(String factoryName) {
+ this.factoryName = factoryName;
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedComponentBuilder.java b/tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedComponentBuilder.java
new file mode 100644
index 0000000000..dfffc2187c
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedComponentBuilder.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.runtime.standalone.host.implementation.launched;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.builder.BuilderConfigException;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentBuilderExtension;
+import org.apache.tuscany.spi.host.ResourceHost;
+import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.Resource;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.PropertyValue;
+
+import org.apache.tuscany.core.implementation.PojoConfiguration;
+import org.apache.tuscany.core.implementation.java.JavaAtomicComponent;
+import org.apache.tuscany.core.injection.MethodEventInvoker;
+import org.apache.tuscany.core.injection.PojoObjectFactory;
+import org.apache.tuscany.core.injection.ResourceObjectFactory;
+
+/**
+ * @version $Revsion$ $Date$
+ * <p/>
+ * TODO This is a straight copy from the JUnit component builder
+ */
+public class LaunchedComponentBuilder extends ComponentBuilderExtension<Launched> {
+
+ private ResourceHost host;
+
+ @Reference
+ public void setHost(ResourceHost host) {
+ this.host = host;
+ }
+
+ @Override
+ protected Class<Launched> getImplementationType() {
+ return Launched.class;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public Component build(ComponentDefinition<Launched> definition, DeploymentContext deployment)
+ throws BuilderConfigException {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> componentType =
+ definition.getImplementation().getComponentType();
+ Class<?> implClass = componentType.getImplClass();
+
+ PojoConfiguration configuration = new PojoConfiguration();
+ if (definition.getInitLevel() != null) {
+ configuration.setInitLevel(definition.getInitLevel());
+ } else {
+ configuration.setInitLevel(componentType.getInitLevel());
+ }
+ if (componentType.getMaxAge() > 0) {
+ configuration.setMaxAge(componentType.getMaxAge());
+ } else if (componentType.getMaxIdleTime() > 0) {
+ configuration.setMaxIdleTime(componentType.getMaxIdleTime());
+ }
+ Method initMethod = componentType.getInitMethod();
+ if (initMethod != null) {
+ configuration.setInitInvoker(new MethodEventInvoker(initMethod));
+ }
+ Method destroyMethod = componentType.getDestroyMethod();
+ if (destroyMethod != null) {
+ configuration.setDestroyInvoker(new MethodEventInvoker(destroyMethod));
+ }
+
+ configuration.setProxyService(proxyService);
+ configuration.setWorkContext(workContext);
+ configuration.setImplementationClass(implClass);
+ configuration.setGroupId(deployment.getGroupId());
+
+ // setup property injection sites
+ for (JavaMappedProperty<?> property : componentType.getProperties().values()) {
+ configuration.addPropertySite(property.getName(), property.getMember());
+ }
+
+ // setup reference injection sites
+ for (JavaMappedReference reference : componentType.getReferences().values()) {
+ Member member = reference.getMember();
+ if (member != null) {
+ // could be null if the reference is mapped to a constructor
+ configuration.addReferenceSite(reference.getUri().getFragment(), member);
+ }
+ }
+
+ for (Resource resource : componentType.getResources().values()) {
+ Member member = resource.getMember();
+ if (member != null) {
+ // could be null if the resource is mapped to a constructor
+ configuration.addResourceSite(resource.getName(), member);
+ }
+ }
+
+ // setup constructor injection
+ ConstructorDefinition<?> ctorDef = componentType.getConstructorDefinition();
+ Constructor<?> constr = ctorDef.getConstructor();
+ PojoObjectFactory<?> instanceFactory = new PojoObjectFactory(constr);
+ configuration.setInstanceFactory(instanceFactory);
+ configuration.getConstructorParamNames().addAll(ctorDef.getInjectionNames());
+ for (Class<?> clazz : constr.getParameterTypes()) {
+ configuration.addConstructorParamType(clazz);
+ }
+ configuration.setName(definition.getUri());
+ JavaAtomicComponent component = new JavaAtomicComponent(configuration);
+
+ // handle properties
+ handleProperties(definition, component);
+
+ // handle resources
+ handleResources(componentType, component);
+
+ handleCallbackSites(componentType, configuration);
+
+ if (componentType.getConversationIDMember() != null) {
+ component.addConversationIDFactory(componentType.getConversationIDMember());
+ }
+
+ return component;
+ }
+
+ private void handleCallbackSites(
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> componentType,
+ PojoConfiguration configuration) {
+ for (JavaMappedService service : componentType.getServices().values()) {
+ // setup callback injection sites
+ if (service.getCallbackReferenceName() != null) {
+ // Only if there is a callback reference in the service
+ configuration.addCallbackSite(service.getCallbackReferenceName(), service.getCallbackMember());
+ }
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private void handleResources(
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> componentType,
+ JavaAtomicComponent component) {
+
+ for (Resource resource : componentType.getResources().values()) {
+ ObjectFactory<?> objectFactory = resource.getObjectFactory();
+ if (objectFactory != null) {
+ component.addResourceFactory(resource.getName(), objectFactory);
+ } else {
+ String name = resource.getName();
+ boolean optional = resource.isOptional();
+ Class<Object> type = (Class<Object>) resource.getType();
+ ResourceObjectFactory<Object> factory;
+ String mappedName = resource.getMappedName();
+ if (mappedName == null) {
+ // by type
+ factory = new ResourceObjectFactory<Object>(type, optional, host);
+ } else {
+ factory = new ResourceObjectFactory<Object>(type, mappedName, optional, host);
+ }
+ component.addResourceFactory(name, factory);
+ }
+ }
+ }
+
+ private void handleProperties(ComponentDefinition<Launched> definition, JavaAtomicComponent component) {
+ for (PropertyValue<?> property : definition.getPropertyValues().values()) {
+ ObjectFactory<?> factory = property.getValueFactory();
+ if (factory != null) {
+ component.addPropertyFactory(property.getName(), factory);
+ }
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedComponentTypeLoader.java b/tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedComponentTypeLoader.java
new file mode 100644
index 0000000000..c3575ae95b
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedComponentTypeLoader.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.runtime.standalone.host.implementation.launched;
+
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentTypeLoaderExtension;
+import org.apache.tuscany.spi.implementation.java.IntrospectionRegistry;
+import org.apache.tuscany.spi.implementation.java.Introspector;
+import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
+import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
+import org.apache.tuscany.spi.implementation.java.JavaMappedService;
+import org.apache.tuscany.spi.implementation.java.PojoComponentType;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.MissingResourceException;
+import org.apache.tuscany.spi.model.DataType;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class LaunchedComponentTypeLoader extends ComponentTypeLoaderExtension<Launched> {
+ private static final URI SERVICE_NAME = URI.create("#main");
+ private Introspector introspector;
+
+ public LaunchedComponentTypeLoader(@Reference LoaderRegistry loaderRegistry,
+ @Reference IntrospectionRegistry introspector) {
+ super(loaderRegistry);
+ this.introspector = introspector;
+ }
+
+ @Override
+ protected Class<Launched> getImplementationClass() {
+ return Launched.class;
+ }
+
+ public void load(
+ Launched implementation,
+ DeploymentContext deploymentContext) throws LoaderException {
+ String className = implementation.getClassName();
+ Class<?> implClass;
+ try {
+ implClass = deploymentContext.getClassLoader().loadClass(className);
+ } catch (ClassNotFoundException e) {
+ throw new MissingResourceException(className, e);
+ }
+ PojoComponentType componentType = loadByIntrospection(implementation, deploymentContext, implClass);
+ implementation.setComponentType(componentType);
+ }
+
+ protected PojoComponentType loadByIntrospection(
+ Launched implementation,
+ DeploymentContext deploymentContext,
+ Class<?> implClass) throws ProcessingException {
+ PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> componentType =
+ new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(implClass);
+ introspector.introspect(implClass, componentType, deploymentContext);
+
+ ServiceContract launchedContract = generateContract(implClass);
+ JavaMappedService testService = new JavaMappedService(SERVICE_NAME, launchedContract, false);
+ componentType.add(testService);
+ return componentType;
+ }
+
+ private static final DataType<List<DataType<Type>>> INPUT_TYPE;
+ private static final DataType<Type> OUTPUT_TYPE;
+ private static final List<DataType<Type>> FAULT_TYPE;
+
+ static {
+ List<DataType<Type>> paramDataTypes = new ArrayList<DataType<Type>>();
+ //noinspection unchecked
+ paramDataTypes.add(new DataType(null, String[].class, String[].class));
+ INPUT_TYPE = new DataType<List<DataType<Type>>>("idl:input", Object[].class, paramDataTypes);
+ OUTPUT_TYPE = new DataType<Type>(null, Object.class, Object.class);
+ FAULT_TYPE = Collections.emptyList();
+ }
+
+ protected ServiceContract generateContract(Class<?> implClass) {
+ Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>();
+ Operation<Type> operation = new Operation<Type>("main", INPUT_TYPE, OUTPUT_TYPE, FAULT_TYPE);
+ operations.put("main", operation);
+ return new LaunchedServiceContract(operations);
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedLoader.java b/tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedLoader.java
new file mode 100644
index 0000000000..7718e02838
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedLoader.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.runtime.standalone.host.implementation.launched;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.ModelObject;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class LaunchedLoader extends LoaderExtension<Launched> {
+ private static final QName LAUNCHED = new QName("http://tuscany.apache.org/xmlns/sca/2.0-alpha", "launched");
+
+ public LaunchedLoader(@Reference LoaderRegistry registry) {
+ super(registry);
+ }
+
+ public QName getXMLType() {
+ return LAUNCHED;
+ }
+
+ public Launched load(
+ ModelObject object,
+ XMLStreamReader reader,
+ DeploymentContext deploymentContext) throws XMLStreamException, LoaderException {
+ String className = reader.getAttributeValue(null, "class");
+ String factoryName = reader.getAttributeValue(null, "factory");
+ return new Launched(className, factoryName);
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedServiceContract.java b/tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedServiceContract.java
new file mode 100644
index 0000000000..820093917a
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/implementation/launched/LaunchedServiceContract.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.runtime.standalone.host.implementation.launched;
+
+import java.lang.reflect.Type;
+import java.util.Map;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+/**
+ * @version $Revison$ $Date$
+ *
+ */
+public class LaunchedServiceContract extends ServiceContract<Type> {
+
+ public LaunchedServiceContract(Map<String, Operation<Type>> operations) {
+ setOperations(operations);
+ }
+}
+
diff --git a/tags/java/tsss-demo/runtime/webapp/plugin.war/LICENSE.txt b/tags/java/tsss-demo/runtime/webapp/plugin.war/LICENSE.txt
new file mode 100644
index 0000000000..9601ead3f6
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/plugin.war/LICENSE.txt
@@ -0,0 +1,1407 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+APACHE TUSCANY SUBCOMPONENTS:
+
+The Apache Tuscany distribution includes a number of subcomponents with
+separate copyright notices and license terms. Your use of the source
+code for the these subcomponents is subject to the terms and
+conditions of the following licenses.
+
+===============================================================================
+
+For the Eclipse Modeling Framework component and the Celtix binding:
+
+Eclipse Public License - v 1.0
+
+THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
+PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF
+THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
+
+1. DEFINITIONS
+
+"Contribution" means:
+
+a) in the case of the initial Contributor, the initial code and
+documentation distributed under this Agreement, and
+b) in the case of each subsequent Contributor:
+
+i) changes to the Program, and
+
+ii) additions to the Program;
+
+where such changes and/or additions to the Program originate from and
+are distributed by that particular Contributor. A Contribution
+'originates' from a Contributor if it was added to the Program by such
+Contributor itself or anyone acting on such Contributor's behalf.
+Contributions do not include additions to the Program which: (i) are
+separate modules of software distributed in conjunction with the
+Program under their own license agreement, and (ii) are not derivative
+works of the Program.
+
+"Contributor" means any person or entity that distributes the Program.
+
+"Licensed Patents " mean patent claims licensable by a Contributor
+which are necessarily infringed by the use or sale of its Contribution
+alone or when combined with the Program.
+
+"Program" means the Contributions distributed in accordance with this
+Agreement.
+
+"Recipient" means anyone who receives the Program under this
+Agreement, including all Contributors.
+
+2. GRANT OF RIGHTS
+
+a) Subject to the terms of this Agreement, each Contributor hereby
+grants Recipient a non-exclusive, worldwide, royalty-free copyright
+license to reproduce, prepare derivative works of, publicly display,
+publicly perform, distribute and sublicense the Contribution of such
+Contributor, if any, and such derivative works, in source code and
+object code form.
+
+b) Subject to the terms of this Agreement, each Contributor hereby
+grants Recipient a non-exclusive, worldwide, royalty-free patent
+license under Licensed Patents to make, use, sell, offer to sell,
+import and otherwise transfer the Contribution of such Contributor, if
+any, in source code and object code form. This patent license shall
+apply to the combination of the Contribution and the Program if, at
+the time the Contribution is added by the Contributor, such addition
+of the Contribution causes such combination to be covered by the
+Licensed Patents. The patent license shall not apply to any other
+combinations which include the Contribution. No hardware per se is
+licensed hereunder.
+
+c) Recipient understands that although each Contributor grants the
+licenses to its Contributions set forth herein, no assurances are
+provided by any Contributor that the Program does not infringe the
+patent or other intellectual property rights of any other entity. Each
+Contributor disclaims any liability to Recipient for claims brought by
+any other entity based on infringement of intellectual property rights
+or otherwise. As a condition to exercising the rights and licenses
+granted hereunder, each Recipient hereby assumes sole responsibility
+to secure any other intellectual property rights needed, if any. For
+example, if a third party patent license is required to allow
+Recipient to distribute the Program, it is Recipient's responsibility
+to acquire that license before distributing the Program.
+
+d) Each Contributor represents that to its knowledge it has sufficient
+copyright rights in its Contribution, if any, to grant the copyright
+license set forth in this Agreement.
+
+3. REQUIREMENTS
+
+A Contributor may choose to distribute the Program in object code form
+under its own license agreement, provided that:
+
+a) it complies with the terms and conditions of this Agreement; and
+
+b) its license agreement:
+
+i) effectively disclaims on behalf of all Contributors all warranties
+and conditions, express and implied, including warranties or
+conditions of title and non-infringement, and implied warranties or
+conditions of merchantability and fitness for a particular purpose;
+
+ii) effectively excludes on behalf of all Contributors all liability
+for damages, including direct, indirect, special, incidental and
+consequential damages, such as lost profits;
+
+iii) states that any provisions which differ from this Agreement are
+offered by that Contributor alone and not by any other party; and
+
+iv) states that source code for the Program is available from such
+Contributor, and informs licensees how to obtain it in a reasonable
+manner on or through a medium customarily used for software exchange.
+
+When the Program is made available in source code form:
+
+a) it must be made available under this Agreement; and
+
+b) a copy of this Agreement must be included with each copy of the
+Program.
+
+Contributors may not remove or alter any copyright notices contained
+within the Program.
+
+Each Contributor must identify itself as the originator of its
+Contribution, if any, in a manner that reasonably allows subsequent
+Recipients to identify the originator of the Contribution.
+
+4. COMMERCIAL DISTRIBUTION
+
+Commercial distributors of software may accept certain
+responsibilities with respect to end users, business partners and the
+like. While this license is intended to facilitate the commercial use
+of the Program, the Contributor who includes the Program in a
+commercial product offering should do so in a manner which does not
+create potential liability for other Contributors. Therefore, if a
+Contributor includes the Program in a commercial product offering,
+such Contributor ("Commercial Contributor") hereby agrees to defend
+and indemnify every other Contributor ("Indemnified Contributor")
+against any losses, damages and costs (collectively "Losses") arising
+from claims, lawsuits and other legal actions brought by a third party
+against the Indemnified Contributor to the extent caused by the acts
+or omissions of such Commercial Contributor in connection with its
+distribution of the Program in a commercial product offering. The
+obligations in this section do not apply to any claims or Losses
+relating to any actual or alleged intellectual property infringement.
+In order to qualify, an Indemnified Contributor must: a) promptly
+notify the Commercial Contributor in writing of such claim, and b)
+allow the Commercial Contributor to control, and cooperate with the
+Commercial Contributor in, the defense and any related settlement
+negotiations. The Indemnified Contributor may participate in any such
+claim at its own expense.
+
+For example, a Contributor might include the Program in a commercial
+product offering, Product X. That Contributor is then a Commercial
+Contributor. If that Commercial Contributor then makes performance
+claims, or offers warranties related to Product X, those performance
+claims and warranties are such Commercial Contributor's responsibility
+alone. Under this section, the Commercial Contributor would have to
+defend claims against the other Contributors related to those
+performance claims and warranties, and if a court requires any other
+Contributor to pay any damages as a result, the Commercial Contributor
+must pay those damages.
+
+5. NO WARRANTY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
+PROVIDED 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. Each Recipient is solely
+responsible for determining the appropriateness of using and
+distributing the Program and assumes all risks associated with its
+exercise of rights under this Agreement , including but not limited to
+the risks and costs of program errors, compliance with applicable
+laws, damage to or loss of data, programs or equipment, and
+unavailability or interruption of operations.
+
+6. DISCLAIMER OF LIABILITY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR
+ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING
+WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR
+DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+7. GENERAL
+
+If any provision of this Agreement is invalid or unenforceable under
+applicable law, it shall not affect the validity or enforceability of
+the remainder of the terms of this Agreement, and without further
+action by the parties hereto, such provision shall be reformed to the
+minimum extent necessary to make such provision valid and enforceable.
+
+If Recipient institutes patent litigation against any entity
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+the Program itself (excluding combinations of the Program with other
+software or hardware) infringes such Recipient's patent(s), then such
+Recipient's rights granted under Section 2(b) shall terminate as of
+the date such litigation is filed.
+
+All Recipient's rights under this Agreement shall terminate if it
+fails to comply with any of the material terms or conditions of this
+Agreement and does not cure such failure in a reasonable period of
+time after becoming aware of such noncompliance. If all Recipient's
+rights under this Agreement terminate, Recipient agrees to cease use
+and distribution of the Program as soon as reasonably practicable.
+However, Recipient's obligations under this Agreement and any licenses
+granted by Recipient relating to the Program shall continue and
+survive.
+
+Everyone is permitted to copy and distribute copies of this Agreement,
+but in order to avoid inconsistency the Agreement is copyrighted and
+may only be modified in the following manner. The Agreement Steward
+reserves the right to publish new versions (including revisions) of
+this Agreement from time to time. No one other than the Agreement
+Steward has the right to modify this Agreement. The Eclipse Foundation
+is the initial Agreement Steward. The Eclipse Foundation may assign
+the responsibility to serve as the Agreement Steward to a suitable
+separate entity. Each new version of the Agreement will be given a
+distinguishing version number. The Program (including Contributions)
+may always be distributed subject to the version of the Agreement
+under which it was received. In addition, after a new version of the
+Agreement is published, Contributor may elect to distribute the
+Program (including its Contributions) under the new version. Except as
+expressly stated in Sections 2(a) and 2(b) above, Recipient receives
+no rights or licenses to the intellectual property of any Contributor
+under this Agreement, whether expressly, by implication, estoppel or
+otherwise. All rights in the Program not expressly granted under this
+Agreement are reserved.
+
+This Agreement is governed by the laws of the State of New York and
+the intellectual property laws of the United States of America. No
+party to this Agreement will bring a legal action under this Agreement
+more than one year after the cause of action arose. Each party waives
+its rights to a jury trial in any resulting litigation.
+
+===============================================================================
+
+For the Rhino JavaScript container component:
+
+Netscape Public License V1.1
+
+ AMENDMENTS
+
+ The Netscape Public License Version 1.1 ("NPL") consists of the
+ Mozilla Public License Version 1.1 with the following Amendments,
+ including Exhibit A-Netscape Public License. Files identified with
+ "Exhibit A-Netscape Public License" are governed by the Netscape
+ Public License Version 1.1.
+
+ Additional Terms applicable to the Netscape Public License.
+ I. Effect.
+ These additional terms described in this Netscape Public
+ License -- Amendments shall apply to the Mozilla Communicator
+ client code and to all Covered Code under this License.
+
+ II. "Netscape's Branded Code" means Covered Code that Netscape
+ distributes and/or permits others to distribute under one or more
+ trademark(s) which are controlled by Netscape but which are not
+ licensed for use under this License.
+
+ III. Netscape and logo.
+ This License does not grant any rights to use the trademarks
+ "Netscape", the "Netscape N and horizon" logo or the "Netscape
+ lighthouse" logo, "Netcenter", "Gecko", "Java" or "JavaScript",
+ "Smart Browsing" even if such marks are included in the Original
+ Code or Modifications.
+
+ IV. Inability to Comply Due to Contractual Obligation.
+ Prior to licensing the Original Code under this License, Netscape
+ has licensed third party code for use in Netscape's Branded Code.
+ To the extent that Netscape is limited contractually from making
+ such third party code available under this License, Netscape may
+ choose to reintegrate such code into Covered Code without being
+ required to distribute such code in Source Code form, even if
+ such code would otherwise be considered "Modifications" under
+ this License.
+
+ V. Use of Modifications and Covered Code by Initial Developer.
+ V.1. In General.
+ The obligations of Section 3 apply to Netscape, except to
+ the extent specified in this Amendment, Section V.2 and V.3.
+
+ V.2. Other Products.
+ Netscape may include Covered Code in products other than the
+ Netscape's Branded Code which are released by Netscape
+ during the two (2) years following the release date of the
+ Original Code, without such additional products becoming
+ subject to the terms of this License, and may license such
+ additional products on different terms from those contained
+ in this License.
+
+ V.3. Alternative Licensing.
+ Netscape may license the Source Code of Netscape's Branded
+ Code, including Modifications incorporated therein, without
+ such Netscape Branded Code becoming subject to the terms of
+ this License, and may license such Netscape Branded Code on
+ different terms from those contained in this License.
+
+ VI. Litigation.
+ Notwithstanding the limitations of Section 11 above, the
+ provisions regarding litigation in Section 11(a), (b) and (c) of
+ the License shall apply to all disputes relating to this License.
+
+ EXHIBIT A-Netscape Public License.
+
+ "The contents of this file are subject to the Netscape Public
+ License Version 1.1 (the "License"); you may not use this file
+ except in compliance with the License. You may obtain a copy of
+ the License at http://www.mozilla.org/NPL/
+
+ Software distributed under the License is distributed on an "AS
+ IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ implied. See the License for the specific language governing
+ rights and limitations under the License.
+
+ The Original Code is Mozilla Communicator client code, released
+ March 31, 1998.
+
+ The Initial Developer of the Original Code is Netscape
+ Communications Corporation. Portions created by Netscape are
+ Copyright (C) 1998-1999 Netscape Communications Corporation. All
+ Rights Reserved.
+
+ Contributor(s): ______________________________________.
+
+ Alternatively, the contents of this file may be used under the
+ terms of the _____ license (the "[___] License"), in which case
+ the provisions of [______] License are applicable instead of
+ those above. If you wish to allow use of your version of this
+ file only under the terms of the [____] License and not to allow
+ others to use your version of this file under the NPL, indicate
+ your decision by deleting the provisions above and replace them
+ with the notice and other provisions required by the [___]
+ License. If you do not delete the provisions above, a recipient
+ may use your version of this file under either the NPL or the
+ [___] License."
+
+ ----------------------------------------------------------------------
+
+ MOZILLA PUBLIC LICENSE
+ Version 1.1
+
+ ---------------
+
+1. Definitions.
+
+ 1.0.1. "Commercial Use" means distribution or otherwise making the
+ Covered Code available to a third party.
+
+ 1.1. "Contributor" means each entity that creates or contributes to
+ the creation of Modifications.
+
+ 1.2. "Contributor Version" means the combination of the Original
+ Code, prior Modifications used by a Contributor, and the Modifications
+ made by that particular Contributor.
+
+ 1.3. "Covered Code" means the Original Code or Modifications or the
+ combination of the Original Code and Modifications, in each case
+ including portions thereof.
+
+ 1.4. "Electronic Distribution Mechanism" means a mechanism generally
+ accepted in the software development community for the electronic
+ transfer of data.
+
+ 1.5. "Executable" means Covered Code in any form other than Source
+ Code.
+
+ 1.6. "Initial Developer" means the individual or entity identified
+ as the Initial Developer in the Source Code notice required by Exhibit
+ A.
+
+ 1.7. "Larger Work" means a work which combines Covered Code or
+ portions thereof with code not governed by the terms of this License.
+
+ 1.8. "License" means this document.
+
+ 1.8.1. "Licensable" means having the right to grant, to the maximum
+ extent possible, whether at the time of the initial grant or
+ subsequently acquired, any and all of the rights conveyed herein.
+
+ 1.9. "Modifications" means any addition to or deletion from the
+ substance or structure of either the Original Code or any previous
+ Modifications. When Covered Code is released as a series of files, a
+ Modification is:
+ A. Any addition to or deletion from the contents of a file
+ containing Original Code or previous Modifications.
+
+ B. Any new file that contains any part of the Original Code or
+ previous Modifications.
+
+ 1.10. "Original Code" means Source Code of computer software code
+ which is described in the Source Code notice required by Exhibit A as
+ Original Code, and which, at the time of its release under this
+ License is not already Covered Code governed by this License.
+
+ 1.10.1. "Patent Claims" means any patent claim(s), now owned or
+ hereafter acquired, including without limitation, method, process,
+ and apparatus claims, in any patent Licensable by grantor.
+
+ 1.11. "Source Code" means the preferred form of the Covered Code for
+ making modifications to it, including all modules it contains, plus
+ any associated interface definition files, scripts used to control
+ compilation and installation of an Executable, or source code
+ differential comparisons against either the Original Code or another
+ well known, available Covered Code of the Contributor's choice. The
+ Source Code can be in a compressed or archival form, provided the
+ appropriate decompression or de-archiving software is widely available
+ for no charge.
+
+ 1.12. "You" (or "Your") means an individual or a legal entity
+ exercising rights under, and complying with all of the terms of, this
+ License or a future version of this License issued under Section 6.1.
+ For legal entities, "You" includes any entity which controls, is
+ controlled by, or is under common control with You. For purposes of
+ this definition, "control" means (a) the power, direct or indirect,
+ to cause the direction or management of such entity, whether by
+ contract or otherwise, or (b) ownership of more than fifty percent
+ (50%) of the outstanding shares or beneficial ownership of such
+ entity.
+
+2. Source Code License.
+
+ 2.1. The Initial Developer Grant.
+ The Initial Developer hereby grants You a world-wide, royalty-free,
+ non-exclusive license, subject to third party intellectual property
+ claims:
+ (a) under intellectual property rights (other than patent or
+ trademark) Licensable by Initial Developer to use, reproduce,
+ modify, display, perform, sublicense and distribute the Original
+ Code (or portions thereof) with or without Modifications, and/or
+ as part of a Larger Work; and
+
+ (b) under Patents Claims infringed by the making, using or
+ selling of Original Code, to make, have made, use, practice,
+ sell, and offer for sale, and/or otherwise dispose of the
+ Original Code (or portions thereof).
+
+ (c) the licenses granted in this Section 2.1(a) and (b) are
+ effective on the date Initial Developer first distributes
+ Original Code under the terms of this License.
+
+ (d) Notwithstanding Section 2.1(b) above, no patent license is
+ granted: 1) for code that You delete from the Original Code; 2)
+ separate from the Original Code; or 3) for infringements caused
+ by: i) the modification of the Original Code or ii) the
+ combination of the Original Code with other software or devices.
+
+ 2.2. Contributor Grant.
+ Subject to third party intellectual property claims, each Contributor
+ hereby grants You a world-wide, royalty-free, non-exclusive license
+
+ (a) under intellectual property rights (other than patent or
+ trademark) Licensable by Contributor, to use, reproduce, modify,
+ display, perform, sublicense and distribute the Modifications
+ created by such Contributor (or portions thereof) either on an
+ unmodified basis, with other Modifications, as Covered Code
+ and/or as part of a Larger Work; and
+
+ (b) under Patent Claims infringed by the making, using, or
+ selling of Modifications made by that Contributor either alone
+ and/or in combination with its Contributor Version (or portions
+ of such combination), to make, use, sell, offer for sale, have
+ made, and/or otherwise dispose of: 1) Modifications made by that
+ Contributor (or portions thereof); and 2) the combination of
+ Modifications made by that Contributor with its Contributor
+ Version (or portions of such combination).
+
+ (c) the licenses granted in Sections 2.2(a) and 2.2(b) are
+ effective on the date Contributor first makes Commercial Use of
+ the Covered Code.
+
+ (d) Notwithstanding Section 2.2(b) above, no patent license is
+ granted: 1) for any code that Contributor has deleted from the
+ Contributor Version; 2) separate from the Contributor Version;
+ 3) for infringements caused by: i) third party modifications of
+ Contributor Version or ii) the combination of Modifications made
+ by that Contributor with other software (except as part of the
+ Contributor Version) or other devices; or 4) under Patent Claims
+ infringed by Covered Code in the absence of Modifications made by
+ that Contributor.
+
+3. Distribution Obligations.
+
+ 3.1. Application of License.
+ The Modifications which You create or to which You contribute are
+ governed by the terms of this License, including without limitation
+ Section 2.2. The Source Code version of Covered Code may be
+ distributed only under the terms of this License or a future version
+ of this License released under Section 6.1, and You must include a
+ copy of this License with every copy of the Source Code You
+ distribute. You may not offer or impose any terms on any Source Code
+ version that alters or restricts the applicable version of this
+ License or the recipients' rights hereunder. However, You may include
+ an additional document offering the additional rights described in
+ Section 3.5.
+
+ 3.2. Availability of Source Code.
+ Any Modification which You create or to which You contribute must be
+ made available in Source Code form under the terms of this License
+ either on the same media as an Executable version or via an accepted
+ Electronic Distribution Mechanism to anyone to whom you made an
+ Executable version available; and if made available via Electronic
+ Distribution Mechanism, must remain available for at least twelve (12)
+ months after the date it initially became available, or at least six
+ (6) months after a subsequent version of that particular Modification
+ has been made available to such recipients. You are responsible for
+ ensuring that the Source Code version remains available even if the
+ Electronic Distribution Mechanism is maintained by a third party.
+
+ 3.3. Description of Modifications.
+ You must cause all Covered Code to which You contribute to contain a
+ file documenting the changes You made to create that Covered Code and
+ the date of any change. You must include a prominent statement that
+ the Modification is derived, directly or indirectly, from Original
+ Code provided by the Initial Developer and including the name of the
+ Initial Developer in (a) the Source Code, and (b) in any notice in an
+ Executable version or related documentation in which You describe the
+ origin or ownership of the Covered Code.
+
+ 3.4. Intellectual Property Matters
+ (a) Third Party Claims.
+ If Contributor has knowledge that a license under a third party's
+ intellectual property rights is required to exercise the rights
+ granted by such Contributor under Sections 2.1 or 2.2,
+ Contributor must include a text file with the Source Code
+ distribution titled "LEGAL" which describes the claim and the
+ party making the claim in sufficient detail that a recipient will
+ know whom to contact. If Contributor obtains such knowledge after
+ the Modification is made available as described in Section 3.2,
+ Contributor shall promptly modify the LEGAL file in all copies
+ Contributor makes available thereafter and shall take other steps
+ (such as notifying appropriate mailing lists or newsgroups)
+ reasonably calculated to inform those who received the Covered
+ Code that new knowledge has been obtained.
+
+ (b) Contributor APIs.
+ If Contributor's Modifications include an application programming
+ interface and Contributor has knowledge of patent licenses which
+ are reasonably necessary to implement that API, Contributor must
+ also include this information in the LEGAL file.
+
+ (c) Representations.
+ Contributor represents that, except as disclosed pursuant to
+ Section 3.4(a) above, Contributor believes that Contributor's
+ Modifications are Contributor's original creation(s) and/or
+ Contributor has sufficient rights to grant the rights conveyed by
+ this License.
+
+ 3.5. Required Notices.
+ You must duplicate the notice in Exhibit A in each file of the Source
+ Code. If it is not possible to put such notice in a particular Source
+ Code file due to its structure, then You must include such notice in a
+ location (such as a relevant directory) where a user would be likely
+ to look for such a notice. If You created one or more Modification(s)
+ You may add your name as a Contributor to the notice described in
+ Exhibit A. You must also duplicate this License in any documentation
+ for the Source Code where You describe recipients' rights or ownership
+ rights relating to Covered Code. You may choose to offer, and to
+ charge a fee for, warranty, support, indemnity or liability
+ obligations to one or more recipients of Covered Code. However, You
+ may do so only on Your own behalf, and not on behalf of the Initial
+ Developer or any Contributor. You must make it absolutely clear than
+ any such warranty, support, indemnity or liability obligation is
+ offered by You alone, and You hereby agree to indemnify the Initial
+ Developer and every Contributor for any liability incurred by the
+ Initial Developer or such Contributor as a result of warranty,
+ support, indemnity or liability terms You offer.
+
+ 3.6. Distribution of Executable Versions.
+ You may distribute Covered Code in Executable form only if the
+ requirements of Section 3.1-3.5 have been met for that Covered Code,
+ and if You include a notice stating that the Source Code version of
+ the Covered Code is available under the terms of this License,
+ including a description of how and where You have fulfilled the
+ obligations of Section 3.2. The notice must be conspicuously included
+ in any notice in an Executable version, related documentation or
+ collateral in which You describe recipients' rights relating to the
+ Covered Code. You may distribute the Executable version of Covered
+ Code or ownership rights under a license of Your choice, which may
+ contain terms different from this License, provided that You are in
+ compliance with the terms of this License and that the license for the
+ Executable version does not attempt to limit or alter the recipient's
+ rights in the Source Code version from the rights set forth in this
+ License. If You distribute the Executable version under a different
+ license You must make it absolutely clear that any terms which differ
+ from this License are offered by You alone, not by the Initial
+ Developer or any Contributor. You hereby agree to indemnify the
+ Initial Developer and every Contributor for any liability incurred by
+ the Initial Developer or such Contributor as a result of any such
+ terms You offer.
+
+ 3.7. Larger Works.
+ You may create a Larger Work by combining Covered Code with other code
+ not governed by the terms of this License and distribute the Larger
+ Work as a single product. In such a case, You must make sure the
+ requirements of this License are fulfilled for the Covered Code.
+
+4. Inability to Comply Due to Statute or Regulation.
+
+ If it is impossible for You to comply with any of the terms of this
+ License with respect to some or all of the Covered Code due to
+ statute, judicial order, or regulation then You must: (a) comply with
+ the terms of this License to the maximum extent possible; and (b)
+ describe the limitations and the code they affect. Such description
+ must be included in the LEGAL file described in Section 3.4 and must
+ be included with all distributions of the Source Code. Except to the
+ extent prohibited by statute or regulation, such description must be
+ sufficiently detailed for a recipient of ordinary skill to be able to
+ understand it.
+
+5. Application of this License.
+
+ This License applies to code to which the Initial Developer has
+ attached the notice in Exhibit A and to related Covered Code.
+
+6. Versions of the License.
+
+ 6.1. New Versions.
+ Netscape Communications Corporation ("Netscape") may publish revised
+ and/or new versions of the License from time to time. Each version
+ will be given a distinguishing version number.
+
+ 6.2. Effect of New Versions.
+ Once Covered Code has been published under a particular version of the
+ License, You may always continue to use it under the terms of that
+ version. You may also choose to use such Covered Code under the terms
+ of any subsequent version of the License published by Netscape. No one
+ other than Netscape has the right to modify the terms applicable to
+ Covered Code created under this License.
+
+ 6.3. Derivative Works.
+ If You create or use a modified version of this License (which you may
+ only do in order to apply it to code which is not already Covered Code
+ governed by this License), You must (a) rename Your license so that
+ the phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape",
+ "MPL", "NPL" or any confusingly similar phrase do not appear in your
+ license (except to note that your license differs from this License)
+ and (b) otherwise make it clear that Your version of the license
+ contains terms which differ from the Mozilla Public License and
+ Netscape Public License. (Filling in the name of the Initial
+ Developer, Original Code or Contributor in the notice described in
+ Exhibit A shall not of themselves be deemed to be modifications of
+ this License.)
+
+7. DISCLAIMER OF WARRANTY.
+
+ COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF
+ DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING.
+ THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE
+ IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT,
+ YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE
+ COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER
+ OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF
+ ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
+
+8. TERMINATION.
+
+ 8.1. This License and the rights granted hereunder will terminate
+ automatically if You fail to comply with terms herein and fail to cure
+ such breach within 30 days of becoming aware of the breach. All
+ sublicenses to the Covered Code which are properly granted shall
+ survive any termination of this License. Provisions which, by their
+ nature, must remain in effect beyond the termination of this License
+ shall survive.
+
+ 8.2. If You initiate litigation by asserting a patent infringement
+ claim (excluding declatory judgment actions) against Initial Developer
+ or a Contributor (the Initial Developer or Contributor against whom
+ You file such action is referred to as "Participant") alleging that:
+
+ (a) such Participant's Contributor Version directly or indirectly
+ infringes any patent, then any and all rights granted by such
+ Participant to You under Sections 2.1 and/or 2.2 of this License
+ shall, upon 60 days notice from Participant terminate prospectively,
+ unless if within 60 days after receipt of notice You either: (i)
+ agree in writing to pay Participant a mutually agreeable reasonable
+ royalty for Your past and future use of Modifications made by such
+ Participant, or (ii) withdraw Your litigation claim with respect to
+ the Contributor Version against such Participant. If within 60 days
+ of notice, a reasonable royalty and payment arrangement are not
+ mutually agreed upon in writing by the parties or the litigation claim
+ is not withdrawn, the rights granted by Participant to You under
+ Sections 2.1 and/or 2.2 automatically terminate at the expiration of
+ the 60 day notice period specified above.
+
+ (b) any software, hardware, or device, other than such Participant's
+ Contributor Version, directly or indirectly infringes any patent, then
+ any rights granted to You by such Participant under Sections 2.1(b)
+ and 2.2(b) are revoked effective as of the date You first made, used,
+ sold, distributed, or had made, Modifications made by that
+ Participant.
+
+ 8.3. If You assert a patent infringement claim against Participant
+ alleging that such Participant's Contributor Version directly or
+ indirectly infringes any patent where such claim is resolved (such as
+ by license or settlement) prior to the initiation of patent
+ infringement litigation, then the reasonable value of the licenses
+ granted by such Participant under Sections 2.1 or 2.2 shall be taken
+ into account in determining the amount or value of any payment or
+ license.
+
+ 8.4. In the event of termination under Sections 8.1 or 8.2 above,
+ all end user license agreements (excluding distributors and resellers)
+ which have been validly granted by You or any distributor hereunder
+ prior to termination shall survive termination.
+
+9. LIMITATION OF LIABILITY.
+
+ UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
+ (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL
+ DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE,
+ OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR
+ ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY
+ CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL,
+ WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER
+ COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN
+ INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF
+ LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY
+ RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW
+ PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE
+ EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO
+ THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
+
+10. U.S. GOVERNMENT END USERS.
+
+ The Covered Code is a "commercial item," as that term is defined in
+ 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer
+ software" and "commercial computer software documentation," as such
+ terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48
+ C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995),
+ all U.S. Government End Users acquire Covered Code with only those
+ rights set forth herein.
+
+11. MISCELLANEOUS.
+
+ This License represents the complete agreement concerning subject
+ matter hereof. If any provision of this License is held to be
+ unenforceable, such provision shall be reformed only to the extent
+ necessary to make it enforceable. This License shall be governed by
+ California law provisions (except to the extent applicable law, if
+ any, provides otherwise), excluding its conflict-of-law provisions.
+ With respect to disputes in which at least one party is a citizen of,
+ or an entity chartered or registered to do business in the United
+ States of America, any litigation relating to this License shall be
+ subject to the jurisdiction of the Federal Courts of the Northern
+ District of California, with venue lying in Santa Clara County,
+ California, with the losing party responsible for costs, including
+ without limitation, court costs and reasonable attorneys' fees and
+ expenses. The application of the United Nations Convention on
+ Contracts for the International Sale of Goods is expressly excluded.
+ Any law or regulation which provides that the language of a contract
+ shall be construed against the drafter shall not apply to this
+ License.
+
+12. RESPONSIBILITY FOR CLAIMS.
+
+ As between Initial Developer and the Contributors, each party is
+ responsible for claims and damages arising, directly or indirectly,
+ out of its utilization of rights under this License and You agree to
+ work with Initial Developer and Contributors to distribute such
+ responsibility on an equitable basis. Nothing herein is intended or
+ shall be deemed to constitute any admission of liability.
+
+13. MULTIPLE-LICENSED CODE.
+
+ Initial Developer may designate portions of the Covered Code as
+ "Multiple-Licensed". "Multiple-Licensed" means that the Initial
+ Developer permits you to utilize portions of the Covered Code under
+ Your choice of the NPL or the alternative licenses, if any, specified
+ by the Initial Developer in the file described in Exhibit A.
+
+EXHIBIT A -Mozilla Public License.
+
+ ``The contents of this file are subject to the Mozilla Public License
+ Version 1.1 (the "License"); you may not use this file except in
+ compliance with the License. You may obtain a copy of the License at
+ http://www.mozilla.org/MPL/
+
+ Software distributed under the License is distributed on an "AS IS"
+ basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ License for the specific language governing rights and limitations
+ under the License.
+
+ The Original Code is ______________________________________.
+
+ The Initial Developer of the Original Code is ________________________.
+ Portions created by ______________________ are Copyright (C) ______
+ _______________________. All Rights Reserved.
+
+ Contributor(s): ______________________________________.
+
+ Alternatively, the contents of this file may be used under the terms
+ of the _____ license (the "[___] License"), in which case the
+ provisions of [______] License are applicable instead of those
+ above. If you wish to allow use of your version of this file only
+ under the terms of the [____] License and not to allow others to use
+ your version of this file under the MPL, indicate your decision by
+ deleting the provisions above and replace them with the notice and
+ other provisions required by the [___] License. If you do not delete
+ the provisions above, a recipient may use your version of this file
+ under either the MPL or the [___] License."
+
+ [NOTE: The text of this Exhibit A may differ slightly from the text of
+ the notices in the Source Code files of the Original Code. You should
+ use the text of this Exhibit A rather than the text found in the
+ Original Code Source Code for Your Modifications.]
+
+
+===============================================================================
+
+For the JAX-WS Reference Implementation component:
+
+COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
+
+
+ 1. Definitions.
+
+ 1.1. "Contributor" means each individual or entity that
+ creates or contributes to the creation of Modifications.
+
+ 1.2. "Contributor Version" means the combination of the
+ Original Software, prior Modifications used by a
+ Contributor (if any), and the Modifications made by that
+ particular Contributor.
+
+ 1.3. "Covered Software" means (a) the Original Software, or
+ (b) Modifications, or (c) the combination of files
+ containing Original Software with files containing
+ Modifications, in each case including portions thereof.
+
+ 1.4. "Executable" means the Covered Software in any form
+ other than Source Code.
+
+ 1.5. "Initial Developer" means the individual or entity
+ that first makes Original Software available under this
+ License.
+
+ 1.6. "Larger Work" means a work which combines Covered
+ Software or portions thereof with code not governed by the
+ terms of this License.
+
+ 1.7. "License" means this document.
+
+ 1.8. "Licensable" means having the right to grant, to the
+ maximum extent possible, whether at the time of the initial
+ grant or subsequently acquired, any and all of the rights
+ conveyed herein.
+
+ 1.9. "Modifications" means the Source Code and Executable
+ form of any of the following:
+
+ A. Any file that results from an addition to,
+ deletion from or modification of the contents of a
+ file containing Original Software or previous
+ Modifications;
+
+ B. Any new file that contains any part of the
+ Original Software or previous Modification; or
+
+ C. Any new file that is contributed or otherwise made
+ available under the terms of this License.
+
+ 1.10. "Original Software" means the Source Code and
+ Executable form of computer software code that is
+ originally released under this License.
+
+ 1.11. "Patent Claims" means any patent claim(s), now owned
+ or hereafter acquired, including without limitation,
+ method, process, and apparatus claims, in any patent
+ Licensable by grantor.
+
+ 1.12. "Source Code" means (a) the common form of computer
+ software code in which modifications are made and (b)
+ associated documentation included in or with such code.
+
+ 1.13. "You" (or "Your") means an individual or a legal
+ entity exercising rights under, and complying with all of
+ the terms of, this License. For legal entities, "You"
+ includes any entity which controls, is controlled by, or is
+ under common control with You. For purposes of this
+ definition, "control" means (a) the power, direct or
+ indirect, to cause the direction or management of such
+ entity, whether by contract or otherwise, or (b) ownership
+ of more than fifty percent (50%) of the outstanding shares
+ or beneficial ownership of such entity.
+
+ 2. License Grants.
+
+ 2.1. The Initial Developer Grant.
+
+ Conditioned upon Your compliance with Section 3.1 below and
+ subject to third party intellectual property claims, the
+ Initial Developer hereby grants You a world-wide,
+ royalty-free, non-exclusive license:
+
+ (a) under intellectual property rights (other than
+ patent or trademark) Licensable by Initial Developer,
+ to use, reproduce, modify, display, perform,
+ sublicense and distribute the Original Software (or
+ portions thereof), with or without Modifications,
+ and/or as part of a Larger Work; and
+
+ (b) under Patent Claims infringed by the making,
+ using or selling of Original Software, to make, have
+ made, use, practice, sell, and offer for sale, and/or
+ otherwise dispose of the Original Software (or
+ portions thereof).
+
+ (c) The licenses granted in Sections 2.1(a) and (b)
+ are effective on the date Initial Developer first
+ distributes or otherwise makes the Original Software
+ available to a third party under the terms of this
+ License.
+
+ (d) Notwithstanding Section 2.1(b) above, no patent
+ license is granted: (1) for code that You delete from
+ the Original Software, or (2) for infringements
+ caused by: (i) the modification of the Original
+ Software, or (ii) the combination of the Original
+ Software with other software or devices.
+
+ 2.2. Contributor Grant.
+
+ Conditioned upon Your compliance with Section 3.1 below and
+ subject to third party intellectual property claims, each
+ Contributor hereby grants You a world-wide, royalty-free,
+ non-exclusive license:
+
+ (a) under intellectual property rights (other than
+ patent or trademark) Licensable by Contributor to
+ use, reproduce, modify, display, perform, sublicense
+ and distribute the Modifications created by such
+ Contributor (or portions thereof), either on an
+ unmodified basis, with other Modifications, as
+ Covered Software and/or as part of a Larger Work; and
+
+
+ (b) under Patent Claims infringed by the making,
+ using, or selling of Modifications made by that
+ Contributor either alone and/or in combination with
+ its Contributor Version (or portions of such
+ combination), to make, use, sell, offer for sale,
+ have made, and/or otherwise dispose of: (1)
+ Modifications made by that Contributor (or portions
+ thereof); and (2) the combination of Modifications
+ made by that Contributor with its Contributor Version
+ (or portions of such combination).
+
+ (c) The licenses granted in Sections 2.2(a) and
+ 2.2(b) are effective on the date Contributor first
+ distributes or otherwise makes the Modifications
+ available to a third party.
+
+ (d) Notwithstanding Section 2.2(b) above, no patent
+ license is granted: (1) for any code that Contributor
+ has deleted from the Contributor Version; (2) for
+ infringements caused by: (i) third party
+ modifications of Contributor Version, or (ii) the
+ combination of Modifications made by that Contributor
+ with other software (except as part of the
+ Contributor Version) or other devices; or (3) under
+ Patent Claims infringed by Covered Software in the
+ absence of Modifications made by that Contributor.
+
+ 3. Distribution Obligations.
+
+ 3.1. Availability of Source Code.
+
+ Any Covered Software that You distribute or otherwise make
+ available in Executable form must also be made available in
+ Source Code form and that Source Code form must be
+ distributed only under the terms of this License. You must
+ include a copy of this License with every copy of the
+ Source Code form of the Covered Software You distribute or
+ otherwise make available. You must inform recipients of any
+ such Covered Software in Executable form as to how they can
+ obtain such Covered Software in Source Code form in a
+ reasonable manner on or through a medium customarily used
+ for software exchange.
+
+ 3.2. Modifications.
+
+ The Modifications that You create or to which You
+ contribute are governed by the terms of this License. You
+ represent that You believe Your Modifications are Your
+ original creation(s) and/or You have sufficient rights to
+ grant the rights conveyed by this License.
+
+ 3.3. Required Notices.
+
+ You must include a notice in each of Your Modifications
+ that identifies You as the Contributor of the Modification.
+ You may not remove or alter any copyright, patent or
+ trademark notices contained within the Covered Software, or
+ any notices of licensing or any descriptive text giving
+ attribution to any Contributor or the Initial Developer.
+
+ 3.4. Application of Additional Terms.
+
+ You may not offer or impose any terms on any Covered
+ Software in Source Code form that alters or restricts the
+ applicable version of this License or the recipients'
+ rights hereunder. You may choose to offer, and to charge a
+ fee for, warranty, support, indemnity or liability
+ obligations to one or more recipients of Covered Software.
+ However, you may do so only on Your own behalf, and not on
+ behalf of the Initial Developer or any Contributor. You
+ must make it absolutely clear that any such warranty,
+ support, indemnity or liability obligation is offered by
+ You alone, and You hereby agree to indemnify the Initial
+ Developer and every Contributor for any liability incurred
+ by the Initial Developer or such Contributor as a result of
+ warranty, support, indemnity or liability terms You offer.
+
+
+ 3.5. Distribution of Executable Versions.
+
+ You may distribute the Executable form of the Covered
+ Software under the terms of this License or under the terms
+ of a license of Your choice, which may contain terms
+ different from this License, provided that You are in
+ compliance with the terms of this License and that the
+ license for the Executable form does not attempt to limit
+ or alter the recipient's rights in the Source Code form
+ from the rights set forth in this License. If You
+ distribute the Covered Software in Executable form under a
+ different license, You must make it absolutely clear that
+ any terms which differ from this License are offered by You
+ alone, not by the Initial Developer or Contributor. You
+ hereby agree to indemnify the Initial Developer and every
+ Contributor for any liability incurred by the Initial
+ Developer or such Contributor as a result of any such terms
+ You offer.
+
+ 3.6. Larger Works.
+
+ You may create a Larger Work by combining Covered Software
+ with other code not governed by the terms of this License
+ and distribute the Larger Work as a single product. In such
+ a case, You must make sure the requirements of this License
+ are fulfilled for the Covered Software.
+
+ 4. Versions of the License.
+
+ 4.1. New Versions.
+
+ Sun Microsystems, Inc. is the initial license steward and
+ may publish revised and/or new versions of this License
+ from time to time. Each version will be given a
+ distinguishing version number. Except as provided in
+ Section 4.3, no one other than the license steward has the
+ right to modify this License.
+
+ 4.2. Effect of New Versions.
+
+ You may always continue to use, distribute or otherwise
+ make the Covered Software available under the terms of the
+ version of the License under which You originally received
+ the Covered Software. If the Initial Developer includes a
+ notice in the Original Software prohibiting it from being
+ distributed or otherwise made available under any
+ subsequent version of the License, You must distribute and
+ make the Covered Software available under the terms of the
+ version of the License under which You originally received
+ the Covered Software. Otherwise, You may also choose to
+ use, distribute or otherwise make the Covered Software
+ available under the terms of any subsequent version of the
+ License published by the license steward.
+
+ 4.3. Modified Versions.
+
+ When You are an Initial Developer and You want to create a
+ new license for Your Original Software, You may create and
+ use a modified version of this License if You: (a) rename
+ the license and remove any references to the name of the
+ license steward (except to note that the license differs
+ from this License); and (b) otherwise make it clear that
+ the license contains terms which differ from this License.
+
+
+ 5. DISCLAIMER OF WARRANTY.
+
+ COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS"
+ BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
+ INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED
+ SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR
+ PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND
+ PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY
+ COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE
+ INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF
+ ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF
+ WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF
+ ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS
+ DISCLAIMER.
+
+ 6. TERMINATION.
+
+ 6.1. This License and the rights granted hereunder will
+ terminate automatically if You fail to comply with terms
+ herein and fail to cure such breach within 30 days of
+ becoming aware of the breach. Provisions which, by their
+ nature, must remain in effect beyond the termination of
+ this License shall survive.
+
+ 6.2. If You assert a patent infringement claim (excluding
+ declaratory judgment actions) against Initial Developer or
+ a Contributor (the Initial Developer or Contributor against
+ whom You assert such claim is referred to as "Participant")
+ alleging that the Participant Software (meaning the
+ Contributor Version where the Participant is a Contributor
+ or the Original Software where the Participant is the
+ Initial Developer) directly or indirectly infringes any
+ patent, then any and all rights granted directly or
+ indirectly to You by such Participant, the Initial
+ Developer (if the Initial Developer is not the Participant)
+ and all Contributors under Sections 2.1 and/or 2.2 of this
+ License shall, upon 60 days notice from Participant
+ terminate prospectively and automatically at the expiration
+ of such 60 day notice period, unless if within such 60 day
+ period You withdraw Your claim with respect to the
+ Participant Software against such Participant either
+ unilaterally or pursuant to a written agreement with
+ Participant.
+
+ 6.3. In the event of termination under Sections 6.1 or 6.2
+ above, all end user licenses that have been validly granted
+ by You or any distributor hereunder prior to termination
+ (excluding licenses granted to You by any distributor)
+ shall survive termination.
+
+ 7. LIMITATION OF LIABILITY.
+
+ UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
+ (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE
+ INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF
+ COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE
+ LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT
+ LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK
+ STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER
+ COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN
+ INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF
+ LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL
+ INJURY RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT
+ APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO
+ NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR
+ CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT
+ APPLY TO YOU.
+
+ 8. U.S. GOVERNMENT END USERS.
+
+ The Covered Software is a "commercial item," as that term is
+ defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial
+ computer software" (as that term is defined at 48 C.F.R.
+ 252.227-7014(a)(1)) and "commercial computer software
+ documentation" as such terms are used in 48 C.F.R. 12.212 (Sept.
+ 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1
+ through 227.7202-4 (June 1995), all U.S. Government End Users
+ acquire Covered Software with only those rights set forth herein.
+ This U.S. Government Rights clause is in lieu of, and supersedes,
+ any other FAR, DFAR, or other clause or provision that addresses
+ Government rights in computer software under this License.
+
+ 9. MISCELLANEOUS.
+
+ This License represents the complete agreement concerning subject
+ matter hereof. If any provision of this License is held to be
+ unenforceable, such provision shall be reformed only to the
+ extent necessary to make it enforceable. This License shall be
+ governed by the law of the jurisdiction specified in a notice
+ contained within the Original Software (except to the extent
+ applicable law, if any, provides otherwise), excluding such
+ jurisdiction's conflict-of-law provisions. Any litigation
+ relating to this License shall be subject to the jurisdiction of
+ the courts located in the jurisdiction and venue specified in a
+ notice contained within the Original Software, with the losing
+ party responsible for costs, including, without limitation, court
+ costs and reasonable attorneys' fees and expenses. The
+ application of the United Nations Convention on Contracts for the
+ International Sale of Goods is expressly excluded. Any law or
+ regulation which provides that the language of a contract shall
+ be construed against the drafter shall not apply to this License.
+ You agree that You alone are responsible for compliance with the
+ United States export administration regulations (and the export
+ control laws and regulation of any other countries) when You use,
+ distribute or otherwise make available any Covered Software.
+
+ 10. RESPONSIBILITY FOR CLAIMS.
+
+ As between Initial Developer and the Contributors, each party is
+ responsible for claims and damages arising, directly or
+ indirectly, out of its utilization of rights under this License
+ and You agree to work with Initial Developer and Contributors to
+ distribute such responsibility on an equitable basis. Nothing
+ herein is intended or shall be deemed to constitute any admission
+ of liability.
+
diff --git a/tags/java/tsss-demo/runtime/webapp/plugin.war/NOTICE.txt b/tags/java/tsss-demo/runtime/webapp/plugin.war/NOTICE.txt
new file mode 100644
index 0000000000..d83ebbe236
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/plugin.war/NOTICE.txt
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/runtime/webapp/plugin.war/pom.xml b/tags/java/tsss-demo/runtime/webapp/plugin.war/pom.xml
new file mode 100644
index 0000000000..6243b60b0a
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/plugin.war/pom.xml
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany</groupId>
+ <artifactId>sca</artifactId>
+ <version>1.0-incubating</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>tuscany-war-plugin</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ <packaging>maven-plugin</packaging>
+ <name>Apache Tuscany War Plugin</name>
+ <description>A plugin for Apache Maven that adds a Tuscany runtime to a war.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.2</version>
+ </dependency>
+ </dependencies>
+
+ <distributionManagement>
+ <site>
+ <id>apache.website</id>
+ <url>scp://people.apache.org/www/incubator.apache.org/tuscany/plugins/tuscany-war-plugin</url>
+ </site>
+ </distributionManagement>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>2.2</version>
+ <configuration>
+ <goalPrefix>tuscany</goalPrefix>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>2.2</version>
+ </plugin>
+ </plugins>
+ </reporting>
+</project>
diff --git a/tags/java/tsss-demo/runtime/webapp/plugin.war/src/main/java/org/apache/tuscany/plugin/war/Dependency.java b/tags/java/tsss-demo/runtime/webapp/plugin.war/src/main/java/org/apache/tuscany/plugin/war/Dependency.java
new file mode 100644
index 0000000000..07817eeca0
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/plugin.war/src/main/java/org/apache/tuscany/plugin/war/Dependency.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.plugin.war;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+
+/**
+ * Represents a configured tuscany dependency for boot and extension libraries.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Dependency {
+
+ /**
+ * JAR type artifact.
+ */
+ private static final String TYPE_JAR = "jar";
+
+ /**
+ * Group Id that is injected in from configuration.
+ */
+ private String groupId;
+
+ /**
+ * Artifact Id that is injected in from configuration.
+ */
+ private String artifactId;
+
+ /**
+ * Version that is injected in from configuration.
+ */
+ private String version;
+
+ /**
+ * Default constructor.
+ */
+ public Dependency() {
+ }
+
+ /**
+ * Initializes the field.
+ *
+ * @param groupId Group id.
+ * @param artifactId Artifact id.
+ * @param version Artifact version.
+ */
+ public Dependency(String groupId, String artifactId, String version) {
+ super();
+ this.groupId = groupId;
+ this.artifactId = artifactId;
+ this.version = version;
+ }
+
+ /**
+ * Gets the artifact using the specified artifact factory.
+ *
+ * @param artifactFactory Artifact factory to use.
+ * @return Artifact identified by the dependency.
+ */
+ public Artifact getArtifact(ArtifactFactory artifactFactory) {
+ return artifactFactory.createArtifact(groupId, artifactId, version, Artifact.SCOPE_RUNTIME, TYPE_JAR);
+ }
+
+ /**
+ * Checks whether the specified artifact has the same artifact id.
+ *
+ * @param artifact Artifact to be matched.
+ * @return True if the specified artifact has the same id.
+ */
+ public boolean match(Artifact artifact) {
+ return artifact.getArtifactId().equals(artifactId);
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/plugin.war/src/main/java/org/apache/tuscany/plugin/war/TuscanyWarMojo.java b/tags/java/tsss-demo/runtime/webapp/plugin.war/src/main/java/org/apache/tuscany/plugin/war/TuscanyWarMojo.java
new file mode 100644
index 0000000000..5eb8cdcba3
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/plugin.war/src/main/java/org/apache/tuscany/plugin/war/TuscanyWarMojo.java
@@ -0,0 +1,508 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.plugin.war;
+
+import java.beans.XMLEncoder;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Properties;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.JarOutputStream;
+import java.util.zip.ZipException;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.metadata.ResolutionGroup;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * Build the tuscany war file by adding the tuscany dependencies.
+ *
+ * Performs the following tasks.
+ *
+ * <ul>
+ * <li>Adds the boot dependencies transitively to WEB-INF/tuscany/boot</li>
+ * <li>By default boot libraries are transitively resolved from webapp-host</li>
+ * <li>The version of boot libraries can be specified using configuration/runTimeVersion element</li>
+ * <li>Boot libraries can be overridden using the configuration/bootLibs element in the plugin</li>
+ * <li>Adds the extension artifacts specified using configuration/extensions to WEB-INF/tuscany/extensions</li>
+ * <li>If configuration/loadExtensionsDependency is set to true extension dependencies are transitivel loaded</li>
+ * <li>Extension dependencies are loaded into WEB-INF/tuscany/repository directory in a Maven repo format</li>
+ * <li>Extension dependency metadata is written to WEB-INF/tuscany/repository/dependency.metadata file</li>
+ * </ul>
+ * @goal tuscany-war
+ * @phase package
+ *
+ * @version $Rev$ $Date$
+ *
+ */
+public class TuscanyWarMojo extends AbstractMojo {
+
+ /**
+ * Tuscany path.
+ */
+ private static final String TUSCANY_PATH = "WEB-INF/tuscany/";
+
+ /**
+ * Tuscany boot path.
+ */
+ private static final String BOOT_PATH = TUSCANY_PATH + "boot/";
+
+ /**
+ * Tuscany extension path.
+ */
+ private static final String EXTENSION_PATH = TUSCANY_PATH + "extensions/";
+
+ /**
+ * Tuscany repository path.
+ */
+ private static final String REPOSITORY_PATH = TUSCANY_PATH + "repository/";
+
+ /**
+ * Artifact metadata source.
+ *
+ * @component
+ */
+ public ArtifactMetadataSource metadataSource;
+
+ /**
+ * Used to look up Artifacts in the remote repository.
+ *
+ * @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}"
+ * @required
+ * @readonly
+ */
+ public ArtifactFactory artifactFactory;
+
+ /**
+ * Used to look up Artifacts in the remote repository.
+ *
+ * @parameter expression="${component.org.apache.maven.artifact.resolver.ArtifactResolver}"
+ * @required
+ * @readonly
+ */
+ public ArtifactResolver resolver;
+
+ /**
+ * Location of the local repository.
+ *
+ * @parameter expression="${localRepository}"
+ * @readonly
+ * @required
+ */
+ public ArtifactRepository localRepository;
+
+ /**
+ * List of Remote Repositories used by the resolver
+ *
+ * @parameter expression="${project.remoteArtifactRepositories}"
+ * @readonly
+ * @required
+ */
+ public List remoteRepositories;
+
+ /**
+ * The directory for the generated WAR.
+ *
+ * @parameter expression="${project.build.directory}"
+ * @required
+ */
+ public String outputDirectory;
+
+ /**
+ * The directory for the generated WAR.
+ *
+ * @parameter
+ */
+ public Dependency[] bootLibs;
+
+ /**
+ * The directory for the generated WAR.
+ *
+ * @parameter
+ */
+ public Dependency[] extensions = new Dependency[0];
+
+ /**
+ * The directory for the generated WAR.
+ *
+ * @parameter
+ */
+ public Dependency[] dependencies = new Dependency[0];
+
+ /**
+ * The name of the generated WAR.
+ *
+ * @parameter expression="${project.build.finalName}"
+ * @required
+ */
+ public String warName;
+
+ /**
+ * A flag to indicate whether extension dependencies should be resolved transitively.
+ *
+ * @parameter
+ */
+ public boolean loadExtensionDependencies;
+
+ /**
+ * The default version of the runtime to use.
+ *
+ * @parameter
+ */
+ public String runTimeVersion;
+
+ /**
+ * WEB-INF jar files.
+ */
+ public Set<String> packagedLibs = new HashSet<String>();
+
+ /**
+ * Transitive dependencies for extensions.
+ */
+ public Map<String, Set<String>> transDepenedencyMap = new HashMap<String, Set<String>>();
+
+ /**
+ * Executes the MOJO.
+ */
+ public void execute() throws MojoExecutionException {
+
+ JarFile originalWar;
+ JarOutputStream newWar = null;
+ File originalWarFile = null;
+ File newWarFile = null;
+
+ boolean success = false;
+
+ if (runTimeVersion == null) {
+ try {
+ runTimeVersion = getPluginVersion();
+ } catch (IOException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
+ }
+ }
+
+ if (bootLibs == null) {
+ Dependency dependancy = new Dependency("org.apache.tuscany.sca.runtime.webapp",
+ "webapp-host",
+ runTimeVersion);
+ bootLibs = new Dependency[] {dependancy};
+ }
+
+ try {
+ originalWarFile = new File(outputDirectory, warName + ".war");
+ originalWar = new JarFile(originalWarFile);
+
+ newWarFile = new File(outputDirectory, warName + "-temp.war");
+ newWar = new JarOutputStream(new FileOutputStream(newWarFile));
+
+ copyOriginal(originalWar, newWar);
+
+ addEntry(newWar, TUSCANY_PATH);
+ addEntry(newWar, BOOT_PATH);
+ addEntry(newWar, EXTENSION_PATH);
+ addEntry(newWar, REPOSITORY_PATH);
+
+ for (Dependency dependency : bootLibs) {
+ for (Artifact art : resolveArtifact(dependency.getArtifact(artifactFactory), true)) {
+ addArtifact(newWar, BOOT_PATH, art);
+ }
+ }
+
+ for (Dependency dependency : extensions) {
+ for (Artifact art : resolveArtifact(dependency.getArtifact(artifactFactory), loadExtensionDependencies)) {
+ if (dependency.match(art)) {
+ addArtifact(newWar, EXTENSION_PATH, art);
+ }
+
+ // Load dependencies even for the extension itself
+ if (loadExtensionDependencies) {
+ loadTransitiveDependencies(newWar, art);
+ }
+
+ }
+ }
+
+ for (Dependency dependency : dependencies) {
+ for (Artifact art : resolveArtifact(dependency.getArtifact(artifactFactory), loadExtensionDependencies)) {
+ loadTransitiveDependencies(newWar, art);
+ }
+ }
+
+ writeDependencyMetadata(newWar);
+
+ success = true;
+
+ } catch (Exception ex) {
+ throw new MojoExecutionException(ex.getMessage(), ex);
+ } finally {
+ IOUtils.closeQuietly(newWar);
+ }
+
+ if (success) {
+ if (!originalWarFile.delete()) {
+ throw new MojoExecutionException("Unable to rename war file");
+ }
+ if (!newWarFile.renameTo(originalWarFile)) {
+ throw new MojoExecutionException("Unable to rename war file");
+ }
+ }
+
+ }
+
+ /**
+ * Adds an entry to the JAR failing safe for duplicate.
+ *
+ * @param jar JAR to which the entry is added.
+ * @param entry Entry to be added.
+ * @return True if added successfully.
+ * @throws IOException In case of an IO error.
+ */
+ private boolean addEntry(JarOutputStream jar, String entry) throws IOException {
+ try {
+ jar.putNextEntry(new JarEntry(entry));
+ return true;
+ } catch (ZipException duplicateEntry) {
+ getLog().info(duplicateEntry.getMessage());
+ return false;
+ }
+ }
+
+ /**
+ * Writes the dependency metadata.
+ * @param newWar WAR to which the metadata is written.
+ * @throws IOException In case of an IO error.
+ */
+ private void writeDependencyMetadata(JarOutputStream newWar) throws IOException {
+
+ FileOutputStream depMapOutStream = null;
+ FileInputStream depMapInStream = null;
+
+ try {
+ String metadataFile = "dependency.metadata";
+
+ File file = new File(outputDirectory, "webapp");
+ file = new File(file, REPOSITORY_PATH);
+ file.mkdirs();
+
+ file = new File(file, metadataFile);
+ file.createNewFile();
+
+ depMapOutStream = new FileOutputStream(file);
+ XMLEncoder xmlEncoder = new XMLEncoder(depMapOutStream);
+ xmlEncoder.writeObject(transDepenedencyMap);
+ xmlEncoder.close();
+
+ if (addEntry(newWar, REPOSITORY_PATH + metadataFile)) {
+ depMapInStream = new FileInputStream(file);
+ IOUtils.copy(depMapInStream, newWar);
+ }
+
+ } finally {
+ IOUtils.closeQuietly(depMapOutStream);
+ IOUtils.closeQuietly(depMapInStream);
+ }
+
+ }
+
+ /**
+ * Builds the transitive dependencies for artifacts.
+ *
+ * @param newWar WARto which the artifacts are added.
+ * @param art Extension artifact.
+ * @throws IOException In case of an unexpected IO error.
+ * @throws ArtifactResolutionException If the artifact cannot be resolved.
+ * @throws ArtifactNotFoundException If the artifact is not found.
+ * @throws ArtifactMetadataRetrievalException In case of error in retrieving metadata.
+ */
+ private void loadTransitiveDependencies(JarOutputStream newWar, Artifact art) throws IOException, ArtifactResolutionException,
+ ArtifactNotFoundException, ArtifactMetadataRetrievalException {
+
+ String artPath = art.getGroupId() + "/" + art.getArtifactId() + "/" + art.getVersion() + "/";
+ String path = REPOSITORY_PATH + artPath;
+ addArtifact(newWar, path, art);
+
+ Set<String> transDepenedenyList = new HashSet<String>();
+ transDepenedencyMap.put(artPath, transDepenedenyList);
+
+ // Get the transitive dependencies for each dependency.
+ for (Artifact transArt : resolveArtifact(art, true)) {
+ String transArtPath = transArt.getGroupId() + "/" + transArt.getArtifactId() + "/" + transArt.getVersion() + "/";
+ if (addArtifact(newWar, REPOSITORY_PATH + transArtPath, transArt)) {
+ transDepenedenyList.add(transArtPath + transArt.getFile().getName());
+ }
+ }
+
+ }
+
+ /**
+ * Resolves the specified artifact.
+ *
+ * @param artifact Artifact to be resolved.
+ * @param transitive Whether to resolve transitively.
+ * @return A set of resolved artifacts.
+ * @throws IOException In case of an unexpected IO error.
+ * @throws ArtifactResolutionException If the artifact cannot be resolved.
+ * @throws ArtifactNotFoundException If the artifact is not found.
+ * @throws ArtifactMetadataRetrievalException In case of error in retrieving metadata.
+ */
+ private Set<Artifact> resolveArtifact(Artifact artifact, boolean transitive) throws IOException, ArtifactResolutionException,
+ ArtifactNotFoundException, ArtifactMetadataRetrievalException {
+
+ Set<Artifact> resolvedArtifacts = new HashSet<Artifact>();
+
+ // Resolve the artifact
+ resolver.resolve(artifact, remoteRepositories, localRepository);
+ resolvedArtifacts.add(artifact);
+
+ if (!transitive) {
+ return resolvedArtifacts;
+ }
+
+ // Transitively resolve all the dependencies
+ ResolutionGroup resolutionGroup = metadataSource.retrieve(artifact, localRepository, remoteRepositories);
+ ArtifactResolutionResult result = resolver.resolveTransitively(resolutionGroup.getArtifacts(), artifact, remoteRepositories, localRepository,
+ metadataSource);
+
+ // Add the artifacts to the deployment unit
+ for (Object depArtifact : result.getArtifacts()) {
+ resolvedArtifacts.add((Artifact) depArtifact);
+ }
+ return resolvedArtifacts;
+
+ }
+
+ /**
+ * Adds the artifact to the war file.
+ *
+ * @param newWar War file to which the artifact is added.
+ * @param path Path within the war file where artifact is added.
+ * @param artifact Artifact to be added.
+ * @throws IOException In case of an unexpected IO error.
+ * @return true if the artifact was added
+ */
+ private boolean addArtifact(JarOutputStream newWar, String path, Artifact artifact) throws IOException {
+
+ FileInputStream artifactStream = null;
+ FileOutputStream fileOutputStream = null;
+
+ try {
+
+ File artifactFile = artifact.getFile();
+ // For extensions, we'll add it even the packagedLibs has it
+ if ((!EXTENSION_PATH.equals(path)) && packagedLibs.contains(artifactFile.getName())) {
+ return false;
+ }
+ artifactStream = new FileInputStream(artifactFile);
+
+ newWar.putNextEntry(new JarEntry(path + artifactFile.getName()));
+
+ File file = new File(outputDirectory, "webapp");
+ file = new File(file, path);
+ file.mkdirs();
+
+ file = new File(file, artifactFile.getName());
+ fileOutputStream = new FileOutputStream(file);
+
+ IOUtils.copy(artifactStream, fileOutputStream);
+ IOUtils.closeQuietly(artifactStream);
+
+ artifactStream = new FileInputStream(artifactFile);
+ IOUtils.copy(artifactStream, newWar);
+
+ packagedLibs.add(artifactFile.getName());
+
+ getLog().info("Processed " + path + artifactFile.getName());
+
+ return true;
+
+ } finally {
+ IOUtils.closeQuietly(artifactStream);
+ IOUtils.closeQuietly(fileOutputStream);
+ }
+
+ }
+
+ /**
+ * Copies the original war file.
+ *
+ * @param originalWar Original war file.
+ * @param newWar New war file.
+ * @throws IOException In case of an unexpected IO error.
+ */
+ private void copyOriginal(JarFile originalWar, JarOutputStream newWar) throws IOException {
+
+ Enumeration entries = originalWar.entries();
+ packagedLibs.clear();
+
+ while (entries.hasMoreElements()) {
+
+ JarEntry entry = (JarEntry) entries.nextElement();
+ InputStream jarEntryStream = null;
+
+ try {
+ jarEntryStream = originalWar.getInputStream(entry);
+ newWar.putNextEntry(entry);
+ IOUtils.copy(jarEntryStream, newWar);
+ String name = entry.getName();
+
+ if (name.endsWith(".jar")) {
+ packagedLibs.add(name.substring(name.lastIndexOf("/") + 1));
+ }
+ } finally {
+ IOUtils.closeQuietly(jarEntryStream);
+ }
+
+ }
+
+ originalWar.close();
+
+ }
+
+ private String getPluginVersion() throws IOException {
+ Properties pomProperties = new Properties();
+ String propFile = "/META-INF/maven/org.apache.tuscany/tuscany-war-plugin/pom.properties";
+ InputStream is = getClass().getResourceAsStream(propFile);
+ try {
+ pomProperties.load(is);
+ return pomProperties.getProperty("version");
+ } finally {
+ IOUtils.closeQuietly(is);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/plugin.war/src/site/apt/usage.apt b/tags/java/tsss-demo/runtime/webapp/plugin.war/src/site/apt/usage.apt
new file mode 100644
index 0000000000..3a13e07e16
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/plugin.war/src/site/apt/usage.apt
@@ -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.
+
+Usage
+
+ The <<<tuscany-war-plugin>>> is associated with the <<<package>>> phase of the build lifecycle
+ and is typically included in the build definition for your project:
+
++---+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-war-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>tuscany-war</id>
+ <goals>
+ <goal>tuscany-war</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
++---+
+
+ The plugin adds the jars needed by the webapp integration code into WEB-INF/lib
+ so that they are included on the web application's classpath.
+
+ It also adds the jars needed by the webapp runtime into WEB-INF/tuscany/lib.
+ These are loaded by the integration code and do not appear on the web application's classpath. \ No newline at end of file
diff --git a/tags/java/tsss-demo/runtime/webapp/plugin.war/src/site/site.xml b/tags/java/tsss-demo/runtime/webapp/plugin.war/src/site/site.xml
new file mode 100644
index 0000000000..caa04a13fe
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/plugin.war/src/site/site.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project>
+ <body>
+ <menu name="Overview">
+ <item name="Introduction" href="index.html"/>
+ <item name="Goals" href="plugin-info.html"/>
+ <item name="Usage" href="usage.html"/>
+<!--
+ <item name="FAQ" href="faq.html"/>
+-->
+ </menu>
+<!--
+ <menu name="Examples">
+ </menu>
+-->
+ </body>
+</project>
diff --git a/tags/java/tsss-demo/runtime/webapp/pom.xml b/tags/java/tsss-demo/runtime/webapp/pom.xml
new file mode 100644
index 0000000000..829065b201
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/pom.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>runtime</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.runtime</groupId>
+ <artifactId>webapp</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache Tuscany Webapp SCA Runtime</name>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <profiles>
+ <profile>
+ <id>default</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <modules>
+ <module>webapp-api</module>
+ <module>webapp-host</module>
+ <module>plugin.war</module>
+ <module>smoketest</module>
+ </modules>
+ </profile>
+
+ <profile>
+ <!-- for the release profile exclude the smoketest as the gpg plugin cannot handle war packaging -->
+ <id>release</id>
+ <modules>
+ <module>webapp-api</module>
+ <module>webapp-host</module>
+ <module>plugin.war</module>
+ </modules>
+ </profile>
+ </profiles>
+</project>
diff --git a/tags/java/tsss-demo/runtime/webapp/smoketest/LICENSE.txt b/tags/java/tsss-demo/runtime/webapp/smoketest/LICENSE.txt
new file mode 100644
index 0000000000..9601ead3f6
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/smoketest/LICENSE.txt
@@ -0,0 +1,1407 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+APACHE TUSCANY SUBCOMPONENTS:
+
+The Apache Tuscany distribution includes a number of subcomponents with
+separate copyright notices and license terms. Your use of the source
+code for the these subcomponents is subject to the terms and
+conditions of the following licenses.
+
+===============================================================================
+
+For the Eclipse Modeling Framework component and the Celtix binding:
+
+Eclipse Public License - v 1.0
+
+THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
+PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF
+THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
+
+1. DEFINITIONS
+
+"Contribution" means:
+
+a) in the case of the initial Contributor, the initial code and
+documentation distributed under this Agreement, and
+b) in the case of each subsequent Contributor:
+
+i) changes to the Program, and
+
+ii) additions to the Program;
+
+where such changes and/or additions to the Program originate from and
+are distributed by that particular Contributor. A Contribution
+'originates' from a Contributor if it was added to the Program by such
+Contributor itself or anyone acting on such Contributor's behalf.
+Contributions do not include additions to the Program which: (i) are
+separate modules of software distributed in conjunction with the
+Program under their own license agreement, and (ii) are not derivative
+works of the Program.
+
+"Contributor" means any person or entity that distributes the Program.
+
+"Licensed Patents " mean patent claims licensable by a Contributor
+which are necessarily infringed by the use or sale of its Contribution
+alone or when combined with the Program.
+
+"Program" means the Contributions distributed in accordance with this
+Agreement.
+
+"Recipient" means anyone who receives the Program under this
+Agreement, including all Contributors.
+
+2. GRANT OF RIGHTS
+
+a) Subject to the terms of this Agreement, each Contributor hereby
+grants Recipient a non-exclusive, worldwide, royalty-free copyright
+license to reproduce, prepare derivative works of, publicly display,
+publicly perform, distribute and sublicense the Contribution of such
+Contributor, if any, and such derivative works, in source code and
+object code form.
+
+b) Subject to the terms of this Agreement, each Contributor hereby
+grants Recipient a non-exclusive, worldwide, royalty-free patent
+license under Licensed Patents to make, use, sell, offer to sell,
+import and otherwise transfer the Contribution of such Contributor, if
+any, in source code and object code form. This patent license shall
+apply to the combination of the Contribution and the Program if, at
+the time the Contribution is added by the Contributor, such addition
+of the Contribution causes such combination to be covered by the
+Licensed Patents. The patent license shall not apply to any other
+combinations which include the Contribution. No hardware per se is
+licensed hereunder.
+
+c) Recipient understands that although each Contributor grants the
+licenses to its Contributions set forth herein, no assurances are
+provided by any Contributor that the Program does not infringe the
+patent or other intellectual property rights of any other entity. Each
+Contributor disclaims any liability to Recipient for claims brought by
+any other entity based on infringement of intellectual property rights
+or otherwise. As a condition to exercising the rights and licenses
+granted hereunder, each Recipient hereby assumes sole responsibility
+to secure any other intellectual property rights needed, if any. For
+example, if a third party patent license is required to allow
+Recipient to distribute the Program, it is Recipient's responsibility
+to acquire that license before distributing the Program.
+
+d) Each Contributor represents that to its knowledge it has sufficient
+copyright rights in its Contribution, if any, to grant the copyright
+license set forth in this Agreement.
+
+3. REQUIREMENTS
+
+A Contributor may choose to distribute the Program in object code form
+under its own license agreement, provided that:
+
+a) it complies with the terms and conditions of this Agreement; and
+
+b) its license agreement:
+
+i) effectively disclaims on behalf of all Contributors all warranties
+and conditions, express and implied, including warranties or
+conditions of title and non-infringement, and implied warranties or
+conditions of merchantability and fitness for a particular purpose;
+
+ii) effectively excludes on behalf of all Contributors all liability
+for damages, including direct, indirect, special, incidental and
+consequential damages, such as lost profits;
+
+iii) states that any provisions which differ from this Agreement are
+offered by that Contributor alone and not by any other party; and
+
+iv) states that source code for the Program is available from such
+Contributor, and informs licensees how to obtain it in a reasonable
+manner on or through a medium customarily used for software exchange.
+
+When the Program is made available in source code form:
+
+a) it must be made available under this Agreement; and
+
+b) a copy of this Agreement must be included with each copy of the
+Program.
+
+Contributors may not remove or alter any copyright notices contained
+within the Program.
+
+Each Contributor must identify itself as the originator of its
+Contribution, if any, in a manner that reasonably allows subsequent
+Recipients to identify the originator of the Contribution.
+
+4. COMMERCIAL DISTRIBUTION
+
+Commercial distributors of software may accept certain
+responsibilities with respect to end users, business partners and the
+like. While this license is intended to facilitate the commercial use
+of the Program, the Contributor who includes the Program in a
+commercial product offering should do so in a manner which does not
+create potential liability for other Contributors. Therefore, if a
+Contributor includes the Program in a commercial product offering,
+such Contributor ("Commercial Contributor") hereby agrees to defend
+and indemnify every other Contributor ("Indemnified Contributor")
+against any losses, damages and costs (collectively "Losses") arising
+from claims, lawsuits and other legal actions brought by a third party
+against the Indemnified Contributor to the extent caused by the acts
+or omissions of such Commercial Contributor in connection with its
+distribution of the Program in a commercial product offering. The
+obligations in this section do not apply to any claims or Losses
+relating to any actual or alleged intellectual property infringement.
+In order to qualify, an Indemnified Contributor must: a) promptly
+notify the Commercial Contributor in writing of such claim, and b)
+allow the Commercial Contributor to control, and cooperate with the
+Commercial Contributor in, the defense and any related settlement
+negotiations. The Indemnified Contributor may participate in any such
+claim at its own expense.
+
+For example, a Contributor might include the Program in a commercial
+product offering, Product X. That Contributor is then a Commercial
+Contributor. If that Commercial Contributor then makes performance
+claims, or offers warranties related to Product X, those performance
+claims and warranties are such Commercial Contributor's responsibility
+alone. Under this section, the Commercial Contributor would have to
+defend claims against the other Contributors related to those
+performance claims and warranties, and if a court requires any other
+Contributor to pay any damages as a result, the Commercial Contributor
+must pay those damages.
+
+5. NO WARRANTY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
+PROVIDED 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. Each Recipient is solely
+responsible for determining the appropriateness of using and
+distributing the Program and assumes all risks associated with its
+exercise of rights under this Agreement , including but not limited to
+the risks and costs of program errors, compliance with applicable
+laws, damage to or loss of data, programs or equipment, and
+unavailability or interruption of operations.
+
+6. DISCLAIMER OF LIABILITY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR
+ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING
+WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR
+DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+7. GENERAL
+
+If any provision of this Agreement is invalid or unenforceable under
+applicable law, it shall not affect the validity or enforceability of
+the remainder of the terms of this Agreement, and without further
+action by the parties hereto, such provision shall be reformed to the
+minimum extent necessary to make such provision valid and enforceable.
+
+If Recipient institutes patent litigation against any entity
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+the Program itself (excluding combinations of the Program with other
+software or hardware) infringes such Recipient's patent(s), then such
+Recipient's rights granted under Section 2(b) shall terminate as of
+the date such litigation is filed.
+
+All Recipient's rights under this Agreement shall terminate if it
+fails to comply with any of the material terms or conditions of this
+Agreement and does not cure such failure in a reasonable period of
+time after becoming aware of such noncompliance. If all Recipient's
+rights under this Agreement terminate, Recipient agrees to cease use
+and distribution of the Program as soon as reasonably practicable.
+However, Recipient's obligations under this Agreement and any licenses
+granted by Recipient relating to the Program shall continue and
+survive.
+
+Everyone is permitted to copy and distribute copies of this Agreement,
+but in order to avoid inconsistency the Agreement is copyrighted and
+may only be modified in the following manner. The Agreement Steward
+reserves the right to publish new versions (including revisions) of
+this Agreement from time to time. No one other than the Agreement
+Steward has the right to modify this Agreement. The Eclipse Foundation
+is the initial Agreement Steward. The Eclipse Foundation may assign
+the responsibility to serve as the Agreement Steward to a suitable
+separate entity. Each new version of the Agreement will be given a
+distinguishing version number. The Program (including Contributions)
+may always be distributed subject to the version of the Agreement
+under which it was received. In addition, after a new version of the
+Agreement is published, Contributor may elect to distribute the
+Program (including its Contributions) under the new version. Except as
+expressly stated in Sections 2(a) and 2(b) above, Recipient receives
+no rights or licenses to the intellectual property of any Contributor
+under this Agreement, whether expressly, by implication, estoppel or
+otherwise. All rights in the Program not expressly granted under this
+Agreement are reserved.
+
+This Agreement is governed by the laws of the State of New York and
+the intellectual property laws of the United States of America. No
+party to this Agreement will bring a legal action under this Agreement
+more than one year after the cause of action arose. Each party waives
+its rights to a jury trial in any resulting litigation.
+
+===============================================================================
+
+For the Rhino JavaScript container component:
+
+Netscape Public License V1.1
+
+ AMENDMENTS
+
+ The Netscape Public License Version 1.1 ("NPL") consists of the
+ Mozilla Public License Version 1.1 with the following Amendments,
+ including Exhibit A-Netscape Public License. Files identified with
+ "Exhibit A-Netscape Public License" are governed by the Netscape
+ Public License Version 1.1.
+
+ Additional Terms applicable to the Netscape Public License.
+ I. Effect.
+ These additional terms described in this Netscape Public
+ License -- Amendments shall apply to the Mozilla Communicator
+ client code and to all Covered Code under this License.
+
+ II. "Netscape's Branded Code" means Covered Code that Netscape
+ distributes and/or permits others to distribute under one or more
+ trademark(s) which are controlled by Netscape but which are not
+ licensed for use under this License.
+
+ III. Netscape and logo.
+ This License does not grant any rights to use the trademarks
+ "Netscape", the "Netscape N and horizon" logo or the "Netscape
+ lighthouse" logo, "Netcenter", "Gecko", "Java" or "JavaScript",
+ "Smart Browsing" even if such marks are included in the Original
+ Code or Modifications.
+
+ IV. Inability to Comply Due to Contractual Obligation.
+ Prior to licensing the Original Code under this License, Netscape
+ has licensed third party code for use in Netscape's Branded Code.
+ To the extent that Netscape is limited contractually from making
+ such third party code available under this License, Netscape may
+ choose to reintegrate such code into Covered Code without being
+ required to distribute such code in Source Code form, even if
+ such code would otherwise be considered "Modifications" under
+ this License.
+
+ V. Use of Modifications and Covered Code by Initial Developer.
+ V.1. In General.
+ The obligations of Section 3 apply to Netscape, except to
+ the extent specified in this Amendment, Section V.2 and V.3.
+
+ V.2. Other Products.
+ Netscape may include Covered Code in products other than the
+ Netscape's Branded Code which are released by Netscape
+ during the two (2) years following the release date of the
+ Original Code, without such additional products becoming
+ subject to the terms of this License, and may license such
+ additional products on different terms from those contained
+ in this License.
+
+ V.3. Alternative Licensing.
+ Netscape may license the Source Code of Netscape's Branded
+ Code, including Modifications incorporated therein, without
+ such Netscape Branded Code becoming subject to the terms of
+ this License, and may license such Netscape Branded Code on
+ different terms from those contained in this License.
+
+ VI. Litigation.
+ Notwithstanding the limitations of Section 11 above, the
+ provisions regarding litigation in Section 11(a), (b) and (c) of
+ the License shall apply to all disputes relating to this License.
+
+ EXHIBIT A-Netscape Public License.
+
+ "The contents of this file are subject to the Netscape Public
+ License Version 1.1 (the "License"); you may not use this file
+ except in compliance with the License. You may obtain a copy of
+ the License at http://www.mozilla.org/NPL/
+
+ Software distributed under the License is distributed on an "AS
+ IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ implied. See the License for the specific language governing
+ rights and limitations under the License.
+
+ The Original Code is Mozilla Communicator client code, released
+ March 31, 1998.
+
+ The Initial Developer of the Original Code is Netscape
+ Communications Corporation. Portions created by Netscape are
+ Copyright (C) 1998-1999 Netscape Communications Corporation. All
+ Rights Reserved.
+
+ Contributor(s): ______________________________________.
+
+ Alternatively, the contents of this file may be used under the
+ terms of the _____ license (the "[___] License"), in which case
+ the provisions of [______] License are applicable instead of
+ those above. If you wish to allow use of your version of this
+ file only under the terms of the [____] License and not to allow
+ others to use your version of this file under the NPL, indicate
+ your decision by deleting the provisions above and replace them
+ with the notice and other provisions required by the [___]
+ License. If you do not delete the provisions above, a recipient
+ may use your version of this file under either the NPL or the
+ [___] License."
+
+ ----------------------------------------------------------------------
+
+ MOZILLA PUBLIC LICENSE
+ Version 1.1
+
+ ---------------
+
+1. Definitions.
+
+ 1.0.1. "Commercial Use" means distribution or otherwise making the
+ Covered Code available to a third party.
+
+ 1.1. "Contributor" means each entity that creates or contributes to
+ the creation of Modifications.
+
+ 1.2. "Contributor Version" means the combination of the Original
+ Code, prior Modifications used by a Contributor, and the Modifications
+ made by that particular Contributor.
+
+ 1.3. "Covered Code" means the Original Code or Modifications or the
+ combination of the Original Code and Modifications, in each case
+ including portions thereof.
+
+ 1.4. "Electronic Distribution Mechanism" means a mechanism generally
+ accepted in the software development community for the electronic
+ transfer of data.
+
+ 1.5. "Executable" means Covered Code in any form other than Source
+ Code.
+
+ 1.6. "Initial Developer" means the individual or entity identified
+ as the Initial Developer in the Source Code notice required by Exhibit
+ A.
+
+ 1.7. "Larger Work" means a work which combines Covered Code or
+ portions thereof with code not governed by the terms of this License.
+
+ 1.8. "License" means this document.
+
+ 1.8.1. "Licensable" means having the right to grant, to the maximum
+ extent possible, whether at the time of the initial grant or
+ subsequently acquired, any and all of the rights conveyed herein.
+
+ 1.9. "Modifications" means any addition to or deletion from the
+ substance or structure of either the Original Code or any previous
+ Modifications. When Covered Code is released as a series of files, a
+ Modification is:
+ A. Any addition to or deletion from the contents of a file
+ containing Original Code or previous Modifications.
+
+ B. Any new file that contains any part of the Original Code or
+ previous Modifications.
+
+ 1.10. "Original Code" means Source Code of computer software code
+ which is described in the Source Code notice required by Exhibit A as
+ Original Code, and which, at the time of its release under this
+ License is not already Covered Code governed by this License.
+
+ 1.10.1. "Patent Claims" means any patent claim(s), now owned or
+ hereafter acquired, including without limitation, method, process,
+ and apparatus claims, in any patent Licensable by grantor.
+
+ 1.11. "Source Code" means the preferred form of the Covered Code for
+ making modifications to it, including all modules it contains, plus
+ any associated interface definition files, scripts used to control
+ compilation and installation of an Executable, or source code
+ differential comparisons against either the Original Code or another
+ well known, available Covered Code of the Contributor's choice. The
+ Source Code can be in a compressed or archival form, provided the
+ appropriate decompression or de-archiving software is widely available
+ for no charge.
+
+ 1.12. "You" (or "Your") means an individual or a legal entity
+ exercising rights under, and complying with all of the terms of, this
+ License or a future version of this License issued under Section 6.1.
+ For legal entities, "You" includes any entity which controls, is
+ controlled by, or is under common control with You. For purposes of
+ this definition, "control" means (a) the power, direct or indirect,
+ to cause the direction or management of such entity, whether by
+ contract or otherwise, or (b) ownership of more than fifty percent
+ (50%) of the outstanding shares or beneficial ownership of such
+ entity.
+
+2. Source Code License.
+
+ 2.1. The Initial Developer Grant.
+ The Initial Developer hereby grants You a world-wide, royalty-free,
+ non-exclusive license, subject to third party intellectual property
+ claims:
+ (a) under intellectual property rights (other than patent or
+ trademark) Licensable by Initial Developer to use, reproduce,
+ modify, display, perform, sublicense and distribute the Original
+ Code (or portions thereof) with or without Modifications, and/or
+ as part of a Larger Work; and
+
+ (b) under Patents Claims infringed by the making, using or
+ selling of Original Code, to make, have made, use, practice,
+ sell, and offer for sale, and/or otherwise dispose of the
+ Original Code (or portions thereof).
+
+ (c) the licenses granted in this Section 2.1(a) and (b) are
+ effective on the date Initial Developer first distributes
+ Original Code under the terms of this License.
+
+ (d) Notwithstanding Section 2.1(b) above, no patent license is
+ granted: 1) for code that You delete from the Original Code; 2)
+ separate from the Original Code; or 3) for infringements caused
+ by: i) the modification of the Original Code or ii) the
+ combination of the Original Code with other software or devices.
+
+ 2.2. Contributor Grant.
+ Subject to third party intellectual property claims, each Contributor
+ hereby grants You a world-wide, royalty-free, non-exclusive license
+
+ (a) under intellectual property rights (other than patent or
+ trademark) Licensable by Contributor, to use, reproduce, modify,
+ display, perform, sublicense and distribute the Modifications
+ created by such Contributor (or portions thereof) either on an
+ unmodified basis, with other Modifications, as Covered Code
+ and/or as part of a Larger Work; and
+
+ (b) under Patent Claims infringed by the making, using, or
+ selling of Modifications made by that Contributor either alone
+ and/or in combination with its Contributor Version (or portions
+ of such combination), to make, use, sell, offer for sale, have
+ made, and/or otherwise dispose of: 1) Modifications made by that
+ Contributor (or portions thereof); and 2) the combination of
+ Modifications made by that Contributor with its Contributor
+ Version (or portions of such combination).
+
+ (c) the licenses granted in Sections 2.2(a) and 2.2(b) are
+ effective on the date Contributor first makes Commercial Use of
+ the Covered Code.
+
+ (d) Notwithstanding Section 2.2(b) above, no patent license is
+ granted: 1) for any code that Contributor has deleted from the
+ Contributor Version; 2) separate from the Contributor Version;
+ 3) for infringements caused by: i) third party modifications of
+ Contributor Version or ii) the combination of Modifications made
+ by that Contributor with other software (except as part of the
+ Contributor Version) or other devices; or 4) under Patent Claims
+ infringed by Covered Code in the absence of Modifications made by
+ that Contributor.
+
+3. Distribution Obligations.
+
+ 3.1. Application of License.
+ The Modifications which You create or to which You contribute are
+ governed by the terms of this License, including without limitation
+ Section 2.2. The Source Code version of Covered Code may be
+ distributed only under the terms of this License or a future version
+ of this License released under Section 6.1, and You must include a
+ copy of this License with every copy of the Source Code You
+ distribute. You may not offer or impose any terms on any Source Code
+ version that alters or restricts the applicable version of this
+ License or the recipients' rights hereunder. However, You may include
+ an additional document offering the additional rights described in
+ Section 3.5.
+
+ 3.2. Availability of Source Code.
+ Any Modification which You create or to which You contribute must be
+ made available in Source Code form under the terms of this License
+ either on the same media as an Executable version or via an accepted
+ Electronic Distribution Mechanism to anyone to whom you made an
+ Executable version available; and if made available via Electronic
+ Distribution Mechanism, must remain available for at least twelve (12)
+ months after the date it initially became available, or at least six
+ (6) months after a subsequent version of that particular Modification
+ has been made available to such recipients. You are responsible for
+ ensuring that the Source Code version remains available even if the
+ Electronic Distribution Mechanism is maintained by a third party.
+
+ 3.3. Description of Modifications.
+ You must cause all Covered Code to which You contribute to contain a
+ file documenting the changes You made to create that Covered Code and
+ the date of any change. You must include a prominent statement that
+ the Modification is derived, directly or indirectly, from Original
+ Code provided by the Initial Developer and including the name of the
+ Initial Developer in (a) the Source Code, and (b) in any notice in an
+ Executable version or related documentation in which You describe the
+ origin or ownership of the Covered Code.
+
+ 3.4. Intellectual Property Matters
+ (a) Third Party Claims.
+ If Contributor has knowledge that a license under a third party's
+ intellectual property rights is required to exercise the rights
+ granted by such Contributor under Sections 2.1 or 2.2,
+ Contributor must include a text file with the Source Code
+ distribution titled "LEGAL" which describes the claim and the
+ party making the claim in sufficient detail that a recipient will
+ know whom to contact. If Contributor obtains such knowledge after
+ the Modification is made available as described in Section 3.2,
+ Contributor shall promptly modify the LEGAL file in all copies
+ Contributor makes available thereafter and shall take other steps
+ (such as notifying appropriate mailing lists or newsgroups)
+ reasonably calculated to inform those who received the Covered
+ Code that new knowledge has been obtained.
+
+ (b) Contributor APIs.
+ If Contributor's Modifications include an application programming
+ interface and Contributor has knowledge of patent licenses which
+ are reasonably necessary to implement that API, Contributor must
+ also include this information in the LEGAL file.
+
+ (c) Representations.
+ Contributor represents that, except as disclosed pursuant to
+ Section 3.4(a) above, Contributor believes that Contributor's
+ Modifications are Contributor's original creation(s) and/or
+ Contributor has sufficient rights to grant the rights conveyed by
+ this License.
+
+ 3.5. Required Notices.
+ You must duplicate the notice in Exhibit A in each file of the Source
+ Code. If it is not possible to put such notice in a particular Source
+ Code file due to its structure, then You must include such notice in a
+ location (such as a relevant directory) where a user would be likely
+ to look for such a notice. If You created one or more Modification(s)
+ You may add your name as a Contributor to the notice described in
+ Exhibit A. You must also duplicate this License in any documentation
+ for the Source Code where You describe recipients' rights or ownership
+ rights relating to Covered Code. You may choose to offer, and to
+ charge a fee for, warranty, support, indemnity or liability
+ obligations to one or more recipients of Covered Code. However, You
+ may do so only on Your own behalf, and not on behalf of the Initial
+ Developer or any Contributor. You must make it absolutely clear than
+ any such warranty, support, indemnity or liability obligation is
+ offered by You alone, and You hereby agree to indemnify the Initial
+ Developer and every Contributor for any liability incurred by the
+ Initial Developer or such Contributor as a result of warranty,
+ support, indemnity or liability terms You offer.
+
+ 3.6. Distribution of Executable Versions.
+ You may distribute Covered Code in Executable form only if the
+ requirements of Section 3.1-3.5 have been met for that Covered Code,
+ and if You include a notice stating that the Source Code version of
+ the Covered Code is available under the terms of this License,
+ including a description of how and where You have fulfilled the
+ obligations of Section 3.2. The notice must be conspicuously included
+ in any notice in an Executable version, related documentation or
+ collateral in which You describe recipients' rights relating to the
+ Covered Code. You may distribute the Executable version of Covered
+ Code or ownership rights under a license of Your choice, which may
+ contain terms different from this License, provided that You are in
+ compliance with the terms of this License and that the license for the
+ Executable version does not attempt to limit or alter the recipient's
+ rights in the Source Code version from the rights set forth in this
+ License. If You distribute the Executable version under a different
+ license You must make it absolutely clear that any terms which differ
+ from this License are offered by You alone, not by the Initial
+ Developer or any Contributor. You hereby agree to indemnify the
+ Initial Developer and every Contributor for any liability incurred by
+ the Initial Developer or such Contributor as a result of any such
+ terms You offer.
+
+ 3.7. Larger Works.
+ You may create a Larger Work by combining Covered Code with other code
+ not governed by the terms of this License and distribute the Larger
+ Work as a single product. In such a case, You must make sure the
+ requirements of this License are fulfilled for the Covered Code.
+
+4. Inability to Comply Due to Statute or Regulation.
+
+ If it is impossible for You to comply with any of the terms of this
+ License with respect to some or all of the Covered Code due to
+ statute, judicial order, or regulation then You must: (a) comply with
+ the terms of this License to the maximum extent possible; and (b)
+ describe the limitations and the code they affect. Such description
+ must be included in the LEGAL file described in Section 3.4 and must
+ be included with all distributions of the Source Code. Except to the
+ extent prohibited by statute or regulation, such description must be
+ sufficiently detailed for a recipient of ordinary skill to be able to
+ understand it.
+
+5. Application of this License.
+
+ This License applies to code to which the Initial Developer has
+ attached the notice in Exhibit A and to related Covered Code.
+
+6. Versions of the License.
+
+ 6.1. New Versions.
+ Netscape Communications Corporation ("Netscape") may publish revised
+ and/or new versions of the License from time to time. Each version
+ will be given a distinguishing version number.
+
+ 6.2. Effect of New Versions.
+ Once Covered Code has been published under a particular version of the
+ License, You may always continue to use it under the terms of that
+ version. You may also choose to use such Covered Code under the terms
+ of any subsequent version of the License published by Netscape. No one
+ other than Netscape has the right to modify the terms applicable to
+ Covered Code created under this License.
+
+ 6.3. Derivative Works.
+ If You create or use a modified version of this License (which you may
+ only do in order to apply it to code which is not already Covered Code
+ governed by this License), You must (a) rename Your license so that
+ the phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape",
+ "MPL", "NPL" or any confusingly similar phrase do not appear in your
+ license (except to note that your license differs from this License)
+ and (b) otherwise make it clear that Your version of the license
+ contains terms which differ from the Mozilla Public License and
+ Netscape Public License. (Filling in the name of the Initial
+ Developer, Original Code or Contributor in the notice described in
+ Exhibit A shall not of themselves be deemed to be modifications of
+ this License.)
+
+7. DISCLAIMER OF WARRANTY.
+
+ COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF
+ DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING.
+ THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE
+ IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT,
+ YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE
+ COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER
+ OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF
+ ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
+
+8. TERMINATION.
+
+ 8.1. This License and the rights granted hereunder will terminate
+ automatically if You fail to comply with terms herein and fail to cure
+ such breach within 30 days of becoming aware of the breach. All
+ sublicenses to the Covered Code which are properly granted shall
+ survive any termination of this License. Provisions which, by their
+ nature, must remain in effect beyond the termination of this License
+ shall survive.
+
+ 8.2. If You initiate litigation by asserting a patent infringement
+ claim (excluding declatory judgment actions) against Initial Developer
+ or a Contributor (the Initial Developer or Contributor against whom
+ You file such action is referred to as "Participant") alleging that:
+
+ (a) such Participant's Contributor Version directly or indirectly
+ infringes any patent, then any and all rights granted by such
+ Participant to You under Sections 2.1 and/or 2.2 of this License
+ shall, upon 60 days notice from Participant terminate prospectively,
+ unless if within 60 days after receipt of notice You either: (i)
+ agree in writing to pay Participant a mutually agreeable reasonable
+ royalty for Your past and future use of Modifications made by such
+ Participant, or (ii) withdraw Your litigation claim with respect to
+ the Contributor Version against such Participant. If within 60 days
+ of notice, a reasonable royalty and payment arrangement are not
+ mutually agreed upon in writing by the parties or the litigation claim
+ is not withdrawn, the rights granted by Participant to You under
+ Sections 2.1 and/or 2.2 automatically terminate at the expiration of
+ the 60 day notice period specified above.
+
+ (b) any software, hardware, or device, other than such Participant's
+ Contributor Version, directly or indirectly infringes any patent, then
+ any rights granted to You by such Participant under Sections 2.1(b)
+ and 2.2(b) are revoked effective as of the date You first made, used,
+ sold, distributed, or had made, Modifications made by that
+ Participant.
+
+ 8.3. If You assert a patent infringement claim against Participant
+ alleging that such Participant's Contributor Version directly or
+ indirectly infringes any patent where such claim is resolved (such as
+ by license or settlement) prior to the initiation of patent
+ infringement litigation, then the reasonable value of the licenses
+ granted by such Participant under Sections 2.1 or 2.2 shall be taken
+ into account in determining the amount or value of any payment or
+ license.
+
+ 8.4. In the event of termination under Sections 8.1 or 8.2 above,
+ all end user license agreements (excluding distributors and resellers)
+ which have been validly granted by You or any distributor hereunder
+ prior to termination shall survive termination.
+
+9. LIMITATION OF LIABILITY.
+
+ UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
+ (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL
+ DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE,
+ OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR
+ ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY
+ CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL,
+ WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER
+ COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN
+ INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF
+ LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY
+ RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW
+ PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE
+ EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO
+ THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
+
+10. U.S. GOVERNMENT END USERS.
+
+ The Covered Code is a "commercial item," as that term is defined in
+ 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer
+ software" and "commercial computer software documentation," as such
+ terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48
+ C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995),
+ all U.S. Government End Users acquire Covered Code with only those
+ rights set forth herein.
+
+11. MISCELLANEOUS.
+
+ This License represents the complete agreement concerning subject
+ matter hereof. If any provision of this License is held to be
+ unenforceable, such provision shall be reformed only to the extent
+ necessary to make it enforceable. This License shall be governed by
+ California law provisions (except to the extent applicable law, if
+ any, provides otherwise), excluding its conflict-of-law provisions.
+ With respect to disputes in which at least one party is a citizen of,
+ or an entity chartered or registered to do business in the United
+ States of America, any litigation relating to this License shall be
+ subject to the jurisdiction of the Federal Courts of the Northern
+ District of California, with venue lying in Santa Clara County,
+ California, with the losing party responsible for costs, including
+ without limitation, court costs and reasonable attorneys' fees and
+ expenses. The application of the United Nations Convention on
+ Contracts for the International Sale of Goods is expressly excluded.
+ Any law or regulation which provides that the language of a contract
+ shall be construed against the drafter shall not apply to this
+ License.
+
+12. RESPONSIBILITY FOR CLAIMS.
+
+ As between Initial Developer and the Contributors, each party is
+ responsible for claims and damages arising, directly or indirectly,
+ out of its utilization of rights under this License and You agree to
+ work with Initial Developer and Contributors to distribute such
+ responsibility on an equitable basis. Nothing herein is intended or
+ shall be deemed to constitute any admission of liability.
+
+13. MULTIPLE-LICENSED CODE.
+
+ Initial Developer may designate portions of the Covered Code as
+ "Multiple-Licensed". "Multiple-Licensed" means that the Initial
+ Developer permits you to utilize portions of the Covered Code under
+ Your choice of the NPL or the alternative licenses, if any, specified
+ by the Initial Developer in the file described in Exhibit A.
+
+EXHIBIT A -Mozilla Public License.
+
+ ``The contents of this file are subject to the Mozilla Public License
+ Version 1.1 (the "License"); you may not use this file except in
+ compliance with the License. You may obtain a copy of the License at
+ http://www.mozilla.org/MPL/
+
+ Software distributed under the License is distributed on an "AS IS"
+ basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ License for the specific language governing rights and limitations
+ under the License.
+
+ The Original Code is ______________________________________.
+
+ The Initial Developer of the Original Code is ________________________.
+ Portions created by ______________________ are Copyright (C) ______
+ _______________________. All Rights Reserved.
+
+ Contributor(s): ______________________________________.
+
+ Alternatively, the contents of this file may be used under the terms
+ of the _____ license (the "[___] License"), in which case the
+ provisions of [______] License are applicable instead of those
+ above. If you wish to allow use of your version of this file only
+ under the terms of the [____] License and not to allow others to use
+ your version of this file under the MPL, indicate your decision by
+ deleting the provisions above and replace them with the notice and
+ other provisions required by the [___] License. If you do not delete
+ the provisions above, a recipient may use your version of this file
+ under either the MPL or the [___] License."
+
+ [NOTE: The text of this Exhibit A may differ slightly from the text of
+ the notices in the Source Code files of the Original Code. You should
+ use the text of this Exhibit A rather than the text found in the
+ Original Code Source Code for Your Modifications.]
+
+
+===============================================================================
+
+For the JAX-WS Reference Implementation component:
+
+COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
+
+
+ 1. Definitions.
+
+ 1.1. "Contributor" means each individual or entity that
+ creates or contributes to the creation of Modifications.
+
+ 1.2. "Contributor Version" means the combination of the
+ Original Software, prior Modifications used by a
+ Contributor (if any), and the Modifications made by that
+ particular Contributor.
+
+ 1.3. "Covered Software" means (a) the Original Software, or
+ (b) Modifications, or (c) the combination of files
+ containing Original Software with files containing
+ Modifications, in each case including portions thereof.
+
+ 1.4. "Executable" means the Covered Software in any form
+ other than Source Code.
+
+ 1.5. "Initial Developer" means the individual or entity
+ that first makes Original Software available under this
+ License.
+
+ 1.6. "Larger Work" means a work which combines Covered
+ Software or portions thereof with code not governed by the
+ terms of this License.
+
+ 1.7. "License" means this document.
+
+ 1.8. "Licensable" means having the right to grant, to the
+ maximum extent possible, whether at the time of the initial
+ grant or subsequently acquired, any and all of the rights
+ conveyed herein.
+
+ 1.9. "Modifications" means the Source Code and Executable
+ form of any of the following:
+
+ A. Any file that results from an addition to,
+ deletion from or modification of the contents of a
+ file containing Original Software or previous
+ Modifications;
+
+ B. Any new file that contains any part of the
+ Original Software or previous Modification; or
+
+ C. Any new file that is contributed or otherwise made
+ available under the terms of this License.
+
+ 1.10. "Original Software" means the Source Code and
+ Executable form of computer software code that is
+ originally released under this License.
+
+ 1.11. "Patent Claims" means any patent claim(s), now owned
+ or hereafter acquired, including without limitation,
+ method, process, and apparatus claims, in any patent
+ Licensable by grantor.
+
+ 1.12. "Source Code" means (a) the common form of computer
+ software code in which modifications are made and (b)
+ associated documentation included in or with such code.
+
+ 1.13. "You" (or "Your") means an individual or a legal
+ entity exercising rights under, and complying with all of
+ the terms of, this License. For legal entities, "You"
+ includes any entity which controls, is controlled by, or is
+ under common control with You. For purposes of this
+ definition, "control" means (a) the power, direct or
+ indirect, to cause the direction or management of such
+ entity, whether by contract or otherwise, or (b) ownership
+ of more than fifty percent (50%) of the outstanding shares
+ or beneficial ownership of such entity.
+
+ 2. License Grants.
+
+ 2.1. The Initial Developer Grant.
+
+ Conditioned upon Your compliance with Section 3.1 below and
+ subject to third party intellectual property claims, the
+ Initial Developer hereby grants You a world-wide,
+ royalty-free, non-exclusive license:
+
+ (a) under intellectual property rights (other than
+ patent or trademark) Licensable by Initial Developer,
+ to use, reproduce, modify, display, perform,
+ sublicense and distribute the Original Software (or
+ portions thereof), with or without Modifications,
+ and/or as part of a Larger Work; and
+
+ (b) under Patent Claims infringed by the making,
+ using or selling of Original Software, to make, have
+ made, use, practice, sell, and offer for sale, and/or
+ otherwise dispose of the Original Software (or
+ portions thereof).
+
+ (c) The licenses granted in Sections 2.1(a) and (b)
+ are effective on the date Initial Developer first
+ distributes or otherwise makes the Original Software
+ available to a third party under the terms of this
+ License.
+
+ (d) Notwithstanding Section 2.1(b) above, no patent
+ license is granted: (1) for code that You delete from
+ the Original Software, or (2) for infringements
+ caused by: (i) the modification of the Original
+ Software, or (ii) the combination of the Original
+ Software with other software or devices.
+
+ 2.2. Contributor Grant.
+
+ Conditioned upon Your compliance with Section 3.1 below and
+ subject to third party intellectual property claims, each
+ Contributor hereby grants You a world-wide, royalty-free,
+ non-exclusive license:
+
+ (a) under intellectual property rights (other than
+ patent or trademark) Licensable by Contributor to
+ use, reproduce, modify, display, perform, sublicense
+ and distribute the Modifications created by such
+ Contributor (or portions thereof), either on an
+ unmodified basis, with other Modifications, as
+ Covered Software and/or as part of a Larger Work; and
+
+
+ (b) under Patent Claims infringed by the making,
+ using, or selling of Modifications made by that
+ Contributor either alone and/or in combination with
+ its Contributor Version (or portions of such
+ combination), to make, use, sell, offer for sale,
+ have made, and/or otherwise dispose of: (1)
+ Modifications made by that Contributor (or portions
+ thereof); and (2) the combination of Modifications
+ made by that Contributor with its Contributor Version
+ (or portions of such combination).
+
+ (c) The licenses granted in Sections 2.2(a) and
+ 2.2(b) are effective on the date Contributor first
+ distributes or otherwise makes the Modifications
+ available to a third party.
+
+ (d) Notwithstanding Section 2.2(b) above, no patent
+ license is granted: (1) for any code that Contributor
+ has deleted from the Contributor Version; (2) for
+ infringements caused by: (i) third party
+ modifications of Contributor Version, or (ii) the
+ combination of Modifications made by that Contributor
+ with other software (except as part of the
+ Contributor Version) or other devices; or (3) under
+ Patent Claims infringed by Covered Software in the
+ absence of Modifications made by that Contributor.
+
+ 3. Distribution Obligations.
+
+ 3.1. Availability of Source Code.
+
+ Any Covered Software that You distribute or otherwise make
+ available in Executable form must also be made available in
+ Source Code form and that Source Code form must be
+ distributed only under the terms of this License. You must
+ include a copy of this License with every copy of the
+ Source Code form of the Covered Software You distribute or
+ otherwise make available. You must inform recipients of any
+ such Covered Software in Executable form as to how they can
+ obtain such Covered Software in Source Code form in a
+ reasonable manner on or through a medium customarily used
+ for software exchange.
+
+ 3.2. Modifications.
+
+ The Modifications that You create or to which You
+ contribute are governed by the terms of this License. You
+ represent that You believe Your Modifications are Your
+ original creation(s) and/or You have sufficient rights to
+ grant the rights conveyed by this License.
+
+ 3.3. Required Notices.
+
+ You must include a notice in each of Your Modifications
+ that identifies You as the Contributor of the Modification.
+ You may not remove or alter any copyright, patent or
+ trademark notices contained within the Covered Software, or
+ any notices of licensing or any descriptive text giving
+ attribution to any Contributor or the Initial Developer.
+
+ 3.4. Application of Additional Terms.
+
+ You may not offer or impose any terms on any Covered
+ Software in Source Code form that alters or restricts the
+ applicable version of this License or the recipients'
+ rights hereunder. You may choose to offer, and to charge a
+ fee for, warranty, support, indemnity or liability
+ obligations to one or more recipients of Covered Software.
+ However, you may do so only on Your own behalf, and not on
+ behalf of the Initial Developer or any Contributor. You
+ must make it absolutely clear that any such warranty,
+ support, indemnity or liability obligation is offered by
+ You alone, and You hereby agree to indemnify the Initial
+ Developer and every Contributor for any liability incurred
+ by the Initial Developer or such Contributor as a result of
+ warranty, support, indemnity or liability terms You offer.
+
+
+ 3.5. Distribution of Executable Versions.
+
+ You may distribute the Executable form of the Covered
+ Software under the terms of this License or under the terms
+ of a license of Your choice, which may contain terms
+ different from this License, provided that You are in
+ compliance with the terms of this License and that the
+ license for the Executable form does not attempt to limit
+ or alter the recipient's rights in the Source Code form
+ from the rights set forth in this License. If You
+ distribute the Covered Software in Executable form under a
+ different license, You must make it absolutely clear that
+ any terms which differ from this License are offered by You
+ alone, not by the Initial Developer or Contributor. You
+ hereby agree to indemnify the Initial Developer and every
+ Contributor for any liability incurred by the Initial
+ Developer or such Contributor as a result of any such terms
+ You offer.
+
+ 3.6. Larger Works.
+
+ You may create a Larger Work by combining Covered Software
+ with other code not governed by the terms of this License
+ and distribute the Larger Work as a single product. In such
+ a case, You must make sure the requirements of this License
+ are fulfilled for the Covered Software.
+
+ 4. Versions of the License.
+
+ 4.1. New Versions.
+
+ Sun Microsystems, Inc. is the initial license steward and
+ may publish revised and/or new versions of this License
+ from time to time. Each version will be given a
+ distinguishing version number. Except as provided in
+ Section 4.3, no one other than the license steward has the
+ right to modify this License.
+
+ 4.2. Effect of New Versions.
+
+ You may always continue to use, distribute or otherwise
+ make the Covered Software available under the terms of the
+ version of the License under which You originally received
+ the Covered Software. If the Initial Developer includes a
+ notice in the Original Software prohibiting it from being
+ distributed or otherwise made available under any
+ subsequent version of the License, You must distribute and
+ make the Covered Software available under the terms of the
+ version of the License under which You originally received
+ the Covered Software. Otherwise, You may also choose to
+ use, distribute or otherwise make the Covered Software
+ available under the terms of any subsequent version of the
+ License published by the license steward.
+
+ 4.3. Modified Versions.
+
+ When You are an Initial Developer and You want to create a
+ new license for Your Original Software, You may create and
+ use a modified version of this License if You: (a) rename
+ the license and remove any references to the name of the
+ license steward (except to note that the license differs
+ from this License); and (b) otherwise make it clear that
+ the license contains terms which differ from this License.
+
+
+ 5. DISCLAIMER OF WARRANTY.
+
+ COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS"
+ BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
+ INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED
+ SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR
+ PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND
+ PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY
+ COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE
+ INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF
+ ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF
+ WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF
+ ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS
+ DISCLAIMER.
+
+ 6. TERMINATION.
+
+ 6.1. This License and the rights granted hereunder will
+ terminate automatically if You fail to comply with terms
+ herein and fail to cure such breach within 30 days of
+ becoming aware of the breach. Provisions which, by their
+ nature, must remain in effect beyond the termination of
+ this License shall survive.
+
+ 6.2. If You assert a patent infringement claim (excluding
+ declaratory judgment actions) against Initial Developer or
+ a Contributor (the Initial Developer or Contributor against
+ whom You assert such claim is referred to as "Participant")
+ alleging that the Participant Software (meaning the
+ Contributor Version where the Participant is a Contributor
+ or the Original Software where the Participant is the
+ Initial Developer) directly or indirectly infringes any
+ patent, then any and all rights granted directly or
+ indirectly to You by such Participant, the Initial
+ Developer (if the Initial Developer is not the Participant)
+ and all Contributors under Sections 2.1 and/or 2.2 of this
+ License shall, upon 60 days notice from Participant
+ terminate prospectively and automatically at the expiration
+ of such 60 day notice period, unless if within such 60 day
+ period You withdraw Your claim with respect to the
+ Participant Software against such Participant either
+ unilaterally or pursuant to a written agreement with
+ Participant.
+
+ 6.3. In the event of termination under Sections 6.1 or 6.2
+ above, all end user licenses that have been validly granted
+ by You or any distributor hereunder prior to termination
+ (excluding licenses granted to You by any distributor)
+ shall survive termination.
+
+ 7. LIMITATION OF LIABILITY.
+
+ UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
+ (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE
+ INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF
+ COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE
+ LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT
+ LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK
+ STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER
+ COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN
+ INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF
+ LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL
+ INJURY RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT
+ APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO
+ NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR
+ CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT
+ APPLY TO YOU.
+
+ 8. U.S. GOVERNMENT END USERS.
+
+ The Covered Software is a "commercial item," as that term is
+ defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial
+ computer software" (as that term is defined at 48 C.F.R.
+ 252.227-7014(a)(1)) and "commercial computer software
+ documentation" as such terms are used in 48 C.F.R. 12.212 (Sept.
+ 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1
+ through 227.7202-4 (June 1995), all U.S. Government End Users
+ acquire Covered Software with only those rights set forth herein.
+ This U.S. Government Rights clause is in lieu of, and supersedes,
+ any other FAR, DFAR, or other clause or provision that addresses
+ Government rights in computer software under this License.
+
+ 9. MISCELLANEOUS.
+
+ This License represents the complete agreement concerning subject
+ matter hereof. If any provision of this License is held to be
+ unenforceable, such provision shall be reformed only to the
+ extent necessary to make it enforceable. This License shall be
+ governed by the law of the jurisdiction specified in a notice
+ contained within the Original Software (except to the extent
+ applicable law, if any, provides otherwise), excluding such
+ jurisdiction's conflict-of-law provisions. Any litigation
+ relating to this License shall be subject to the jurisdiction of
+ the courts located in the jurisdiction and venue specified in a
+ notice contained within the Original Software, with the losing
+ party responsible for costs, including, without limitation, court
+ costs and reasonable attorneys' fees and expenses. The
+ application of the United Nations Convention on Contracts for the
+ International Sale of Goods is expressly excluded. Any law or
+ regulation which provides that the language of a contract shall
+ be construed against the drafter shall not apply to this License.
+ You agree that You alone are responsible for compliance with the
+ United States export administration regulations (and the export
+ control laws and regulation of any other countries) when You use,
+ distribute or otherwise make available any Covered Software.
+
+ 10. RESPONSIBILITY FOR CLAIMS.
+
+ As between Initial Developer and the Contributors, each party is
+ responsible for claims and damages arising, directly or
+ indirectly, out of its utilization of rights under this License
+ and You agree to work with Initial Developer and Contributors to
+ distribute such responsibility on an equitable basis. Nothing
+ herein is intended or shall be deemed to constitute any admission
+ of liability.
+
diff --git a/tags/java/tsss-demo/runtime/webapp/smoketest/NOTICE.txt b/tags/java/tsss-demo/runtime/webapp/smoketest/NOTICE.txt
new file mode 100644
index 0000000000..d83ebbe236
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/smoketest/NOTICE.txt
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/runtime/webapp/smoketest/pom.xml b/tags/java/tsss-demo/runtime/webapp/smoketest/pom.xml
new file mode 100644
index 0000000000..9dee9cff73
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/smoketest/pom.xml
@@ -0,0 +1,118 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca.runtime</groupId>
+ <artifactId>webapp</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.runtime.webapp</groupId>
+ <artifactId>webapp-smoketest</artifactId>
+ <packaging>war</packaging>
+ <name>Apache Tuscany WebApp Smoketest</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.runtime.webapp</groupId>
+ <artifactId>webapp-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+ <build>
+ <finalName>${artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.tuscany</groupId>
+ <artifactId>tuscany-war-plugin</artifactId>
+ <version>${project.version}</version>
+ <executions>
+ <execution>
+ <id>tuscany-war</id>
+ <goals>
+ <goal>tuscany-war</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.cargo</groupId>
+ <artifactId>cargo-maven2-plugin</artifactId>
+ <configuration>
+ <container>
+ <containerId>jetty6x</containerId>
+ <type>embedded</type>
+ </container>
+ <wait>false</wait>
+ <configuration>
+ <properties>
+ <cargo.servlet.port>8088</cargo.servlet.port>
+ </properties>
+ </configuration>
+ </configuration>
+ <executions>
+ <execution>
+ <id>start-container</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>start</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>stop-container</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>stop</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>integration-test</phase>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <includes>
+ <include>**/SmokeTest*.java</include>
+ </includes>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tags/java/tsss-demo/runtime/webapp/smoketest/src/main/java/org/apache/tuscany/sca/runtime/webapp/smoketest/HelloService.java b/tags/java/tsss-demo/runtime/webapp/smoketest/src/main/java/org/apache/tuscany/sca/runtime/webapp/smoketest/HelloService.java
new file mode 100644
index 0000000000..87566cbba4
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/smoketest/src/main/java/org/apache/tuscany/sca/runtime/webapp/smoketest/HelloService.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.runtime.webapp.smoketest;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface HelloService {
+ String getGreeting();
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/smoketest/src/main/java/org/apache/tuscany/sca/runtime/webapp/smoketest/HelloServiceImpl.java b/tags/java/tsss-demo/runtime/webapp/smoketest/src/main/java/org/apache/tuscany/sca/runtime/webapp/smoketest/HelloServiceImpl.java
new file mode 100644
index 0000000000..9cf2ced4d8
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/smoketest/src/main/java/org/apache/tuscany/sca/runtime/webapp/smoketest/HelloServiceImpl.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.runtime.webapp.smoketest;
+
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class HelloServiceImpl implements HelloService {
+ private final String greeting;
+
+ public HelloServiceImpl(@Property(name="greeting")String greeting) {
+ this.greeting = greeting;
+ }
+
+ public String getGreeting() {
+ return greeting;
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/smoketest/src/main/java/org/apache/tuscany/sca/runtime/webapp/smoketest/TestServlet.java b/tags/java/tsss-demo/runtime/webapp/smoketest/src/main/java/org/apache/tuscany/sca/runtime/webapp/smoketest/TestServlet.java
new file mode 100644
index 0000000000..49dd12d6f4
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/smoketest/src/main/java/org/apache/tuscany/sca/runtime/webapp/smoketest/TestServlet.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.runtime.webapp.smoketest;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletException;
+
+import org.osoa.sca.ComponentContext;
+
+import org.apache.tuscany.runtime.webapp.Constants;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TestServlet extends HttpServlet {
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ PrintWriter out = response.getWriter();
+ String test = request.getParameter("test");
+ if ("context".equals(test)) {
+ ComponentContext context = (ComponentContext) getServletContext().getAttribute(Constants.CONTEXT_ATTRIBUTE);
+ if (context == null) {
+ response.sendError(500, "Context was not bound");
+ return;
+ }
+ out.print("component URI is " + context.getURI());
+ } else {
+ response.sendError(500, "No test specified");
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/smoketest/src/main/webapp/WEB-INF/default.scdl b/tags/java/tsss-demo/runtime/webapp/smoketest/src/main/webapp/WEB-INF/default.scdl
new file mode 100644
index 0000000000..9a21678676
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/smoketest/src/main/webapp/WEB-INF/default.scdl
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/2.0-alpha"
+ name="WebappSmoketestComposite">
+
+ <component name="smoketest">
+ <tuscany:webapp>
+ <reference name="hello" interface="org.apache.tuscany.sca.runtime.webapp.smoketest.HelloService"/>
+ </tuscany:webapp>
+ <reference name="hello" target="HelloComponent"/>
+ </component>
+
+ <component name="HelloComponent">
+ <implementation.java class="org.apache.tuscany.sca.runtime.webapp.smoketest.HelloServiceImpl"/>
+ <property name="greeting">Hello World</property>
+ </component>
+</composite>
diff --git a/tags/java/tsss-demo/runtime/webapp/smoketest/src/main/webapp/WEB-INF/web.xml b/tags/java/tsss-demo/runtime/webapp/smoketest/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000000..fe6975f514
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/smoketest/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+
+<web-app version="2.4"
+ xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
+
+ <display-name>Apache Tuscany Webapp Smoketest</display-name>
+
+ <listener>
+ <listener-class>org.apache.tuscany.runtime.webapp.TuscanyContextListener</listener-class>
+ </listener>
+
+ <context-param>
+ <param-name>tuscany.component</param-name>
+ <param-value>smoketest</param-value>
+ </context-param>
+
+ <servlet>
+ <servlet-name>TestServlet</servlet-name>
+ <servlet-class>org.apache.tuscany.sca.runtime.webapp.smoketest.TestServlet</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>TestServlet</servlet-name>
+ <url-pattern>/smoketest</url-pattern>
+ </servlet-mapping>
+</web-app>
diff --git a/tags/java/tsss-demo/runtime/webapp/smoketest/src/test/java/org/apache/tuscany/sca/runtime/webapp/smoketest/SmokeTestContext.java b/tags/java/tsss-demo/runtime/webapp/smoketest/src/test/java/org/apache/tuscany/sca/runtime/webapp/smoketest/SmokeTestContext.java
new file mode 100644
index 0000000000..e0510848f1
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/smoketest/src/test/java/org/apache/tuscany/sca/runtime/webapp/smoketest/SmokeTestContext.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.runtime.webapp.smoketest;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SmokeTestContext extends TestCase {
+ private URL base;
+
+ public void testContext() throws IOException {
+ URL url = new URL(base, "smoketest?test=context");
+ String result = getContent(url);
+ assertEquals("component URI is http://locahost/sca/smoketest", result);
+ }
+
+ private String getContent(URL url) throws IOException {
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ Reader reader = new InputStreamReader(connection.getInputStream());
+ StringBuilder result = new StringBuilder();
+ int ch;
+ while ((ch = reader.read()) != -1) {
+ result.append((char)ch);
+ }
+ reader.close();
+ assertEquals(200, connection.getResponseCode());
+ return result.toString();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ base = new URL("http://localhost:8088/webapp-smoketest/");
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-api/.ruleset b/tags/java/tsss-demo/runtime/webapp/webapp-api/.ruleset
new file mode 100644
index 0000000000..3886f07f2d
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-api/.ruleset
@@ -0,0 +1,190 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<ruleset name="pmd-eclipse">
+ <description>PMD Plugin preferences rule set</description>
+
+
+ <rule ref="rulesets/basic.xml/BooleanInstantiation"/>
+ <rule ref="rulesets/basic.xml/CollapsibleIfStatements"/>
+ <rule ref="rulesets/basic.xml/DoubleCheckedLocking"/>
+<!--<rule ref="rulesets/basic.xml/EmptyCatchBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyFinallyBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyIfStmt"/>-->
+ <rule ref="rulesets/basic.xml/EmptyStatementNotInLoop"/>
+<!--<rule ref="rulesets/basic.xml/EmptyStaticInitializer"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptySwitchStatements"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptySynchronizedBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyTryBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyWhileStmt"/>-->
+ <rule ref="rulesets/basic.xml/ForLoopShouldBeWhileLoop"/>
+ <rule ref="rulesets/basic.xml/JumbledIncrementer"/>
+<!--<rule ref="rulesets/basic.xml/OverrideBothEqualsAndHashcode"/>-->
+ <rule ref="rulesets/basic.xml/ReturnFromFinallyBlock"/>
+ <rule ref="rulesets/basic.xml/UnconditionalIfStatement"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryConversionTemporary"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryFinalModifier"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryReturn"/>
+<!--<rule ref="rulesets/basic.xml/UselessOverridingMethod"/>-->
+
+<!--<rule ref="rulesets/braces.xml/ForLoopsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/IfElseStmtsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/IfStmtsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/WhileLoopsMustUseBraces"/>-->
+
+<!--<rule ref="rulesets/clone.xml/CloneMethodMustImplementCloneable"/>-->
+<!--<rule ref="rulesets/clone.xml/CloneThrowsCloneNotSupportedException"/>-->
+<!--<rule ref="rulesets/clone.xml/ProperCloneImplementation"/>-->
+
+<!--<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>-->
+<!--<rule ref="rulesets/codesize.xml/TooManyFields"/>-->
+
+<rule ref="rulesets/controversial.xml/AssignmentInOperand"/>
+<!--<rule ref="rulesets/controversial.xml/AtLeastOneConstructor"/>-->
+<!--<rule ref="rulesets/controversial.xml/CallSuperInConstructor"/>-->
+<!--<rule ref="rulesets/controversial.xml/DontImportSun"/>-->
+<!--<rule ref="rulesets/controversial.xml/NullAssignment"/>-->
+<!--<rule ref="rulesets/controversial.xml/OnlyOneReturn"/>-->
+<!--<rule ref="rulesets/controversial.xml/SingularField"/>-->
+<!--<rule ref="rulesets/controversial.xml/SuspiciousOctalEscape"/>-->
+<!--<rule ref="rulesets/controversial.xml/UnnecessaryConstructor"/>-->
+<rule ref="rulesets/controversial.xml/UnnecessaryParentheses"/>
+<!--<rule ref="rulesets/controversial.xml/UnusedModifier"/>-->
+
+<!--<rule ref="rulesets/coupling.xml/CouplingBetweenObjects"/>-->
+<!--<rule ref="rulesets/coupling.xml/ExcessiveImports"/>-->
+<!--<rule ref="rulesets/coupling.xml/LooseCoupling"/>-->
+
+<!--<rule ref="rulesets/design.xml/AbstractClassWithoutAbstractMethod"/>-->
+<!--<rule ref="rulesets/design.xml/AccessorClassGeneration"/>-->
+<!--<rule ref="rulesets/design.xml/AssignmentToNonFinalStatic"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidDeeplyNestedIfStmts"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidInstanceofChecksInCatchClause"/>-->
+<rule ref="rulesets/design.xml/AvoidProtectedFieldInFinalClass"/>
+<!--<rule ref="rulesets/design.xml/AvoidReassigningParameters"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidSynchronizedAtMethodLevel"/>-->
+<!--<rule ref="rulesets/design.xml/BadComparison"/>-->
+<!--<rule ref="rulesets/design.xml/CloseConnection"/>-->
+<!--<rule ref="rulesets/design.xml/CompareObjectsWithEquals"/>-->
+<!--<rule ref="rulesets/design.xml/ConfusingTernary"/>-->
+<rule ref="rulesets/design.xml/ConstructorCallsOverridableMethod"/>
+<!--<rule ref="rulesets/design.xml/DefaultLabelNotLastInSwitchStmt"/>-->
+<!--<rule ref="rulesets/design.xml/FinalFieldCouldBeStatic"/>-->
+<rule ref="rulesets/design.xml/IdempotentOperations"/>
+<!--<rule ref="rulesets/design.xml/ImmutableField"/>-->
+<!--<rule ref="rulesets/design.xml/InstantiationToGetClass"/>-->
+<!--<rule ref="rulesets/design.xml/MissingBreakInSwitch"/>-->
+<!--<rule ref="rulesets/design.xml/MissingStaticMethodInNonInstantiatableClass"/>-->
+<!--<rule ref="rulesets/design.xml/NonCaseLabelInSwitchStatement"/>-->
+<!--<rule ref="rulesets/design.xml/NonStaticInitializer"/>-->
+<rule ref="rulesets/design.xml/OptimizableToArrayCall"/>
+<rule ref="rulesets/design.xml/PositionLiteralsFirstInComparisons"/>
+<rule ref="rulesets/design.xml/SimplifyBooleanExpressions"/>
+<rule ref="rulesets/design.xml/SimplifyBooleanReturns"/>
+<rule ref="rulesets/design.xml/SimplifyConditional"/>
+<!--<rule ref="rulesets/design.xml/SwitchDensity"/>-->
+<!--<rule ref="rulesets/design.xml/SwitchStmtsShouldHaveDefault"/>-->
+<rule ref="rulesets/design.xml/UnnecessaryLocalBeforeReturn"/>
+<!--<rule ref="rulesets/design.xml/UseLocaleWithCaseConversions"/>-->
+<!--<rule ref="rulesets/design.xml/UseNotifyAllInsteadOfNotify"/>-->
+<!--<rule ref="rulesets/design.xml/UseSingleton"/>-->
+
+<!--<rule ref="rulesets/finalizers.xml/EmptyFinalizer"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeOnlyCallsSuperFinalize"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeOverloaded"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeDoesNotCallSuperFinalize"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeShouldBeProtected"/>-->
+<!--<rule ref="rulesets/finalizers.xml/AvoidCallingFinalize"/>-->
+
+<!--<rule ref="rulesets/imports.xml/DuplicateImports"/>-->
+<!--<rule ref="rulesets/imports.xml/DontImportJavaLang"/>-->
+<!--<rule ref="rulesets/imports.xml/UnusedImports"/>-->
+<!--<rule ref="rulesets/imports.xml/ImportFromSamePackage"/>-->
+
+<!--<rule ref="rulesets/javabeans.xml/BeanMembersShouldSerialize"/>-->
+<!--<rule ref="rulesets/javabeans.xml/MissingSerialVersionUID"/>-->
+
+<!--<rule ref="rulesets/junit.xml/JUnitStaticSuite"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitSpelling"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitAssertionsShouldIncludeMessage"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitTestsShouldIncludeAssert"/>-->
+<!--<rule ref="rulesets/junit.xml/TestClassWithoutTestCases"/>-->
+<!--<rule ref="rulesets/junit.xml/UnnecessaryBooleanAssertion"/>-->
+<!--<rule ref="rulesets/junit.xml/UseAssertEqualsInsteadOfAssertTrue"/>-->
+<!--<rule ref="rulesets/junit.xml/UseAssertSameInsteadOfAssertTrue"/>-->
+
+ <!--<rule ref="rulesets/logging-java.xml/AvoidPrintStackTrace"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/MoreThanOneLogger"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LogBlockWithoutIf"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/SystemPrintln"/>-->
+ <!--<rule ref="rulesets/logging-jakarta-commons.xml/UseCorrectExceptionLogging"/>-->
+ <!--<rule ref="rulesets/logging-jakarta-commons.xml/ProperLogger"/>-->
+
+ <!--<rule ref="rulesets/naming.xml/ShortVariable"/>-->
+ <!--<rule ref="rulesets/naming.xml/LongVariable"/>-->
+ <!--<rule ref="rulesets/naming.xml/ShortMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/VariableNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/MethodNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/ClassNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/AbstractNaming"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidDollarSigns"/>-->
+ <!--<rule ref="rulesets/naming.xml/MethodWithSameNameAsEnclosingClass"/>-->
+ <!--<rule ref="rulesets/naming.xml/SuspiciousHashcodeMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/SuspiciousConstantFieldName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingTypeName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidNonConstructorMethodsWithClassName"/>-->
+ <!--<rule ref="rulesets/naming.xml/NoPackage"/>-->
+ <!--<rule ref="rulesets/naming.xml/PackageCase"/>-->
+
+ <!--<rule ref="rulesets/optimizations.xml/LocalVariableCouldBeFinal"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/MethodArgumentCouldBeFinal"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/AvoidInstantiatingObjectsInLoops"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/UseArrayListInsteadOfVector"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/SimplifyStartsWith"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/UseStringBufferForStringAppends"/>-->
+
+ <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingThrowable"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/SignatureDeclareThrowsException"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/ExceptionAsFlowControl"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingNPE"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingRawExceptionTypes"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingNullPointerException"/>-->
+
+ <!--<rule ref="rulesets/strings.xml/AvoidDuplicateLiterals"/>-->
+ <!--<rule ref="rulesets/strings.xml/StringInstantiation"/>-->
+ <!--<rule ref="rulesets/strings.xml/StringToString"/>-->
+ <!--<rule ref="rulesets/strings.xml/AvoidConcatenatingNonLiteralsInStringBuffer"/>-->
+ <!--<rule ref="rulesets/strings.xml/UnnecessaryCaseChange"/>-->
+
+ <!--<rule ref="rulesets/sunsecure.xml/MethodReturnsInternalArray"/>-->
+ <!--<rule ref="rulesets/sunsecure.xml/ArrayIsStoredDirectly"/>-->
+
+ <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/>
+ <rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/>
+ <rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/>
+ <!--<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>-->
+
+</ruleset>
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-api/LICENSE.txt b/tags/java/tsss-demo/runtime/webapp/webapp-api/LICENSE.txt
new file mode 100644
index 0000000000..0084319535
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-api/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, serviceDefinition marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-api/NOTICE.txt b/tags/java/tsss-demo/runtime/webapp/webapp-api/NOTICE.txt
new file mode 100644
index 0000000000..d83ebbe236
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-api/NOTICE.txt
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-api/pom.xml b/tags/java/tsss-demo/runtime/webapp/webapp-api/pom.xml
new file mode 100644
index 0000000000..a9a7959c8c
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-api/pom.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca.runtime</groupId>
+ <artifactId>webapp</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.runtime.webapp</groupId>
+ <artifactId>webapp-api</artifactId>
+ <packaging>jar</packaging>
+ <name>Apache Tuscany Web Application Runtime</name>
+ <description>Integration code to run Tuscany in a Web application.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-host-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/Constants.java b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/Constants.java
new file mode 100644
index 0000000000..ef209c05ee
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/Constants.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.runtime.webapp;
+
+/**
+ * Constants used by the web application booter
+ *
+ * @version $Rev$ $Date$
+ */
+public final class Constants {
+
+ /**
+ * Name of the servlet context-param that should contain the component id for the webapp.
+ */
+ public static final String COMPOSITE_PARAM = "tuscany.composite";
+
+ /**
+ * Name of the servlet context-param that should contain the component id for the webapp.
+ */
+ public static final String COMPONENT_PARAM = "tuscany.component";
+
+ /**
+ * Servlet context-param name for user-specified application SCDL path.
+ */
+ static final String APPLICATION_SCDL_PATH_PARAM = "tuscany.applicationScdlPath";
+
+ /**
+ * Default application SCDL path.
+ */
+ public static final String APPLICATION_SCDL_PATH_DEFAULT = "/WEB-INF/default.scdl";
+
+ /**
+ * Servlet context-param name for setting if the runtime is online.
+ */
+ public static final String ONLINE_PARAM = "tuscany.online";
+
+ /**
+ * Name of the context attribute that contains the ComponentContext.
+ */
+ public static final String CONTEXT_ATTRIBUTE = "tuscany.context";
+
+ /**
+ * Name of the parameter that defines the name of webapp resource containing bootstrap jars.
+ */
+ static final String BOOTDIR_PARAM = "tuscany.bootDir";
+
+ /**
+ * Default value for BOOTDIR_PARAM.
+ */
+ static final String BOOTDIR_DEFAULT = "/WEB-INF/tuscany/boot";
+
+ /**
+ * Name of the parameter that defines the class to load to launch the runtime.
+ */
+ static final String RUNTIME_PARAM = "tuscany.runtimeImpl";
+
+ /**
+ * Name of the default webapp runtime implementation.
+ */
+ static final String RUNTIME_DEFAULT = "org.apache.tuscany.runtime.webapp.WebappRuntimeImpl";
+
+ /**
+ * Servlet context-param name for user-specified system SCDL path.
+ */
+ static final String SYSTEM_SCDL_PATH_PARAM = "tuscany.systemScdlPath";
+
+ /**
+ * Default webapp system SCDL path.
+ */
+ static final String SYSTEM_SCDL_PATH_DEFAULT = "META-INF/tuscany/webapp.scdl";
+
+ /**
+ * Context attribute to which the Tuscany runtime for this servlet context is stored.
+ */
+ static final String RUNTIME_ATTRIBUTE = "tuscany.runtime";
+
+ /**
+ * Servlet context-param name for the path to the composite to set as the webb app composite
+ */
+ static final String CURRENT_COMPOSITE_PATH_PARAM = "tuscany.currentCompositePath";
+
+ /**
+ * Servlet context-param name for user-specified system SCDL path.
+ */
+ static final String EXTENSION_SCDL_PATH_PARAM = "tuscany.extensionScdlPath";
+
+ /**
+ * Default path for extensions if no "extensionScdlPath param is specified
+ */
+ static final String DEFAULT_EXTENSION_PATH_PARAM = "/WEB-INF/tuscany/extensions";
+
+ /**
+ * Servlet context-param name for system monitoring level. Supported values are the names of statics defined in
+ * java.util.logging.Level. If absent, no monitoring will take place.
+ */
+ static final String SYSTEM_MONITORING_PARAM = "tuscany.monitoringLevel";
+
+ private Constants() {
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/InvalidResourcePath.java b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/InvalidResourcePath.java
new file mode 100644
index 0000000000..3d1353de25
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/InvalidResourcePath.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.runtime.webapp;
+
+/**
+ * Denotes an invalid or non-existing path for a resource required by the runtime bootstrap
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidResourcePath extends TuscanyInitException {
+
+ public InvalidResourcePath(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherMonitor.java b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherMonitor.java
new file mode 100644
index 0000000000..5936240481
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherMonitor.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.runtime.webapp;
+
+import org.apache.tuscany.api.annotation.LogLevel;
+
+/**
+ * A monitor interface used during runtime bootstrap
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ServletLauncherMonitor {
+
+ @LogLevel("DEBUG")
+ void deployExtension(String path);
+
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.java
new file mode 100644
index 0000000000..dce4fa7393
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyContextListener.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.runtime.webapp;
+
+import java.net.URL;
+import java.net.URI;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+import org.apache.tuscany.host.runtime.ShutdownException;
+import static org.apache.tuscany.runtime.webapp.Constants.COMPOSITE_PARAM;
+import static org.apache.tuscany.runtime.webapp.Constants.COMPONENT_PARAM;
+import static org.apache.tuscany.runtime.webapp.Constants.ONLINE_PARAM;
+import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_ATTRIBUTE;
+import static org.apache.tuscany.runtime.webapp.Constants.APPLICATION_SCDL_PATH_DEFAULT;
+import static org.apache.tuscany.runtime.webapp.Constants.APPLICATION_SCDL_PATH_PARAM;
+
+/**
+ * Launches a Tuscany runtime in a web application, loading information from servlet context parameters. This listener
+ * manages one runtime per servlet context; the lifecycle of that runtime corresponds to the the lifecycle of the
+ * associated servlet context.
+ * <p/>
+ * The runtime is launched in a child classloader of the web application, thereby providing isolation between
+ * application and system artifacts. Application code only has access to the SCA API and may not reference Tuscany
+ * system artifacts directly.
+ * <p/>
+ * The <code>web.xml</code> of a web application embedding Tuscany must have entries for this listener and {@link
+ * TuscanySessionListener}. The latter notifies the runtime of session creation and expiration events through a
+ * "bridging" contract, {@link WebappRuntime}. The <code>web.xml</code> may also optionally be configured with entries
+ * for {@link TuscanyFilter} and {@link TuscanyServlet}. The former must be mapped to all urls that execute "unmanaged"
+ * code which accesses the Tuscany runtime though the SCA API, for example, JSPs and Servlets. The latter forwards
+ * service requests into the runtime, by default requests sent to URLs relative to the context path beginning with
+ * <code>/services</code>.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TuscanyContextListener implements ServletContextListener {
+
+ public void contextInitialized(ServletContextEvent event) {
+ ClassLoader webappClassLoader = Thread.currentThread().getContextClassLoader();
+ ServletContext servletContext = event.getServletContext();
+ WebappUtil utils = getUtils(servletContext);
+ try {
+ // FIXME work this out from the servlet context
+ String defaultComposite = "http://locahost/sca";
+ URI compositeId = new URI(utils.getInitParameter(COMPOSITE_PARAM, defaultComposite));
+ URI componentId = new URI(utils.getInitParameter(COMPONENT_PARAM, "webapp"));
+ String scdlPath = utils.getInitParameter(APPLICATION_SCDL_PATH_PARAM, APPLICATION_SCDL_PATH_DEFAULT);
+ URL scdl = servletContext.getResource(scdlPath);
+
+ boolean online = Boolean.valueOf(utils.getInitParameter(ONLINE_PARAM, "true"));
+ WebappRuntimeInfo info = new WebappRuntimeInfoImpl(servletContext,
+ servletContext.getResource("/WEB-INF/tuscany/"),
+ online);
+ ClassLoader bootClassLoader = utils.getBootClassLoader(webappClassLoader);
+ URL systemScdl = utils.getSystemScdl(bootClassLoader);
+
+ WebappRuntime runtime = utils.getRuntime(bootClassLoader);
+ runtime.setServletContext(servletContext);
+ runtime.setRuntimeInfo(info);
+ runtime.setHostClassLoader(webappClassLoader);
+ runtime.setSystemScdl(systemScdl);
+ runtime.initialize();
+ servletContext.setAttribute(RUNTIME_ATTRIBUTE, runtime);
+
+ runtime.deploy(compositeId, scdl, componentId);
+ } catch (TuscanyRuntimeException e) {
+ servletContext.log(e.getMessage(), e);
+ e.printStackTrace();
+ throw e;
+ } catch (Throwable e) {
+ servletContext.log(e.getMessage(), e);
+ e.printStackTrace();
+ throw new TuscanyInitException(e);
+ }
+ }
+
+ protected WebappUtil getUtils(ServletContext servletContext) {
+ return new WebappUtilImpl(servletContext);
+ }
+
+ public void contextDestroyed(ServletContextEvent event) {
+ ServletContext servletContext = event.getServletContext();
+ WebappRuntime runtime = (WebappRuntime) servletContext.getAttribute(RUNTIME_ATTRIBUTE);
+ if (runtime == null) {
+ return;
+ }
+ servletContext.removeAttribute(RUNTIME_ATTRIBUTE);
+ try {
+ runtime.destroy();
+ } catch (ShutdownException e) {
+ servletContext.log("Error destroying runtume", e);
+ }
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyFilter.java b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyFilter.java
new file mode 100644
index 0000000000..e1433014b2
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyFilter.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.runtime.webapp;
+
+import java.io.IOException;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.ServletContext;
+
+import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_ATTRIBUTE;
+
+/**
+ * Maps an incoming request and the current composite context to the composite component for the web application. This
+ * filter must be applied to all web application urls that execute unmanaged code (e.g. JSPs and Servlets) which
+ * accesses the Tuscany runtime.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TuscanyFilter implements Filter {
+ private WebappRuntime runtime;
+
+ public void init(FilterConfig config) throws ServletException {
+ ServletContext servletContext = config.getServletContext();
+ runtime = (WebappRuntime) servletContext.getAttribute(RUNTIME_ATTRIBUTE);
+ if (runtime == null) {
+ throw new ServletException("Tuscany is not configured for the web application");
+ }
+ }
+
+ public void doFilter(ServletRequest req, ServletResponse resp, FilterChain filterChain)
+ throws IOException, ServletException {
+ try {
+ runtime.startRequest();
+ filterChain.doFilter(req, resp);
+ } finally {
+ runtime.stopRequest();
+ }
+ }
+
+ public void destroy() {
+ runtime = null;
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyInitException.java b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyInitException.java
new file mode 100644
index 0000000000..a929dd6307
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyInitException.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.runtime.webapp;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * Exception indicating that there was a problem starting the Tuscany runtime.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TuscanyInitException extends TuscanyRuntimeException {
+ public TuscanyInitException(String string) {
+ super(string);
+ }
+
+ public TuscanyInitException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public TuscanyInitException(String string, Throwable throwable) {
+ super(string, throwable);
+ }
+
+ public TuscanyInitException(String message, String identifier, Throwable cause) {
+ super(message, identifier, cause);
+ }
+
+ public TuscanyInitException(Throwable throwable) {
+ super(throwable);
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyRequestListener.java b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyRequestListener.java
new file mode 100644
index 0000000000..325532aef6
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyRequestListener.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.runtime.webapp;
+
+import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_ATTRIBUTE;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletRequestEvent;
+import javax.servlet.ServletRequestListener;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+/**
+ * Notifies the Tuscany runtime of session creation and expiration events.
+ *
+ * @version $Rev: 441961 $ $Date: 2006-09-10 11:48:29 -0400 (Sun, 10 Sep 2006) $
+ */
+public class TuscanyRequestListener implements ServletRequestListener {
+ private WebappRuntime runtime;
+
+ public void requestDestroyed(ServletRequestEvent servletRequestEvent) {
+
+ final ServletContext context = servletRequestEvent.getServletContext();
+ getRuntime(context);
+ ServletRequest servletRequest = servletRequestEvent.getServletRequest();
+ if (servletRequest instanceof HttpServletRequest) {
+ HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
+ HttpSession session = httpServletRequest.getSession(false);
+ runtime.httpRequestEnded(session == null ? null : session.getId());
+
+ }
+
+ }
+
+ public void requestInitialized(ServletRequestEvent servletRequestEvent) {
+
+ final ServletContext context = servletRequestEvent.getServletContext();
+ getRuntime(context);
+ ServletRequest servletRequest = servletRequestEvent.getServletRequest();
+ if (servletRequest instanceof HttpServletRequest) {
+ runtime.httpRequestStarted((HttpServletRequest) servletRequest);
+
+ }
+
+ }
+
+ protected WebappRuntime getRuntime(final ServletContext context) {
+ if (runtime == null) {
+
+ runtime = (WebappRuntime) context.getAttribute(RUNTIME_ATTRIBUTE);
+ if (runtime == null) {
+ context.log("requestInitialized", new ServletException("Tuscany runtime not configured"));
+ return null;
+ }
+ }
+ return runtime;
+ }
+} \ No newline at end of file
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyServlet.java b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyServlet.java
new file mode 100644
index 0000000000..3132559fdd
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyServlet.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.runtime.webapp;
+
+import java.io.IOException;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServlet;
+
+import org.apache.tuscany.host.servlet.ServletRequestInjector;
+import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_ATTRIBUTE;
+
+/**
+ * A servlet that forwards requests intended for SCA services into the Tuscany runtime via a ServletRequestInjector.
+ * This servlet is typically mapped to relative paths beginning with <code>/services</code> in the <code>web.xml</code>
+ * <p/>
+ * TODO a better URL mapping scheme out to be implemented that corresponds to the SCA specification
+ */
+public class TuscanyServlet extends HttpServlet {
+ private static final long serialVersionUID = 1L;
+
+ private ServletRequestInjector requestInjector;
+
+ @Override
+ public void init(ServletConfig config) throws ServletException {
+ ServletContext servletContext = config.getServletContext();
+ WebappRuntime runtime = (WebappRuntime) servletContext.getAttribute(RUNTIME_ATTRIBUTE);
+ if (runtime == null) {
+ throw new ServletException("Tuscany runtime not configured for web application");
+ }
+ requestInjector = runtime.getRequestInjector();
+ }
+
+ @Override
+ public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
+ requestInjector.service(req, res);
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanySessionListener.java b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanySessionListener.java
new file mode 100644
index 0000000000..0335c7bc6a
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanySessionListener.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.runtime.webapp;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+
+import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_ATTRIBUTE;
+
+/**
+ * Notifies the Tuscany runtime of session creation and expiration events.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TuscanySessionListener implements HttpSessionListener {
+ private WebappRuntime runtime;
+
+ public void sessionCreated(HttpSessionEvent event) {
+ if (runtime == null) {
+ ServletContext context = event.getSession().getServletContext();
+ runtime = (WebappRuntime) context.getAttribute(RUNTIME_ATTRIBUTE);
+ if (runtime == null) {
+ context.log("Error on session creation", new ServletException("Tuscany runtime not configured"));
+ return;
+ }
+ }
+ runtime.sessionCreated(event);
+ }
+
+ public void sessionDestroyed(HttpSessionEvent event) {
+ if (runtime != null) {
+ runtime.sessionDestroyed(event);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java
new file mode 100644
index 0000000000..b74cc6e67e
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.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.runtime.webapp;
+
+import java.net.URI;
+import java.net.URL;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSessionListener;
+
+import org.apache.tuscany.host.runtime.TuscanyRuntime;
+import org.apache.tuscany.host.runtime.InitializationException;
+import org.apache.tuscany.host.servlet.ServletRequestInjector;
+
+/**
+ * The contract for artifacts loaded in the web application classloader to comminicate with the Tuscany runtime loaded
+ * in a child classloader. For example, filters and listeners may use this interface to notify the runtime of the web
+ * container events.
+ *
+ * @version $Rev$ $Date$
+ * @see TuscanyFilter
+ * @see TuscanySessionListener
+ */
+public interface WebappRuntime extends HttpSessionListener, TuscanyRuntime<WebappRuntimeInfo> {
+ /**
+ * Returns the ServletContext associated with this runtime.
+ *
+ * @return the ServletContext associated with this runtime
+ */
+ ServletContext getServletContext();
+
+ /**
+ * Sets the ServletContext associated with this runtime.
+ *
+ * @param servletContext the ServletContext associated with this runtime
+ */
+ void setServletContext(ServletContext servletContext);
+
+ /**
+ * Returns the request injector for the runtime
+ * @return the runtime's request injector
+ */
+ ServletRequestInjector getRequestInjector();
+
+ /**
+ * Notification that the web application has begun servicing a request
+ */
+ void startRequest();
+
+ /**
+ * Notification that the web application has stopped servicing a request
+ */
+ void stopRequest();
+
+ /**
+ * Request has been started for the given request.
+ * @param request the servlet request
+ */
+ void httpRequestStarted(HttpServletRequest request);
+
+ /**
+ * Request has been ended with the given session id.
+ * @param id the session id
+ */
+ void httpRequestEnded(Object id);
+
+ /**
+ * Temporary method for deploying SCDL supplied with an application to the runtime.
+ *
+ * @param compositeId the id of the component that the supplied SCDL should implement
+ * @param applicationScdl the location of an application composite
+ * @param componentId the id of the component that should be bound to the webapp
+ * @throws InitializationException if there was a problem initializing the composite
+ */
+ @Deprecated
+ void deploy(URI compositeId, URL applicationScdl, URI componentId) throws InitializationException;
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeInfo.java b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeInfo.java
new file mode 100644
index 0000000000..3047a30bb0
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeInfo.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.runtime.webapp;
+
+import javax.servlet.ServletContext;
+
+import org.apache.tuscany.host.RuntimeInfo;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface WebappRuntimeInfo extends RuntimeInfo {
+ /**
+ * Returns the ServletContext associated with this webapp runtime.
+ *
+ * @return the ServletContext associated with this webapp runtime.
+ */
+ ServletContext getServletContext();
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeInfoImpl.java b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeInfoImpl.java
new file mode 100644
index 0000000000..1f08fa2790
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeInfoImpl.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.runtime.webapp;
+
+import java.io.File;
+import java.net.URL;
+import java.net.URI;
+import javax.servlet.ServletContext;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WebappRuntimeInfoImpl implements WebappRuntimeInfo {
+ private final ServletContext servletContext;
+ private final URL baseURL;
+ private final boolean online;
+
+ public WebappRuntimeInfoImpl(ServletContext servletContext, URL baseURL, boolean online) {
+ this.servletContext = servletContext;
+ this.baseURL = baseURL;
+ this.online = online;
+ }
+
+ public ServletContext getServletContext() {
+ return servletContext;
+ }
+
+ public URL getBaseURL() {
+ return baseURL;
+ }
+
+ public File getInstallDirectory() {
+ return new File("");
+ }
+
+ public File getApplicationRootDirectory() {
+ return new File("");
+ }
+
+ public boolean isOnline() {
+ return online;
+ }
+
+ public URI getDomain() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getRuntimeId() {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappUtil.java b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappUtil.java
new file mode 100644
index 0000000000..263436bd96
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappUtil.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.runtime.webapp;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface WebappUtil {
+
+ String getApplicationName();
+
+ WebappRuntime getRuntime(ClassLoader bootClassLoader) throws TuscanyInitException;
+
+ /**
+ * Return the classloader that should be used to boot the Tuscany runtime. This will be a child of the web
+ * application's ClassLoader.
+ *
+ * @param webappClassLoader the web application's classloader
+ * @return a classloader that can be used to load the Tuscany runtime classes
+ */
+ ClassLoader getBootClassLoader(ClassLoader webappClassLoader) throws InvalidResourcePath;
+
+ URL getSystemScdl(ClassLoader bootClassLoader) throws InvalidResourcePath;
+
+ URL getApplicationScdl(ClassLoader bootClassLoader) throws InvalidResourcePath;
+
+ URL getScdlURL(String path, ClassLoader classLoader) throws MalformedURLException;
+
+ /**
+ * Return a init parameter from the servlet context or provide a default.
+ *
+ * @param name the name of the parameter
+ * @param value the default value
+ * @return the value of the specified parameter, or the default if not defined
+ */
+ String getInitParameter(String name, String value);
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappUtilImpl.java b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappUtilImpl.java
new file mode 100644
index 0000000000..fcaec7f8ac
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappUtilImpl.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.runtime.webapp;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Set;
+import javax.servlet.ServletContext;
+
+import static org.apache.tuscany.runtime.webapp.Constants.APPLICATION_SCDL_PATH_DEFAULT;
+import static org.apache.tuscany.runtime.webapp.Constants.APPLICATION_SCDL_PATH_PARAM;
+import static org.apache.tuscany.runtime.webapp.Constants.BOOTDIR_DEFAULT;
+import static org.apache.tuscany.runtime.webapp.Constants.BOOTDIR_PARAM;
+import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_DEFAULT;
+import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_PARAM;
+import static org.apache.tuscany.runtime.webapp.Constants.SYSTEM_SCDL_PATH_DEFAULT;
+import static org.apache.tuscany.runtime.webapp.Constants.SYSTEM_SCDL_PATH_PARAM;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WebappUtilImpl implements WebappUtil {
+ private final ServletContext servletContext;
+
+ public WebappUtilImpl(ServletContext servletContext) {
+ this.servletContext = servletContext;
+ }
+
+ public WebappRuntime getRuntime(ClassLoader bootClassLoader) throws TuscanyInitException {
+ try {
+ String className = getInitParameter(RUNTIME_PARAM, RUNTIME_DEFAULT);
+ return (WebappRuntime) bootClassLoader.loadClass(className).newInstance();
+ } catch (InstantiationException e) {
+ throw new TuscanyInitException(e);
+ } catch (IllegalAccessException e) {
+ throw new TuscanyInitException(e);
+ } catch (ClassNotFoundException e) {
+ throw new TuscanyInitException("Runtime Implementation not found", e);
+ }
+ }
+
+ public ClassLoader getBootClassLoader(ClassLoader webappClassLoader) throws InvalidResourcePath {
+ String bootDirName = getInitParameter(BOOTDIR_PARAM, BOOTDIR_DEFAULT);
+ Set paths = servletContext.getResourcePaths(bootDirName);
+ if (paths == null) {
+ // nothing in boot directory, assume everything is in the webapp classloader
+ return webappClassLoader;
+ }
+ URL[] urls = new URL[paths.size()];
+ int i = 0;
+ for (Object path : paths) {
+ try {
+ urls[i++] = servletContext.getResource((String) path);
+ } catch (MalformedURLException e) {
+ throw new InvalidResourcePath(APPLICATION_SCDL_PATH_PARAM, path.toString(), e);
+ }
+ }
+ return new URLClassLoader(urls, webappClassLoader);
+ }
+
+ public URL getSystemScdl(ClassLoader bootClassLoader) throws InvalidResourcePath {
+ String path = getInitParameter(SYSTEM_SCDL_PATH_PARAM, SYSTEM_SCDL_PATH_DEFAULT);
+ try {
+ return getScdlURL(path, bootClassLoader);
+ } catch (MalformedURLException e) {
+ throw new InvalidResourcePath(SYSTEM_SCDL_PATH_PARAM, path, e);
+ }
+ }
+
+ public String getApplicationName() {
+ String name = servletContext.getServletContextName();
+ if (name == null) {
+ name = "application";
+ }
+ return name;
+ }
+
+ public URL getApplicationScdl(ClassLoader bootClassLoader) throws InvalidResourcePath {
+ String path = getInitParameter(APPLICATION_SCDL_PATH_PARAM, APPLICATION_SCDL_PATH_DEFAULT);
+ try {
+ return getScdlURL(path, bootClassLoader);
+ } catch (MalformedURLException e) {
+ throw new InvalidResourcePath(APPLICATION_SCDL_PATH_PARAM, path, e);
+ }
+ }
+
+ public URL getScdlURL(String path, ClassLoader classLoader) throws MalformedURLException {
+ URL ret = null;
+ if (path.charAt(0) == '/') {
+ // user supplied an absolute path - look up as a webapp resource
+ ret = servletContext.getResource(path);
+ }
+ if (ret == null) {
+ // user supplied a relative path - look up as a boot classpath resource
+ ret = classLoader.getResource(path);
+ }
+ return ret;
+ }
+
+ public String getInitParameter(String name, String value) {
+ String result = servletContext.getInitParameter(name);
+ if (result != null && result.length() != 0) {
+ return result;
+ }
+ return value;
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.java
new file mode 100644
index 0000000000..aa237da01c
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyContextListenerTestCase.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.runtime.webapp;
+
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URI;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+
+import junit.framework.TestCase;
+import static org.easymock.classextension.EasyMock.createMock;
+import static org.easymock.classextension.EasyMock.eq;
+import static org.easymock.classextension.EasyMock.expect;
+import static org.easymock.classextension.EasyMock.isA;
+import static org.easymock.classextension.EasyMock.replay;
+import static org.easymock.classextension.EasyMock.verify;
+
+import static org.apache.tuscany.runtime.webapp.Constants.APPLICATION_SCDL_PATH_PARAM;
+import static org.apache.tuscany.runtime.webapp.Constants.APPLICATION_SCDL_PATH_DEFAULT;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TuscanyContextListenerTestCase extends TestCase {
+ private String contextName;
+ private ServletContext context;
+ private TuscanyContextListener listener;
+ private ClassLoader cl;
+ private ClassLoader bootClassLoader;
+ private URL systemUrl;
+ private URL scdl;
+ private WebappUtil utils;
+ private String compositeId;
+
+ public void testInitializationUsingDefaults() throws Exception {
+ ServletContextEvent event = createMock(ServletContextEvent.class);
+ expect(event.getServletContext()).andReturn(context);
+ replay(event);
+
+ WebappRuntime runtime = createMock(WebappRuntime.class);
+ expect(utils.getBootClassLoader(cl)).andReturn(bootClassLoader);
+ expect(utils.getInitParameter("tuscany.composite", compositeId)).andReturn(compositeId);
+ expect(utils.getInitParameter("tuscany.component", contextName)).andReturn(contextName);
+ expect(utils.getInitParameter("tuscany.online", "true")).andReturn("true");
+ expect(utils.getInitParameter(APPLICATION_SCDL_PATH_PARAM, APPLICATION_SCDL_PATH_DEFAULT))
+ .andReturn(APPLICATION_SCDL_PATH_DEFAULT);
+ expect(utils.getRuntime(bootClassLoader)).andReturn(runtime);
+ expect(utils.getSystemScdl(bootClassLoader)).andReturn(systemUrl);
+ replay(utils);
+
+ expect(context.getResource("/WEB-INF/tuscany/")).andReturn(null);
+ expect(context.getResource(APPLICATION_SCDL_PATH_DEFAULT)).andReturn(scdl);
+ context.setAttribute(eq(Constants.RUNTIME_ATTRIBUTE), isA(WebappRuntime.class));
+ replay(context);
+ replay(cl);
+ replay(bootClassLoader);
+ expect(listener.getUtils(context)).andReturn(utils);
+ replay(listener);
+ runtime.setServletContext(context);
+ runtime.setRuntimeInfo(isA(WebappRuntimeInfo.class));
+ runtime.setHostClassLoader(cl);
+ runtime.setSystemScdl(systemUrl);
+ runtime.initialize();
+ runtime.deploy(URI.create(compositeId), scdl, URI.create(contextName));
+ replay(runtime);
+
+ ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(cl);
+ listener.contextInitialized(event);
+ } finally {
+ Thread.currentThread().setContextClassLoader(oldCl);
+ }
+ verify(event);
+ verify(utils);
+ verify(context);
+ verify(listener);
+ verify(cl);
+ verify(bootClassLoader);
+ verify(runtime);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ Method getUtilsMethod = TuscanyContextListener.class.getDeclaredMethod("getUtils", ServletContext.class);
+ utils = createMock(WebappUtil.class);
+ listener = createMock(TuscanyContextListener.class, new Method[]{getUtilsMethod});
+ context = createMock(ServletContext.class);
+ cl = createMock(ClassLoader.class);
+ bootClassLoader = createMock(ClassLoader.class);
+ systemUrl = new URL("file:/system.scdl");
+ scdl = new URL("file:/app.scdl");
+ contextName = "webapp";
+ compositeId = "http://locahost/sca";
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyFilterTestCase.java b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyFilterTestCase.java
new file mode 100644
index 0000000000..9d811df46c
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyFilterTestCase.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.runtime.webapp;
+
+import java.io.IOException;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_ATTRIBUTE;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TuscanyFilterTestCase extends TestCase {
+ private TuscanyFilter filter;
+ private FilterConfig config;
+ private ServletContext servletContext;
+ private WebappRuntime runtime;
+ private ServletRequest request;
+ private ServletResponse response;
+ private FilterChain chain;
+
+ public void testFilterInit() {
+ EasyMock.expect(config.getServletContext()).andReturn(servletContext);
+ EasyMock.expect(servletContext.getAttribute(RUNTIME_ATTRIBUTE)).andReturn(runtime);
+
+ EasyMock.replay(servletContext);
+ EasyMock.replay(config);
+ EasyMock.replay(runtime);
+ try {
+ filter.init(config);
+ } catch (ServletException e) {
+ fail(e.getMessage());
+ }
+ EasyMock.verify(servletContext);
+ EasyMock.verify(config);
+ EasyMock.verify(runtime);
+ }
+
+ public void testFilterInitWithNoRuntimeConfigured() {
+ EasyMock.expect(config.getServletContext()).andReturn(servletContext);
+ EasyMock.expect(servletContext.getAttribute(RUNTIME_ATTRIBUTE)).andReturn(null);
+
+ EasyMock.replay(servletContext);
+ EasyMock.replay(config);
+ EasyMock.replay(runtime);
+ try {
+ filter.init(config);
+ fail("Expected a ServletException");
+ } catch (ServletException e) {
+ // OK
+ }
+ EasyMock.verify(servletContext);
+ EasyMock.verify(config);
+ EasyMock.verify(runtime);
+ }
+
+ public void testContextIsAssociatedWithThread() throws ServletException, IOException {
+ EasyMock.expect(config.getServletContext()).andReturn(servletContext);
+ EasyMock.expect(servletContext.getAttribute(RUNTIME_ATTRIBUTE)).andReturn(runtime);
+ EasyMock.replay(servletContext);
+ EasyMock.replay(config);
+ filter.init(config);
+
+ chain.doFilter(EasyMock.same(request), EasyMock.same(response));
+ EasyMock.replay(chain);
+ runtime.startRequest();
+ runtime.stopRequest();
+ EasyMock.replay(runtime);
+ try {
+ filter.doFilter(request, response, chain);
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ EasyMock.verify(chain);
+ EasyMock.verify(runtime);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ filter = new TuscanyFilter();
+ config = EasyMock.createMock(FilterConfig.class);
+ servletContext = EasyMock.createMock(ServletContext.class);
+ runtime = EasyMock.createMock(WebappRuntime.class);
+ request = EasyMock.createMock(ServletRequest.class);
+ response = EasyMock.createMock(ServletResponse.class);
+ chain = EasyMock.createMock(FilterChain.class);
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyServletTestCase.java b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyServletTestCase.java
new file mode 100644
index 0000000000..5213ae9cb1
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanyServletTestCase.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.runtime.webapp;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.host.servlet.ServletRequestInjector;
+import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_ATTRIBUTE;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+/**
+ * Verifies {@link TuscanyServlet} properly services a request
+ *
+ * @version $Rev$ $Date$
+ */
+public class TuscanyServletTestCase extends TestCase {
+
+ public void testRequestInjection() throws Exception {
+ ServletRequest req = createNiceMock(ServletRequest.class);
+ ServletResponse resp = createNiceMock(ServletResponse.class);
+ ServletRequestInjector injector = createMock(ServletRequestInjector.class);
+ injector.service(eq(req), eq(resp));
+ EasyMock.replay(injector);
+ WebappRuntime runtime = createMock(WebappRuntime.class);
+ expect(runtime.getRequestInjector()).andReturn(injector);
+ replay(runtime);
+ ServletContext context = createNiceMock(ServletContext.class);
+ EasyMock.expect(context.getAttribute(RUNTIME_ATTRIBUTE)).andReturn(runtime);
+ EasyMock.replay(context);
+ TuscanyServlet servlet = new TuscanyServlet();
+ ServletConfig config = createMock(ServletConfig.class);
+ expect(config.getServletContext()).andReturn(context);
+ replay(config);
+ servlet.init(config);
+ servlet.service(req, resp);
+ verify(context);
+ verify(injector);
+ }
+
+ public void testRuntimeNotConfigured() throws Exception {
+ ServletContext context = createNiceMock(ServletContext.class);
+ TuscanyServlet servlet = new TuscanyServlet();
+ ServletConfig config = createMock(ServletConfig.class);
+ expect(config.getServletContext()).andReturn(context);
+ replay(config);
+ try {
+ servlet.init(config);
+ fail();
+ } catch (ServletException e) {
+ //expected
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanySessionListenerTestCase.java b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanySessionListenerTestCase.java
new file mode 100644
index 0000000000..cdce50cc2b
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/TuscanySessionListenerTestCase.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.runtime.webapp;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionEvent;
+
+import junit.framework.TestCase;
+import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_ATTRIBUTE;
+import org.easymock.EasyMock;
+
+/**
+ * Verifies {@link org.apache.tuscany.runtime.webapp.TuscanySessionListener} notifies the runtime of session events
+ *
+ * @version $Rev$ $Date$
+ */
+public class TuscanySessionListenerTestCase extends TestCase {
+
+ public void testSessionPropagated() throws Exception {
+ WebappRuntime runtime = EasyMock.createNiceMock(WebappRuntime.class);
+ runtime.sessionCreated(EasyMock.isA(HttpSessionEvent.class));
+ runtime.sessionDestroyed(EasyMock.isA(HttpSessionEvent.class));
+ EasyMock.replay(runtime);
+ ServletContext context = EasyMock.createNiceMock(ServletContext.class);
+ EasyMock.expect(context.getAttribute(RUNTIME_ATTRIBUTE)).andReturn(runtime);
+ EasyMock.replay(context);
+ HttpSession session = EasyMock.createNiceMock(HttpSession.class);
+ EasyMock.expect(session.getServletContext()).andReturn(context);
+ EasyMock.replay(session);
+ HttpSessionEvent event = new HttpSessionEvent(session);
+ TuscanySessionListener listener = new TuscanySessionListener();
+ listener.sessionCreated(event);
+ listener.sessionDestroyed(event);
+ EasyMock.verify(context);
+ EasyMock.verify(runtime);
+ }
+
+ /**
+ * Verifies an error is logged when no runtime is configured
+ *
+ * @throws Exception
+ */
+ public void testRuntimeNotConfigured() throws Exception {
+ ServletContext context = EasyMock.createNiceMock(ServletContext.class);
+ context.log(EasyMock.isA(String.class), EasyMock.isA(ServletException.class));
+ EasyMock.replay(context);
+ TuscanySessionListener listener = new TuscanySessionListener();
+ HttpSession session = EasyMock.createNiceMock(HttpSession.class);
+ EasyMock.expect(session.getServletContext()).andReturn(context);
+ EasyMock.replay(session);
+ HttpSessionEvent event = new HttpSessionEvent(session);
+ listener.sessionCreated(event);
+ EasyMock.verify(context);
+ }
+
+ public void testSessionDestroyedBeforeCreated() throws Exception {
+ TuscanySessionListener listener = new TuscanySessionListener();
+ listener.sessionDestroyed(null);
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/WebappUtilTestCase.java b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/WebappUtilTestCase.java
new file mode 100644
index 0000000000..f865a4e740
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-api/src/test/java/org/apache/tuscany/runtime/webapp/WebappUtilTestCase.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.runtime.webapp;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import javax.servlet.ServletContext;
+
+import junit.framework.TestCase;
+import static org.easymock.classextension.EasyMock.*;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WebappUtilTestCase extends TestCase {
+ private ServletContext context;
+ private WebappUtilImpl listener;
+ private ClassLoader cl;
+ private URL systemUrl;
+
+
+ public void testGetInitParameterWhenSpecified() {
+ String name = "name";
+ String value = "default";
+ expect(context.getInitParameter(name)).andReturn(value);
+ replay(context);
+
+ assertEquals(value, listener.getInitParameter(name, "default"));
+ verify(context);
+ }
+
+ public void testGetInitParameterUsingDefault() {
+ String name = "name";
+ String value = "default";
+ expect(context.getInitParameter(name)).andReturn(null);
+ replay(context);
+
+ assertEquals(value, listener.getInitParameter(name, value));
+ verify(context);
+ }
+
+ public void testGetInitParameterWithZeroLength() {
+ String name = "name";
+ String value = "default";
+ expect(context.getInitParameter(name)).andReturn("");
+ replay(context);
+
+ assertEquals(value, listener.getInitParameter(name, value));
+ verify(context);
+ }
+
+ public void testGetScdlFromWebapp() throws MalformedURLException {
+ String path = "/WEB-INF/test";
+ expect(context.getResource(path)).andReturn(systemUrl);
+ replay(context);
+ replay(cl);
+ assertSame(systemUrl, listener.getScdlURL(path, cl));
+ verify(context);
+ verify(cl);
+ }
+
+ public void testGetScdlFromWebappMissing() throws MalformedURLException {
+ String path = "/WEB-INF/test";
+ expect(context.getResource(path)).andReturn(null);
+ replay(context);
+ expect(cl.getResource(path)).andReturn(null);
+ replay(cl);
+ assertNull(listener.getScdlURL(path, cl));
+ verify(context);
+ verify(cl);
+ }
+
+ public void testGetScdlFromWebappMalformed() throws MalformedURLException {
+ String path = "/WEB-INF/test";
+ expect(context.getResource(path)).andThrow(new MalformedURLException());
+ replay(context);
+ replay(cl);
+ try {
+ listener.getScdlURL(path, cl);
+ fail();
+ } catch (MalformedURLException e) {
+ // OK
+ }
+ verify(context);
+ verify(cl);
+ }
+
+ public void testGetScdlFromClasspath() throws MalformedURLException {
+ String path = "META-INF/test";
+ replay(context);
+ expect(cl.getResource(path)).andReturn(systemUrl);
+ replay(cl);
+ assertSame(systemUrl, listener.getScdlURL(path, cl));
+ verify(context);
+ verify(cl);
+ }
+
+ public void testGetScdlFromClasspathMissing() throws MalformedURLException {
+ String path = "META-INF/test";
+ replay(context);
+ expect(cl.getResource(path)).andReturn(null);
+ replay(cl);
+ assertNull(listener.getScdlURL(path, cl));
+ verify(context);
+ verify(cl);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ context = createMock(ServletContext.class);
+ listener = new WebappUtilImpl(context);
+ cl = createMock(ClassLoader.class);
+ systemUrl = new URL("file:/system.scdl");
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-host/.ruleset b/tags/java/tsss-demo/runtime/webapp/webapp-host/.ruleset
new file mode 100644
index 0000000000..3886f07f2d
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-host/.ruleset
@@ -0,0 +1,190 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<ruleset name="pmd-eclipse">
+ <description>PMD Plugin preferences rule set</description>
+
+
+ <rule ref="rulesets/basic.xml/BooleanInstantiation"/>
+ <rule ref="rulesets/basic.xml/CollapsibleIfStatements"/>
+ <rule ref="rulesets/basic.xml/DoubleCheckedLocking"/>
+<!--<rule ref="rulesets/basic.xml/EmptyCatchBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyFinallyBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyIfStmt"/>-->
+ <rule ref="rulesets/basic.xml/EmptyStatementNotInLoop"/>
+<!--<rule ref="rulesets/basic.xml/EmptyStaticInitializer"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptySwitchStatements"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptySynchronizedBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyTryBlock"/>-->
+<!--<rule ref="rulesets/basic.xml/EmptyWhileStmt"/>-->
+ <rule ref="rulesets/basic.xml/ForLoopShouldBeWhileLoop"/>
+ <rule ref="rulesets/basic.xml/JumbledIncrementer"/>
+<!--<rule ref="rulesets/basic.xml/OverrideBothEqualsAndHashcode"/>-->
+ <rule ref="rulesets/basic.xml/ReturnFromFinallyBlock"/>
+ <rule ref="rulesets/basic.xml/UnconditionalIfStatement"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryConversionTemporary"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryFinalModifier"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryReturn"/>
+<!--<rule ref="rulesets/basic.xml/UselessOverridingMethod"/>-->
+
+<!--<rule ref="rulesets/braces.xml/ForLoopsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/IfElseStmtsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/IfStmtsMustUseBraces"/>-->
+<!--<rule ref="rulesets/braces.xml/WhileLoopsMustUseBraces"/>-->
+
+<!--<rule ref="rulesets/clone.xml/CloneMethodMustImplementCloneable"/>-->
+<!--<rule ref="rulesets/clone.xml/CloneThrowsCloneNotSupportedException"/>-->
+<!--<rule ref="rulesets/clone.xml/ProperCloneImplementation"/>-->
+
+<!--<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>-->
+<!--<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>-->
+<!--<rule ref="rulesets/codesize.xml/TooManyFields"/>-->
+
+<rule ref="rulesets/controversial.xml/AssignmentInOperand"/>
+<!--<rule ref="rulesets/controversial.xml/AtLeastOneConstructor"/>-->
+<!--<rule ref="rulesets/controversial.xml/CallSuperInConstructor"/>-->
+<!--<rule ref="rulesets/controversial.xml/DontImportSun"/>-->
+<!--<rule ref="rulesets/controversial.xml/NullAssignment"/>-->
+<!--<rule ref="rulesets/controversial.xml/OnlyOneReturn"/>-->
+<!--<rule ref="rulesets/controversial.xml/SingularField"/>-->
+<!--<rule ref="rulesets/controversial.xml/SuspiciousOctalEscape"/>-->
+<!--<rule ref="rulesets/controversial.xml/UnnecessaryConstructor"/>-->
+<rule ref="rulesets/controversial.xml/UnnecessaryParentheses"/>
+<!--<rule ref="rulesets/controversial.xml/UnusedModifier"/>-->
+
+<!--<rule ref="rulesets/coupling.xml/CouplingBetweenObjects"/>-->
+<!--<rule ref="rulesets/coupling.xml/ExcessiveImports"/>-->
+<!--<rule ref="rulesets/coupling.xml/LooseCoupling"/>-->
+
+<!--<rule ref="rulesets/design.xml/AbstractClassWithoutAbstractMethod"/>-->
+<!--<rule ref="rulesets/design.xml/AccessorClassGeneration"/>-->
+<!--<rule ref="rulesets/design.xml/AssignmentToNonFinalStatic"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidDeeplyNestedIfStmts"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidInstanceofChecksInCatchClause"/>-->
+<rule ref="rulesets/design.xml/AvoidProtectedFieldInFinalClass"/>
+<!--<rule ref="rulesets/design.xml/AvoidReassigningParameters"/>-->
+<!--<rule ref="rulesets/design.xml/AvoidSynchronizedAtMethodLevel"/>-->
+<!--<rule ref="rulesets/design.xml/BadComparison"/>-->
+<!--<rule ref="rulesets/design.xml/CloseConnection"/>-->
+<!--<rule ref="rulesets/design.xml/CompareObjectsWithEquals"/>-->
+<!--<rule ref="rulesets/design.xml/ConfusingTernary"/>-->
+<rule ref="rulesets/design.xml/ConstructorCallsOverridableMethod"/>
+<!--<rule ref="rulesets/design.xml/DefaultLabelNotLastInSwitchStmt"/>-->
+<!--<rule ref="rulesets/design.xml/FinalFieldCouldBeStatic"/>-->
+<rule ref="rulesets/design.xml/IdempotentOperations"/>
+<!--<rule ref="rulesets/design.xml/ImmutableField"/>-->
+<!--<rule ref="rulesets/design.xml/InstantiationToGetClass"/>-->
+<!--<rule ref="rulesets/design.xml/MissingBreakInSwitch"/>-->
+<!--<rule ref="rulesets/design.xml/MissingStaticMethodInNonInstantiatableClass"/>-->
+<!--<rule ref="rulesets/design.xml/NonCaseLabelInSwitchStatement"/>-->
+<!--<rule ref="rulesets/design.xml/NonStaticInitializer"/>-->
+<rule ref="rulesets/design.xml/OptimizableToArrayCall"/>
+<rule ref="rulesets/design.xml/PositionLiteralsFirstInComparisons"/>
+<rule ref="rulesets/design.xml/SimplifyBooleanExpressions"/>
+<rule ref="rulesets/design.xml/SimplifyBooleanReturns"/>
+<rule ref="rulesets/design.xml/SimplifyConditional"/>
+<!--<rule ref="rulesets/design.xml/SwitchDensity"/>-->
+<!--<rule ref="rulesets/design.xml/SwitchStmtsShouldHaveDefault"/>-->
+<rule ref="rulesets/design.xml/UnnecessaryLocalBeforeReturn"/>
+<!--<rule ref="rulesets/design.xml/UseLocaleWithCaseConversions"/>-->
+<!--<rule ref="rulesets/design.xml/UseNotifyAllInsteadOfNotify"/>-->
+<!--<rule ref="rulesets/design.xml/UseSingleton"/>-->
+
+<!--<rule ref="rulesets/finalizers.xml/EmptyFinalizer"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeOnlyCallsSuperFinalize"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeOverloaded"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeDoesNotCallSuperFinalize"/>-->
+<!--<rule ref="rulesets/finalizers.xml/FinalizeShouldBeProtected"/>-->
+<!--<rule ref="rulesets/finalizers.xml/AvoidCallingFinalize"/>-->
+
+<!--<rule ref="rulesets/imports.xml/DuplicateImports"/>-->
+<!--<rule ref="rulesets/imports.xml/DontImportJavaLang"/>-->
+<!--<rule ref="rulesets/imports.xml/UnusedImports"/>-->
+<!--<rule ref="rulesets/imports.xml/ImportFromSamePackage"/>-->
+
+<!--<rule ref="rulesets/javabeans.xml/BeanMembersShouldSerialize"/>-->
+<!--<rule ref="rulesets/javabeans.xml/MissingSerialVersionUID"/>-->
+
+<!--<rule ref="rulesets/junit.xml/JUnitStaticSuite"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitSpelling"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitAssertionsShouldIncludeMessage"/>-->
+<!--<rule ref="rulesets/junit.xml/JUnitTestsShouldIncludeAssert"/>-->
+<!--<rule ref="rulesets/junit.xml/TestClassWithoutTestCases"/>-->
+<!--<rule ref="rulesets/junit.xml/UnnecessaryBooleanAssertion"/>-->
+<!--<rule ref="rulesets/junit.xml/UseAssertEqualsInsteadOfAssertTrue"/>-->
+<!--<rule ref="rulesets/junit.xml/UseAssertSameInsteadOfAssertTrue"/>-->
+
+ <!--<rule ref="rulesets/logging-java.xml/AvoidPrintStackTrace"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/MoreThanOneLogger"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/LogBlockWithoutIf"/>-->
+ <!--<rule ref="rulesets/logging-java.xml/SystemPrintln"/>-->
+ <!--<rule ref="rulesets/logging-jakarta-commons.xml/UseCorrectExceptionLogging"/>-->
+ <!--<rule ref="rulesets/logging-jakarta-commons.xml/ProperLogger"/>-->
+
+ <!--<rule ref="rulesets/naming.xml/ShortVariable"/>-->
+ <!--<rule ref="rulesets/naming.xml/LongVariable"/>-->
+ <!--<rule ref="rulesets/naming.xml/ShortMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/VariableNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/MethodNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/ClassNamingConventions"/>-->
+ <!--<rule ref="rulesets/naming.xml/AbstractNaming"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidDollarSigns"/>-->
+ <!--<rule ref="rulesets/naming.xml/MethodWithSameNameAsEnclosingClass"/>-->
+ <!--<rule ref="rulesets/naming.xml/SuspiciousHashcodeMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/SuspiciousConstantFieldName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingTypeName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingMethodName"/>-->
+ <!--<rule ref="rulesets/naming.xml/AvoidNonConstructorMethodsWithClassName"/>-->
+ <!--<rule ref="rulesets/naming.xml/NoPackage"/>-->
+ <!--<rule ref="rulesets/naming.xml/PackageCase"/>-->
+
+ <!--<rule ref="rulesets/optimizations.xml/LocalVariableCouldBeFinal"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/MethodArgumentCouldBeFinal"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/AvoidInstantiatingObjectsInLoops"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/UseArrayListInsteadOfVector"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/SimplifyStartsWith"/>-->
+ <!--<rule ref="rulesets/optimizations.xml/UseStringBufferForStringAppends"/>-->
+
+ <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingThrowable"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/SignatureDeclareThrowsException"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/ExceptionAsFlowControl"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingNPE"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingRawExceptionTypes"/>-->
+ <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingNullPointerException"/>-->
+
+ <!--<rule ref="rulesets/strings.xml/AvoidDuplicateLiterals"/>-->
+ <!--<rule ref="rulesets/strings.xml/StringInstantiation"/>-->
+ <!--<rule ref="rulesets/strings.xml/StringToString"/>-->
+ <!--<rule ref="rulesets/strings.xml/AvoidConcatenatingNonLiteralsInStringBuffer"/>-->
+ <!--<rule ref="rulesets/strings.xml/UnnecessaryCaseChange"/>-->
+
+ <!--<rule ref="rulesets/sunsecure.xml/MethodReturnsInternalArray"/>-->
+ <!--<rule ref="rulesets/sunsecure.xml/ArrayIsStoredDirectly"/>-->
+
+ <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/>
+ <rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/>
+ <rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/>
+ <!--<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>-->
+
+</ruleset>
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-host/LICENSE.txt b/tags/java/tsss-demo/runtime/webapp/webapp-host/LICENSE.txt
new file mode 100644
index 0000000000..0084319535
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-host/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, serviceDefinition marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-host/NOTICE.txt b/tags/java/tsss-demo/runtime/webapp/webapp-host/NOTICE.txt
new file mode 100644
index 0000000000..d83ebbe236
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-host/NOTICE.txt
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-host/pom.xml b/tags/java/tsss-demo/runtime/webapp/webapp-host/pom.xml
new file mode 100644
index 0000000000..751bbca302
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-host/pom.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca.runtime</groupId>
+ <artifactId>webapp</artifactId>
+ <version>2.0-alpha2-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca.runtime.webapp</groupId>
+ <artifactId>webapp-host</artifactId>
+ <packaging>jar</packaging>
+ <name>Apache Tuscany Web Application Host</name>
+ <description>Host code to run Tuscany in a Web application.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca.kernel</groupId>
+ <artifactId>tuscany-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sca.runtime.services</groupId>
+ <artifactId>maven</artifactId>
+ <version>${project.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca.runtime.webapp</groupId>
+ <artifactId>webapp-api</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionId.java b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionId.java
new file mode 100644
index 0000000000..8d3f1153ba
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionId.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.runtime.webapp;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.tuscany.core.component.ScopeIdentifier;
+
+/**
+ * Implements a <code>ScopeIdentifier</code> for a Servlet-based transport.
+ * Wraps an <code>HttpServletRequest</code> so that the session id associated
+ * with the current request may be lazily retrieved by the module context - i.e.
+ * if a session context or session-scoped component is not accessed, no session
+ * is created.
+ *
+ * @version $Rev$ $Date$
+ */
+public class LazyHTTPSessionId implements ScopeIdentifier {
+
+ private HttpServletRequest request;
+
+ //----------------------------------
+ // Constructors
+ //----------------------------------
+
+ public LazyHTTPSessionId(HttpServletRequest request) {
+ this.request = request;
+ }
+
+ //----------------------------------
+ // Methods
+ //----------------------------------
+
+ /**
+ * Returns the session identifier
+ *
+ * @see org.apache.tuscany.core.context.ScopeIdentifier#getIdentifier()
+ */
+ public Object getIdentifier() {
+ return request.getSession(true);
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletHostImpl.java b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletHostImpl.java
new file mode 100644
index 0000000000..17dbe127d3
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletHostImpl.java
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.runtime.webapp;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Service;
+
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.event.Event;
+import org.apache.tuscany.spi.event.EventFilter;
+import org.apache.tuscany.spi.event.EventPublisher;
+import org.apache.tuscany.spi.event.RuntimeEventListener;
+import org.apache.tuscany.spi.host.ServletHost;
+import org.apache.tuscany.spi.model.Scope;
+
+import org.apache.tuscany.core.component.event.HttpRequestEnded;
+import org.apache.tuscany.core.component.event.HttpRequestStart;
+import org.apache.tuscany.core.component.event.HttpSessionEnd;
+import org.apache.tuscany.core.component.event.HttpSessionStart;
+import org.apache.tuscany.host.servlet.ServletRequestInjector;
+
+/**
+ * A <code>ServletHost</code> implementation that forwards requests to registered servlets
+ *
+ * @version $Rev$ $Date$
+ */
+@Service(ServletHost.class)
+@EagerInit
+public class ServletHostImpl implements ServletHost, ServletRequestInjector, EventPublisher {
+ protected Map<String, Servlet> servlets;
+ protected ScopeRegistry registry;
+ protected WorkContext workContext;
+
+ public ServletHostImpl() {
+ this.servlets = new HashMap<String, Servlet>();
+ }
+
+ @Reference(required = false)
+ public void setSessionScopeContainer(ScopeRegistry registry) {
+ this.registry = registry;
+ }
+
+ @Reference(required = false)
+ public void setWorkContext(WorkContext workContext) {
+ this.workContext = workContext;
+ }
+
+ public void service(ServletRequest req, ServletResponse resp) throws ServletException, IOException {
+ assert req instanceof HttpServletRequest : "implementation only supports HttpServletRequest";
+ String path = ((HttpServletRequest) req).getPathInfo();
+ Servlet servlet = servlets.get(path);
+ if (servlet == null) {
+ throw new IllegalStateException("No servlet registered for path: " + path);
+ }
+ servlet.service(req, resp);
+ }
+
+ public void registerMapping(String path, Servlet servlet) {
+ if (servlets.containsKey(path)) {
+ throw new IllegalStateException("Servlet already registered at path: " + path);
+ }
+ servlets.put(path, servlet);
+ }
+
+ public boolean isMappingRegistered(String mapping) {
+ return servlets.containsKey(mapping);
+
+ }
+
+ public Servlet unregisterMapping(String path) {
+ return servlets.remove(path);
+ }
+
+ public void addListener(RuntimeEventListener listener) {
+ throw new UnSupportedRuntimeException("Not Supported");
+
+ }
+
+ public void addListener(EventFilter filter, RuntimeEventListener listener) {
+ throw new UnSupportedRuntimeException("Not Supported");
+
+ }
+
+ public void publish(Event event) {
+ if (null != registry && (event instanceof HttpSessionStart || event instanceof HttpSessionEnd)) {
+ ScopeContainer sc = registry.getScopeContainer(Scope.SESSION);
+ if (null != sc) {
+ sc.onEvent(event);
+
+ }
+ }
+ if (null != workContext) {
+ if (event instanceof HttpRequestStart) {
+ Object key = ((HttpRequestStart) event).getId();
+ if (null != key) {
+ workContext.setIdentifier(Scope.SESSION, ((HttpRequestStart) event).getId());
+ } else { // new request with no session.
+ workContext.clearIdentifier(Scope.SESSION);
+ }
+ } else if (event instanceof HttpRequestEnded) {
+ workContext.clearIdentifier(Scope.SESSION);
+
+ }
+
+ }
+
+ }
+
+ public void removeListener(RuntimeEventListener listener) {
+ throw new UnSupportedRuntimeException("Not Supported");
+
+ }
+
+} \ No newline at end of file
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherInitException.java b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherInitException.java
new file mode 100644
index 0000000000..0b47744e5f
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletLauncherInitException.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.runtime.webapp;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * Thrown when an error is encountered booting the runtme in a web app environment
+ *
+ * @version $Rev$ $Date$
+ */
+public class ServletLauncherInitException extends TuscanyRuntimeException {
+
+ public ServletLauncherInitException() {
+ }
+
+ public ServletLauncherInitException(String message) {
+ super(message);
+ }
+
+ public ServletLauncherInitException(String message, String identifier) {
+ super(message, identifier);
+ }
+
+ public ServletLauncherInitException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ServletLauncherInitException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/UnSupportedRuntimeException.java b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/UnSupportedRuntimeException.java
new file mode 100644
index 0000000000..9cfa7345d6
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/UnSupportedRuntimeException.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.runtime.webapp;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * Thrown when an error is encountered booting the runtme in a web app environment
+ *
+ * @version $Rev: 439728 $ $Date: 2006-09-03 02:02:44 -0400 (Sun, 03 Sep 2006) $
+ */
+public class UnSupportedRuntimeException extends TuscanyRuntimeException {
+
+ public UnSupportedRuntimeException() {
+ }
+
+ public UnSupportedRuntimeException(String message) {
+ super(message);
+ }
+
+ public UnSupportedRuntimeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public UnSupportedRuntimeException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebResourceScanExtender.java b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebResourceScanExtender.java
new file mode 100644
index 0000000000..41069b574b
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebResourceScanExtender.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.runtime.webapp;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Set;
+import javax.servlet.ServletContext;
+
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.EagerInit;
+
+import org.apache.tuscany.core.services.extension.AbstractExtensionDeployer;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@EagerInit
+public class WebResourceScanExtender extends AbstractExtensionDeployer {
+ private final WebappRuntimeInfo runtimeInfo;
+ private final String path;
+
+ public WebResourceScanExtender(@Reference WebappRuntimeInfo runtimeInfo,
+ @Property(name = "path")String path) {
+ this.runtimeInfo = runtimeInfo;
+ this.path = path;
+ }
+
+ @Init
+ public void init() {
+ ServletContext servletContext = runtimeInfo.getServletContext();
+ Set extensions = servletContext.getResourcePaths(path);
+ if (extensions == null || extensions.isEmpty()) {
+ // no extensions in this webapp
+ return;
+ }
+
+ for (Object e : extensions) {
+ String extensionPath = (String) e;
+ URL extension;
+ try {
+ extension = servletContext.getResource(extensionPath);
+ } catch (MalformedURLException e1) {
+ // web container should return an invalid URL for a path it gave us
+ throw new AssertionError();
+ }
+
+ String name = extensionPath.substring(path.length());
+ if (name.charAt(name.length() - 1) == '/') {
+ // TODO support exploded extensions
+ continue;
+ }
+ if (name.charAt(0) == '.') {
+ // hidden file
+ continue;
+ }
+
+ int lastDot = name.lastIndexOf('.');
+ if (lastDot != -1) {
+ name = name.substring(0, lastDot);
+ }
+ deployExtension(name, extension);
+ }
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java
new file mode 100644
index 0000000000..8453f5c934
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java
@@ -0,0 +1,209 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.runtime.webapp;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.Collection;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSessionEvent;
+
+import org.apache.tuscany.core.runtime.AbstractRuntime;
+import org.apache.tuscany.host.runtime.InitializationException;
+import org.apache.tuscany.host.servlet.ServletRequestInjector;
+import org.apache.tuscany.runtime.webapp.implementation.webapp.WebappComponent;
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ComponentException;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.GroupInitializationException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.resolver.ResolutionException;
+
+/**
+ * Bootstrapper for the Tuscany runtime in a web application host. This listener manages one runtime per servlet
+ * context; the lifecycle of that runtime corresponds to the the lifecycle of the associated servlet context.
+ * <p/>
+ * The bootstrapper launches the runtime, booting system extensions and applications, according to the servlet
+ * parameters defined in {@link Constants}. When the runtime is instantiated, it is placed in the servlet context with
+ * the attribute {@link Constants#RUNTIME_PARAM}. The runtime implements {@link WebappRuntime} so that filters and
+ * servlets loaded in the parent web app classloader may pass events and requests to it.
+ * <p/>
+ *
+ * @version $$Rev$$ $$Date$$
+ */
+
+public class WebappRuntimeImpl extends AbstractRuntime<WebappRuntimeInfo> implements WebappRuntime {
+ private ServletContext servletContext;
+
+ private ServletRequestInjector requestInjector;
+
+ public WebappRuntimeImpl() {
+ super(WebappRuntimeInfo.class);
+ }
+
+ public ServletContext getServletContext() {
+ return servletContext;
+ }
+
+ public void setServletContext(ServletContext servletContext) {
+ this.servletContext = servletContext;
+ }
+
+/*
+ public void initialize() throws InitializationException {
+ super.initialize();
+
+ try {
+ SCAObject host = getTuscanySystem().getSystemChild("servletHost");
+ if (!(host instanceof AtomicComponent)) {
+ throw new InitializationException("Servlet host must be an atomic component");
+ }
+ requestInjector = (ServletRequestInjector) ((AtomicComponent) host).getTargetInstance();
+
+ if (getApplicationScdl() == null) {
+ throw new TuscanyInitException("Could not find application SCDL");
+ }
+ getRuntime().getRootComponent().start();
+ application = deployApplicationScdl(getDeployer(),
+ getRuntime().getRootComponent(),
+ getApplicationName(),
+ getApplicationScdl(),
+ getHostClassLoader());
+ application.start();
+ CompositeComponent current = application;
+ String path = servletContext.getInitParameter(Constants.CURRENT_COMPOSITE_PATH_PARAM);
+ if (path != null) {
+ StringTokenizer tokenizer = new StringTokenizer(path, "/");
+ while (tokenizer.hasMoreTokens()) {
+ SCAObject o = current.getChild(tokenizer.nextToken());
+ if (!(o instanceof CompositeComponent)) {
+ throw new ServletLauncherInitException("Invalid context path", path);
+ }
+ current = (CompositeComponent) o;
+ }
+ }
+ context = new CompositeContextImpl(current, getWireService());
+ servletContext.setAttribute(Constants.CONTEXT_ATTRIBUTE, context);
+ } catch (Exception e) {
+ throw new ServletLauncherInitException(e);
+ }
+ }
+*/
+
+ @Deprecated
+ public void deploy(URI compositeId, URL applicationScdl, URI componentId) throws InitializationException {
+ CompositeImplementation impl = new CompositeImplementation();
+ impl.setScdlLocation(applicationScdl);
+ impl.setClassLoader(getHostClassLoader());
+
+ ComponentDefinition<CompositeImplementation> definition =
+ new ComponentDefinition<CompositeImplementation>(compositeId, impl);
+ Collection<Component> components;
+ try {
+ components = getDeployer().deploy(null, definition);
+ } catch (LoaderException e) {
+ throw new InitializationException(e);
+ } catch (BuilderException e) {
+ throw new InitializationException(e);
+ } catch (ComponentException e) {
+ throw new InitializationException(e);
+ } catch (ResolutionException e) {
+ throw new InitializationException(e);
+ }
+ for (Component component : components) {
+ component.start();
+ }
+
+ try {
+ ScopeRegistry scopeRegistry = getScopeRegistry();
+ ScopeContainer<URI> container = scopeRegistry.getScopeContainer(Scope.COMPOSITE);
+ container.startContext(compositeId, compositeId);
+ getWorkContext().setIdentifier(Scope.COMPOSITE, compositeId);
+ } catch (GroupInitializationException e) {
+ throw new InitializationException(e);
+ }
+
+ componentId = URI.create(compositeId.toString()+'/').resolve(componentId);
+ Component component = getComponentManager().getComponent(componentId);
+ if (component == null) {
+ throw new TuscanyInitException("No component found with id " + componentId, componentId.toString());
+ }
+ if (component instanceof WebappComponent) {
+ WebappComponent webapp = (WebappComponent) component;
+ webapp.bind(getServletContext());
+ }
+ }
+
+ public ServletRequestInjector getRequestInjector() {
+ return requestInjector;
+ }
+
+ public void sessionCreated(HttpSessionEvent event) {
+/*
+ HttpSessionStart startSession = new HttpSessionStart(this, event.getSession().getId());
+ application.publish(startSession);
+ ((EventPublisher) requestInjector).publish(startSession);
+*/
+ }
+
+ public void sessionDestroyed(HttpSessionEvent event) {
+/*
+ HttpSessionEnd endSession = new HttpSessionEnd(this, event.getSession().getId());
+ application.publish(endSession);
+ ((EventPublisher) requestInjector).publish(endSession);
+*/
+ }
+
+ public void httpRequestStarted(HttpServletRequest request) {
+/*
+ HttpSession session = request.getSession(false);
+ Object sessionId = session == null ? new LazyHTTPSessionId(request) : session.getId();
+ HttpRequestStart httpRequestStart = new HttpRequestStart(this, sessionId);
+ application.publish(httpRequestStart);
+ ((EventPublisher) requestInjector).publish(httpRequestStart);
+*/
+ }
+
+ public void httpRequestEnded(Object sessionid) {
+/*
+ HttpRequestEnded httpRequestEnded = new HttpRequestEnded(this, sessionid);
+ application.publish(httpRequestEnded);
+ ((EventPublisher) requestInjector).publish(httpRequestEnded);
+*/
+ }
+
+
+ public void startRequest() {
+/*
+ application.publish(new RequestStart(this));
+*/
+ }
+
+ public void stopRequest() {
+/*
+ application.publish(new RequestEnd(this));
+*/
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappBuilder.java b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappBuilder.java
new file mode 100644
index 0000000000..ea9c44c48b
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappBuilder.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.runtime.webapp.implementation.webapp;
+
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentBuilderExtension;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.PropertyValue;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WebappBuilder extends ComponentBuilderExtension<WebappImplementation> {
+ protected Class<WebappImplementation> getImplementationType() {
+ return WebappImplementation.class;
+ }
+
+ public Component build(ComponentDefinition<WebappImplementation> definition, DeploymentContext context)
+ throws BuilderException {
+
+ URI uri = definition.getUri();
+ WebappComponentType componentType = definition.getImplementation().getComponentType();
+
+ Map<String, ObjectFactory<?>> attributes = new HashMap<String, ObjectFactory<?>>();
+ for (PropertyValue<?> property : definition.getPropertyValues().values()) {
+ ObjectFactory<?> factory = property.getValueFactory();
+ if (factory != null) {
+ attributes.put(property.getName(), factory);
+ }
+ }
+
+ Map<String, Class<?>> referenceTypes = new HashMap<String, Class<?>>();
+ for (ReferenceDefinition referenceDefinition : componentType.getReferences().values()) {
+ String name = referenceDefinition.getUri().getFragment();
+ Class<?> type = referenceDefinition.getServiceContract().getInterfaceClass();
+ referenceTypes.put(name, type);
+ }
+
+ return new WebappComponent(uri, proxyService, workContext, context.getGroupId(), attributes, referenceTypes);
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappComponent.java b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappComponent.java
new file mode 100644
index 0000000000..f4b3276c6b
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappComponent.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.runtime.webapp.implementation.webapp;
+
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.servlet.ServletContext;
+
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.ServiceReference;
+
+import org.apache.tuscany.spi.ObjectCreationException;
+import org.apache.tuscany.spi.ObjectFactory;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.TargetInvokerCreationException;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.extension.AtomicComponentExtension;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.physical.PhysicalOperationDefinition;
+import org.apache.tuscany.spi.wire.ProxyService;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.Wire;
+
+import org.apache.tuscany.core.component.ComponentContextImpl;
+import org.apache.tuscany.core.component.ComponentContextProvider;
+import org.apache.tuscany.core.component.ServiceReferenceImpl;
+import org.apache.tuscany.core.wire.WireObjectFactory;
+import org.apache.tuscany.runtime.webapp.Constants;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WebappComponent extends AtomicComponentExtension implements ComponentContextProvider {
+ private final Map<String, ObjectFactory<?>> propertyFactories;
+ private final Map<String, Class<?>> referenceTypes;
+ private final Map<String, Wire> referenceFactories;
+ private final ComponentContext context;
+
+ public WebappComponent(URI name,
+ ProxyService proxyService,
+ WorkContext workContext,
+ URI groupId,
+ Map<String, ObjectFactory<?>> attributes,
+ Map<String, Class<?>> referenceTypes) {
+ super(name, proxyService, workContext, groupId, 0, 0, 0);
+ this.propertyFactories = attributes;
+ this.referenceTypes = referenceTypes;
+ referenceFactories = new ConcurrentHashMap<String, Wire>(referenceTypes.size());
+ context = new ComponentContextImpl(this);
+ }
+
+ public List<Wire> getWires(String name) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void attachCallbackWire(Wire wire) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void attachWire(Wire wire) {
+ String name = wire.getSourceUri().getFragment();
+ referenceFactories.put(name, wire);
+ }
+
+ public void attachWires(List<Wire> wires) {
+ throw new UnsupportedOperationException();
+ }
+
+ protected <B> ObjectFactory<B> createWireFactory(Class<B> interfaze, Wire wire) {
+ return new WireObjectFactory<B>(interfaze, wire, proxyService);
+ }
+
+ public void bind(ServletContext servletContext) {
+ servletContext.setAttribute(Constants.CONTEXT_ATTRIBUTE, getComponentContext());
+ for (Map.Entry<String, ObjectFactory<?>> entry : propertyFactories.entrySet()) {
+ servletContext.setAttribute(entry.getKey(), entry.getValue().getInstance());
+ }
+ for (Map.Entry<String, Wire> entry : referenceFactories.entrySet()) {
+ String name = entry.getKey();
+ Wire wire = entry.getValue();
+ Class<?> type = referenceTypes.get(name);
+ ObjectFactory<?> factory = createWireFactory(type, wire);
+ servletContext.setAttribute(name, factory.getInstance());
+ }
+ }
+
+
+ public TargetInvoker createTargetInvoker(String targetName, Operation operation)
+ throws TargetInvokerCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public TargetInvoker createTargetInvoker(String targetName, PhysicalOperationDefinition operation)
+ throws TargetInvokerCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object createInstance() throws ObjectCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public InstanceWrapper<?> createInstanceWrapper() throws ObjectCreationException {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object getTargetInstance() throws TargetResolutionException {
+ throw new UnsupportedOperationException();
+ }
+
+ public ComponentContext getComponentContext() {
+ return context;
+ }
+
+ public <B> B getProperty(Class<B> type, String propertyName) {
+ ObjectFactory<?> factory = propertyFactories.get(propertyName);
+ if (factory != null) {
+ return type.cast(factory.getInstance());
+ } else {
+ return null;
+ }
+
+ }
+
+ public <B> B getService(Class<B> type, String name) {
+ Wire wire = referenceFactories.get(name);
+ if (wire == null) {
+ return null;
+ }
+ ObjectFactory<B> factory = createWireFactory(type, wire);
+ return factory.getInstance();
+ }
+
+ public <B> ServiceReference<B> getServiceReference(Class<B> type, String name) {
+ Wire wire = referenceFactories.get(name);
+ if (wire == null) {
+ return null;
+ }
+ ObjectFactory<B> factory = createWireFactory(type, wire);
+ return new ServiceReferenceImpl<B>(type, factory);
+ }
+
+ public <B, R extends CallableReference<B>> R cast(B target) {
+ return (R) proxyService.cast(target);
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappComponentType.java b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappComponentType.java
new file mode 100644
index 0000000000..89b3f8283a
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappComponentType.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.runtime.webapp.implementation.webapp;
+
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+import org.apache.tuscany.spi.model.Scope;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WebappComponentType extends ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> {
+ public Scope getImplementationScope() {
+ return Scope.COMPOSITE;
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappComponentTypeLoader.java b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappComponentTypeLoader.java
new file mode 100644
index 0000000000..56bd65169c
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappComponentTypeLoader.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.runtime.webapp.implementation.webapp;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentTypeLoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WebappComponentTypeLoader extends ComponentTypeLoaderExtension<WebappImplementation> {
+
+ public WebappComponentTypeLoader(@Reference LoaderRegistry loaderRegistry) {
+ super(loaderRegistry);
+ }
+
+ protected Class<WebappImplementation> getImplementationClass() {
+ return WebappImplementation.class;
+ }
+
+ public void load(
+ WebappImplementation implementation,
+ DeploymentContext deploymentContext)
+ throws LoaderException {
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappImplementation.java b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappImplementation.java
new file mode 100644
index 0000000000..03a8a7d5be
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappImplementation.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.runtime.webapp.implementation.webapp;
+
+import org.apache.tuscany.spi.model.Implementation;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WebappImplementation extends Implementation<WebappComponentType> {
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappLoader.java b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappLoader.java
new file mode 100644
index 0000000000..7794979a03
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/implementation/webapp/WebappLoader.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.runtime.webapp.implementation.webapp;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import javax.xml.namespace.QName;
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.osoa.sca.annotations.Reference;
+
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.idl.java.InterfaceJavaIntrospector;
+import org.apache.tuscany.spi.implementation.java.ProcessingException;
+import org.apache.tuscany.spi.loader.IllegalSCDLNameException;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.MissingResourceException;
+import org.apache.tuscany.spi.loader.UnrecognizedElementException;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.ServiceContract;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WebappLoader extends LoaderExtension<WebappImplementation> {
+ private static final QName WEBAPP = new QName("http://tuscany.apache.org/xmlns/sca/2.0-alpha", "webapp");
+
+ private final InterfaceJavaIntrospector introspector;
+
+ public WebappLoader(@Reference LoaderRegistry registry,
+ @Reference InterfaceJavaIntrospector introspector) {
+ super(registry);
+ this.introspector = introspector;
+ }
+
+ public QName getXMLType() {
+ return WEBAPP;
+ }
+
+ public WebappImplementation load(
+ ModelObject object,
+ XMLStreamReader reader,
+ DeploymentContext deploymentContext)
+ throws XMLStreamException, LoaderException {
+
+ WebappComponentType componentType = new WebappComponentType();
+ WebappImplementation impl = new WebappImplementation();
+ impl.setComponentType(componentType);
+
+ while (true) {
+ switch (reader.next()) {
+ case START_ELEMENT:
+ QName qname = reader.getName();
+ if ("reference".equals(qname.getLocalPart())) {
+ defineReference(componentType, reader, deploymentContext);
+ } else {
+ throw new UnrecognizedElementException(qname);
+ }
+ reader.next();
+ break;
+ case END_ELEMENT:
+ return impl;
+ }
+ }
+ }
+
+ protected void defineReference(WebappComponentType componentType,
+ XMLStreamReader reader,
+ DeploymentContext context) throws LoaderException {
+ String name = reader.getAttributeValue(null, "name");
+ URI referenceURI;
+ try {
+ referenceURI = new URI('#' + name);
+ } catch (URISyntaxException e) {
+ throw new IllegalSCDLNameException(e);
+ }
+
+ String className = reader.getAttributeValue(null, "interface");
+ if (className == null) {
+ className = reader.getAttributeValue(null, "class");
+ }
+
+ Class<?> referenceType;
+ try {
+ referenceType = context.getClassLoader().loadClass(className);
+ } catch (ClassNotFoundException e) {
+ throw new MissingResourceException(className, e);
+ }
+
+ ServiceContract serviceContract;
+ try {
+ serviceContract = introspector.introspect(referenceType);
+ } catch (InvalidServiceContractException e) {
+ throw new ProcessingException("Invalid service contract", name, e);
+ }
+
+ ReferenceDefinition definition = new ReferenceDefinition(referenceURI, serviceContract);
+ componentType.add(definition);
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/resources/META-INF/tuscany/webapp.scdl b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/resources/META-INF/tuscany/webapp.scdl
new file mode 100644
index 0000000000..35ee968b32
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/main/resources/META-INF/tuscany/webapp.scdl
@@ -0,0 +1,193 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<!--
+ Default system configuration for the launcher environment.
+
+ $Rev$ $Date$
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ name="org.apache.tuscany.runtime.webapp.System"
+ autowire="true">
+
+ <!-- Component that provides the Deployer service -->
+ <component name="deployer">
+ <system:implementation.system class="org.apache.tuscany.core.deployer.DeployerImpl"/>
+ </component>
+
+ <!-- Work management -->
+ <component name="WorkContext">
+ <system:implementation.system class="org.apache.tuscany.core.component.WorkContextImpl"/>
+ </component>
+
+ <!-- Wire service -->
+ <component name="proxyService">
+ <system:implementation.system class="org.apache.tuscany.core.wire.jdk.JDKProxyService"/>
+ </component>
+
+ <!-- Builder and BuilderRegistry -->
+ <component name="builder">
+ <system:implementation.system class="org.apache.tuscany.core.builder.BuilderRegistryImpl"/>
+ </component>
+
+ <!-- Loader and LoaderRegistry -->
+ <component name="loader">
+ <system:implementation.system class="org.apache.tuscany.core.loader.LoaderRegistryImpl"/>
+ </component>
+
+ <!-- Introspector and IntrospectionRegistry -->
+ <component name="introspector">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.IntrospectionRegistryImpl"/>
+ </component>
+
+ <!-- Connector infrastructure -->
+ <component name="connector">
+ <system:implementation.system class="org.apache.tuscany.core.builder.ConnectorImpl"/>
+ </component>
+
+ <component name="interceptorBuilderRegistry">
+ <system:implementation.system
+ class="org.apache.tuscany.core.builder.interceptor.InterceptorBuilderRegistryImpl"/>
+ </component>
+
+ <component name="wireAttacherRegistry">
+ <system:implementation.system
+ class="org.apache.tuscany.core.builder.physical.WireAttacherRegistryImpl"/>
+ </component>
+
+ <component name="wirePostProcessorRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.builder.WirePostProcessorRegistryImpl"/>
+ </component>
+
+ <!-- Resource host registry -->
+ <component name="resourceHostRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.services.host.DelegatingResourceHostRegistry"/>
+ </component>
+
+ <!-- Default scopes -->
+ <component name="scope.stateless">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.StatelessScopeContainer"/>
+ </component>
+
+<!--
+ <component name="scope.httpsession">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.HttpSessionScopeContainer"/>
+ </component>
+-->
+
+<!--
+ <component name="scope.request">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.RequestScopeContainer"/>
+ </component>
+-->
+
+<!--
+ <component name="scope.conversational">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.ConversationalScopeContainer"/>
+ </component>
+-->
+
+ <!-- include loader configuration -->
+ <include name="org.apache.tuscany.launcher.Loader" scdlResource="org/apache/tuscany/core/loader.scdl"/>
+
+ <!-- include implementation processor configuration -->
+ <include name="org.apache.tuscany.launcher.Implementation" scdlResource="org/apache/tuscany/core/implementation.scdl"/>
+
+ <!-- Java interface definition language -->
+ <include name="org.apache.tuscany.launcher.InterfaceJava" scdlResource="org/apache/tuscany/core/interfaceJava.scdl"/>
+
+ <!-- include omposite implementation type -->
+ <include name="org.apache.tuscany.launcher.Composite" scdlResource="org/apache/tuscany/core/composite.scdl"/>
+
+ <!-- System implementation type -->
+ <include name="org.apache.tuscany.launcher.SystemImplementation" scdlResource="org/apache/tuscany/core/systemImplementation.scdl"/>
+
+ <!-- Java implementation type -->
+ <include name="org.apache.tuscany.launcher.JavaImplementation" scdlResource="org/apache/tuscany/core/javaImplementation.scdl"/>
+
+ <!-- Data Binding -->
+ <include name="org.apache.tuscany.launcher.DataBinding" scdlResource="org/apache/tuscany/core/databinding.scdl"/>
+
+ <!-- WorkScheduler service -->
+ <component name="workManager">
+ <system:implementation.system
+ class="org.apache.tuscany.core.services.work.jsr237.workmanager.ThreadPoolWorkManager"/>
+ <property name="poolSize">10</property>
+ </component>
+
+ <component name="workScheduler">
+ <system:implementation.system class="org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler"/>
+ </component>
+
+ <!-- Web app ServletHost -->
+ <component name="servletHost">
+ <system:implementation.system class="org.apache.tuscany.runtime.webapp.ServletHostImpl"/>
+ </component>
+
+ <component name="policyBuilderRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.policy.PolicyBuilderRegistryImpl"/>
+ </component>
+
+ <component name="propertyFactory">
+ <system:implementation.system class="org.apache.tuscany.core.property.PropertyObjectFactoryImpl"/>
+ </component>
+
+ <!-- Store infrastructure -->
+ <component name="store">
+ <system:implementation.system class="org.apache.tuscany.core.services.store.memory.MemoryStore"/>
+ </component>
+
+ <component name="artifactRepository">
+ <system:implementation.system class="org.apache.tuscany.services.maven.MavenArtifactRepository"/>
+ <property name="remoteRepoUrl">http://repo1.maven.org/maven2/,http://people.apache.org/repo/m2-snapshot-repository,http://people.apache.org/repo/m2-incubating-repository/,http://people.apache.org/repo/m1-snapshot-repository/</property>
+ </component>
+
+ <component name="extender" initLevel="90">
+ <system:implementation.system class="org.apache.tuscany.runtime.webapp.WebResourceScanExtender"/>
+ <property name="path">/WEB-INF/tuscany/extensions/</property>
+ </component>
+
+ <component name="wireLoader">
+ <system:implementation.system class="org.apache.tuscany.core.loader.WireLoader"/>
+ </component>
+
+ <!-- the local binding -->
+ <component name="localBindingLoader">
+ <system:implementation.system class="org.apache.tuscany.core.binding.local.LocalBindingLoader"/>
+ </component>
+
+ <component name="localBindingBuilder">
+ <system:implementation.system class="org.apache.tuscany.core.binding.local.LocalBindingBuilder"/>
+ </component>
+
+ <!-- webapp component implementation -->
+ <component name="webappLoader">
+ <system:implementation.system class="org.apache.tuscany.runtime.webapp.implementation.webapp.WebappLoader"/>
+ </component>
+
+ <component name="webappComponentTypeLoader">
+ <system:implementation.system class="org.apache.tuscany.runtime.webapp.implementation.webapp.WebappComponentTypeLoader"/>
+ </component>
+
+ <component name="webappComponentTypeBuilder">
+ <system:implementation.system class="org.apache.tuscany.runtime.webapp.implementation.webapp.WebappBuilder"/>
+ </component>
+
+</composite>
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/Foo.java b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/Foo.java
new file mode 100644
index 0000000000..75b49de188
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/Foo.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.runtime.webapp;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface Foo {
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/FooImpl.java b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/FooImpl.java
new file mode 100644
index 0000000000..dd938f2a58
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/FooImpl.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.runtime.webapp;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class FooImpl implements Foo {
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionIdTestCase.java b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionIdTestCase.java
new file mode 100644
index 0000000000..f41fa2361b
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionIdTestCase.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.runtime.webapp;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import junit.framework.TestCase;
+
+public class LazyHTTPSessionIdTestCase extends TestCase {
+
+ public void testGetIdentifier() {
+ HttpSession id = createMock(HttpSession.class);
+
+ HttpServletRequest request = createMock(HttpServletRequest.class);
+ expect(request.getSession(true)).andReturn(id);
+ replay(request);
+
+ LazyHTTPSessionId lazyHTTPSessionId = new LazyHTTPSessionId(request);
+ assertEquals(id, lazyHTTPSessionId.getIdentifier());
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/ServletHostTestCase.java b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/ServletHostTestCase.java
new file mode 100644
index 0000000000..3d979e8f46
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/ServletHostTestCase.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.runtime.webapp;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.verify;
+
+import javax.servlet.Servlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import junit.framework.TestCase;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ServletHostTestCase extends TestCase {
+
+ public void testDispatch() throws Exception {
+ HttpServletRequest req = createMock(HttpServletRequest.class);
+ expect(req.getPathInfo()).andReturn("foo");
+ replay(req);
+ HttpServletResponse res = createMock(HttpServletResponse.class);
+ Servlet servlet = createMock(Servlet.class);
+ servlet.service(req, res);
+ EasyMock.expectLastCall();
+ replay(servlet);
+ ServletHostImpl host = new ServletHostImpl();
+ host.registerMapping("foo", servlet);
+ host.service(req, res);
+ verify(servlet);
+ }
+
+ public void testDuplicateRegistration() throws Exception {
+ Servlet servlet = createMock(Servlet.class);
+ ServletHostImpl host = new ServletHostImpl();
+ host.registerMapping("foo", servlet);
+ assertEquals(true, host.isMappingRegistered("foo"));
+ assertEquals(false, host.isMappingRegistered("bar"));
+ try {
+ host.registerMapping("foo", servlet);
+ fail();
+ } catch (IllegalStateException e) {
+ // expected
+ }
+ }
+
+ public void testUnregister() throws Exception {
+ HttpServletRequest req = createMock(HttpServletRequest.class);
+ expect(req.getPathInfo()).andReturn("foo");
+ replay(req);
+ HttpServletResponse res = createMock(HttpServletResponse.class);
+ Servlet servlet = createMock(Servlet.class);
+ replay(servlet);
+ ServletHostImpl host = new ServletHostImpl();
+ host.registerMapping("foo", servlet);
+ Servlet unregedServlet = host.unregisterMapping("foo");
+ assertEquals(unregedServlet, servlet);
+ try {
+ host.service(req, res);
+ } catch (IllegalStateException e) {
+ // expected
+ }
+ verify(servlet);
+ }
+
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImplTestCase.java b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImplTestCase.java
new file mode 100644
index 0000000000..c076fb73cf
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImplTestCase.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.runtime.webapp;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+import java.net.URL;
+
+import javax.servlet.ServletContext;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.monitor.NullMonitorFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class WebappRuntimeImplTestCase extends TestCase {
+ private URL applicationScdl;
+ private URL systemScdl;
+ private WebappRuntimeImpl runtime;
+ private ServletContext context;
+
+ /**
+ * Verifies the web app host is configured properly to perform a basic boot
+ */
+ public void testBootWithDefaults() throws Exception {
+ expect(context.getResourcePaths("/WEB-INF/tuscany/extensions/")).andReturn(null);
+ replay(context);
+ runtime.initialize();
+ verify(context);
+ }
+
+/*
+ public void testLazyHttpSessionId() throws Exception {
+ expect(context.getResourcePaths("/WEB-INF/tuscany/extensions/")).andReturn(null);
+ replay(context);
+ runtime.initialize();
+ verify(context);
+
+ HttpServletRequest request = createMock(HttpServletRequest.class);
+ expect(request.getSession(true)).andReturn(null);
+ expect(request.getSession(false)).andReturn(null);
+ replay(request);
+
+ runtime.httpRequestStarted(request);
+
+ ServletRequestInjector injector = runtime.getRequestInjector();
+ class WorkContextAccessor extends ServletHostImpl {
+ ServletHostImpl servletHostImpl;
+ WorkContextAccessor(ServletHostImpl servletHostImpl){
+ this.servletHostImpl = servletHostImpl;
+ }
+ WorkContext getWorkContext() {
+ return servletHostImpl.workContext;
+ }
+ }
+ WorkContext workContext = new WorkContextAccessor((ServletHostImpl)injector).getWorkContext();
+ workContext.getIdentifier(Scope.SESSION);
+ verify(request);
+ }
+*/
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ systemScdl = getClass().getResource("/META-INF/tuscany/webapp.scdl");
+ applicationScdl = getClass().getResource("/testapp.scdl");
+ context = createMock(ServletContext.class);
+
+ runtime = new WebappRuntimeImpl();
+ runtime.setRuntimeInfo(new WebappRuntimeInfoImpl(context, null, false));
+ runtime.setMonitorFactory(new NullMonitorFactory());
+ runtime.setHostClassLoader(getClass().getClassLoader());
+ runtime.setServletContext(context);
+ runtime.setSystemScdl(systemScdl);
+ runtime.setApplicationName("foo");
+ runtime.setApplicationScdl(applicationScdl);
+ }
+}
diff --git a/tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/resources/testapp.scdl b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/resources/testapp.scdl
new file mode 100644
index 0000000000..9b5bda7fb6
--- /dev/null
+++ b/tags/java/tsss-demo/runtime/webapp/webapp-host/src/test/resources/testapp.scdl
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" name="testapp">
+
+ <component name="component">
+ <implementation.java class="org.apache.tuscany.runtime.webapp.FooImpl"/>
+ </component>
+
+</composite>